Skip to content

Commit

Permalink
Try to run as root
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Feb 29, 2024
1 parent 333e9a0 commit b73a9cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/qit-environment-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
24 changes: 15 additions & 9 deletions src/src/Environment/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<info>To run the environment with the correct permissions, please install the posix extension on PHP.</info>' );
// Output warning if neither method is available.
$this->output->writeln( '<info>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.</info>' );
}
} else {
}

if ( ! is_null( $user ) ) {
$docker_command[] = '--user';
$docker_command[] = $user;
}
Expand All @@ -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 );
} );

Expand Down

0 comments on commit b73a9cf

Please sign in to comment.