From b73a9cf5d581844445d84ea7e0d95e2a0af6cde2 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 28 Feb 2024 21:21:46 -0300 Subject: [PATCH] Try to run as root --- .../workflows/qit-environment-test-linux.yml | 3 +++ src/src/Environment/Docker.php | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/qit-environment-test-linux.yml b/.github/workflows/qit-environment-test-linux.yml index b11ef8cf..4d3043c5 100644 --- a/.github/workflows/qit-environment-test-linux.yml +++ b/.github/workflows/qit-environment-test-linux.yml @@ -68,6 +68,9 @@ jobs: - name: Start environment and get URL (Unix) if: runner.os != 'Windows' working-directory: src + env: + QIT_DOCKER_USER: 0 + QIT_DOCKER_GROUP: 0 run: | set -e echo "Starting environment and retrieving site URL..." diff --git a/src/src/Environment/Docker.php b/src/src/Environment/Docker.php index 6c7c7fed..72454e54 100644 --- a/src/src/Environment/Docker.php +++ b/src/src/Environment/Docker.php @@ -63,14 +63,24 @@ public function run_inside_docker( EnvInfo $env_info, array $command, array $env $docker_command = array_merge( $docker_command, [ '-it' ] ); } + // Check if user is not set and try to set it from ENV vars or posix functions. if ( is_null( $user ) ) { - if ( function_exists( 'posix_getuid' ) && function_exists( 'posix_getuid' ) ) { - $docker_command[] = '--user'; - $docker_command[] = posix_getuid() . ':' . posix_getgid(); + $envUser = getenv( 'QIT_DOCKER_USER' ); + $envGroup = getenv( 'QIT_DOCKER_GROUP' ); + + if ( $envUser && $envGroup ) { + // Use user and group from environment variables. + $user = $envUser . ':' . $envGroup; + } elseif ( function_exists( 'posix_getuid' ) && function_exists( 'posix_getgid' ) ) { + // Use user and group from posix functions. + $user = posix_getuid() . ':' . posix_getgid(); } else { - $this->output->writeln( 'To run the environment with the correct permissions, please install the posix extension on PHP.' ); + // Output warning if neither method is available. + $this->output->writeln( 'To run the environment with the correct permissions, please install the posix extension on PHP, or set QIT_DOCKER_USER/QIT_DOCKER_GROUP env vars.' ); } - } else { + } + + if ( ! is_null( $user ) ) { $docker_command[] = '--user'; $docker_command[] = $user; } @@ -97,11 +107,7 @@ public function run_inside_docker( EnvInfo $env_info, array $command, array $env $this->output->writeln( $process->getCommandLine() ); } - echo $process->getCommandLine(); - - echo "Running...\n"; $process->run( function ( $type, $buffer ) { - echo $buffer; $this->output->write( $buffer ); } );