From effd2762b8df0573e366d07d9f4df70cb2162251 Mon Sep 17 00:00:00 2001 From: Breno Ribeiro Date: Tue, 8 Mar 2022 17:47:07 -0300 Subject: [PATCH] The input device is not a TTY (#353) * Add failing test for TTY issue * Fix TTY issue in console * Clean up unneeded variable * Move test script to a gist * Update sail Co-authored-by: Breno Ribeiro Co-authored-by: Taylor Otwell --- bin/sail | 168 +++++++++++++++++++++++++++---------------------------- 1 file changed, 81 insertions(+), 87 deletions(-) diff --git a/bin/sail b/bin/sail index c721d8ac..8e6b2129 100755 --- a/bin/sail +++ b/bin/sail @@ -75,16 +75,17 @@ else EXEC="yes" fi +ARGS=(-f "$SAIL_FILE") + if [ $# -gt 0 ]; then # Proxy PHP commands to the "php" binary on the application container... if [ "$1" == "php" ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - php "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" "php" "$@") else sail_is_not_running fi @@ -94,10 +95,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - ./vendor/bin/"$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" ./vendor/bin/"$@") else sail_is_not_running fi @@ -107,10 +107,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - composer "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" "composer" "$@") else sail_is_not_running fi @@ -120,10 +119,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - php artisan "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" php artisan "$@") else sail_is_not_running fi @@ -133,11 +131,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - -e XDEBUG_SESSION=1 \ - "$APP_SERVICE" \ - php artisan "$@" + ARGS+=(exec -u sail -e XDEBUG_SESSION=1) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" php artisan "$@") else sail_is_not_running fi @@ -147,10 +143,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - php artisan test "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" php artisan test "$@") else sail_is_not_running fi @@ -160,10 +155,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - php vendor/bin/phpunit "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" php vendor/bin/phpunit "$@") else sail_is_not_running fi @@ -173,12 +167,11 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - -e "APP_URL=http://${APP_SERVICE}" \ - -e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \ - "$APP_SERVICE" \ - php artisan dusk "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(-e "APP_URL=http://${APP_SERVICE}") + ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub") + ARGS+=("$APP_SERVICE" php artisan dusk "$@") else sail_is_not_running fi @@ -188,12 +181,11 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - -e "APP_URL=http://${APP_SERVICE}" \ - -e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \ - "$APP_SERVICE" \ - php artisan dusk:fails "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(-e "APP_URL=http://${APP_SERVICE}") + ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub") + ARGS+=("$APP_SERVICE" php artisan dusk:fails "$@") else sail_is_not_running fi @@ -203,10 +195,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - php artisan tinker + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" php artisan tinker) else sail_is_not_running fi @@ -216,10 +207,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - node "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" node "$@") else sail_is_not_running fi @@ -229,10 +219,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - npm "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" npm "$@") else sail_is_not_running fi @@ -242,10 +231,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - npx "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" npx "$@") else sail_is_not_running fi @@ -255,10 +243,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - yarn "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" yarn "$@") else sail_is_not_running fi @@ -268,9 +255,10 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - mysql \ - bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}' + ARGS+=(exec) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(mysql bash -c) + ARGS+=('MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}') else sail_is_not_running fi @@ -280,9 +268,10 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - mariadb \ - bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}' + ARGS+=(exec) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(mariadb bash -c) + ARGS+=('MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}') else sail_is_not_running fi @@ -292,9 +281,10 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - pgsql \ - bash -c 'PGPASSWORD=${PGPASSWORD} psql -U ${POSTGRES_USER} ${POSTGRES_DB}' + ARGS+=(exec) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(pgsql bash -c) + ARGS+=('PGPASSWORD=${PGPASSWORD} psql -U ${POSTGRES_USER} ${POSTGRES_DB}') else sail_is_not_running fi @@ -304,10 +294,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - -u sail \ - "$APP_SERVICE" \ - bash "$@" + ARGS+=(exec -u sail) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" bash "$@") else sail_is_not_running fi @@ -317,9 +306,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - "$APP_SERVICE" \ - bash "$@" + ARGS+=(exec) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=("$APP_SERVICE" bash "$@") else sail_is_not_running fi @@ -329,9 +318,9 @@ if [ $# -gt 0 ]; then shift 1 if [ "$EXEC" == "yes" ]; then - docker-compose -f $SAIL_FILE exec \ - redis \ - redis-cli + ARGS+=(exec) + [ ! -t 0 ] && ARGS+=(-T) + ARGS+=(redis redis-cli) else sail_is_not_running fi @@ -342,19 +331,24 @@ if [ $# -gt 0 ]; then if [ "$EXEC" == "yes" ]; then docker run --init --rm -p $SAIL_SHARE_DASHBOARD:4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \ - --server-host="$SAIL_SHARE_SERVER_HOST" \ - --server-port="$SAIL_SHARE_SERVER_PORT" \ - --auth="$SAIL_SHARE_TOKEN" \ - --subdomain="$SAIL_SHARE_SUBDOMAIN" \ - "$@" + --server-host="$SAIL_SHARE_SERVER_HOST" \ + --server-port="$SAIL_SHARE_SERVER_PORT" \ + --auth="$SAIL_SHARE_TOKEN" \ + --subdomain="$SAIL_SHARE_SUBDOMAIN" \ + "$@" + + exit else sail_is_not_running fi # Pass unknown commands to the "docker-compose" binary... else - docker-compose -f $SAIL_FILE "$@" + ARGS+=("$@") fi else - docker-compose -f $SAIL_FILE ps + ARGS+=(ps) fi + +# Run Docker Compose with the defined arguments... +docker-compose "${ARGS[@]}"