statamic / cli

Install and manage your Statamic projects from the command line.
71 stars 19 forks source link

`statamic new` requires tty to run #65

Open amiuhle opened 8 months ago

amiuhle commented 8 months ago

I'm trying to create a new statamic site in an automated process using a docker image. It works using the -it flags when running the docker image, but without an interactive tty terminal, Statamic fails right after printing the title art:

In Process.php line 1023:

  TTY mode requires /dev/tty to be read/writable.

Statamic site generation should not require an interactive shell if the --no-interaction flag is passed from the command line.

jasonvarga commented 8 months ago

Please provide a way for us to reproduce this, or feel free to open a PR.

Also, what does composer global show | grep prompts output?

amiuhle commented 8 months ago

Below is a docker demo image built with Nix.

It can be built using

nix build && docker load < result

When it's run using the -it flag, it works but the second line without -it fails with the error message above.

docker run -it -v .:/project statamic-demo-image
docker run -v .:/project statamic-demo-image

Also, what does composer global show | grep prompts output?

The output is

laravel/prompts                  v0.1.12
# flake.nix
{
  description = "A flake to build a Statamic docker image";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }: {
    packages."x86_64-linux" =
      let
        pkgs = import nixpkgs { system = "x86_64-linux"; };
      in
      rec {
        default =
          pkgs.dockerTools.buildLayeredImage (
            let
              COMPOSER_HOME = "/tmp/composer";
            in
            rec {
              name = "statamic-demo-image";
              tag = "latest";

              contents = with pkgs; [
                dockerTools.usrBinEnv
                dockerTools.binSh
                dockerTools.caCertificates

                coreutils
                gnugrep
                git

                php81
                php81Packages.composer

                (writeTextDir "etc/passwd" ''
                  root:x:0:0::/root:${runtimeShell}
                '')
                (writeTextDir "root/.ssh/config" ''
                  Host *
                    StrictHostKeyChecking no
                '')

                (writeScriptBin "entrypoint" ''
                  #!${dockerTools.binSh}/bin/sh

                  ${pkgs.php81Packages.composer}/bin/composer global require statamic/cli

                  ${COMPOSER_HOME}/vendor/bin/statamic new -f -n -- test01
                  ${pkgs.php81Packages.composer}/bin/composer global show | grep prompts
                  ${dockerTools.binSh}/bin/sh
                '')
              ];

              config = {
                Entrypoint = [ "entrypoint" ];
                WorkingDir = "/project";
                Env = [
                  "COMPOSER_HOME=${COMPOSER_HOME}"
                  "COMPOSER_ALLOW_SUPERUSER=1"
                ];
                Volumes = {
                  "/project" = { };
                };
              };
            }
          );
      };
  };
}
amiuhle commented 7 months ago

I found a way to reproduce this without a docker image, see my PR comment here: https://github.com/statamic/cli/pull/66#issuecomment-1814252732