Skip to content

Commit

Permalink
Bootstrap the environment (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Feb 27, 2024
1 parent 013e89d commit b1f2a85
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
14 changes: 11 additions & 3 deletions src/src/Commands/Environment/DownEnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ protected function execute( InputInterface $input, OutputInterface $output ): in
$environment->status );
}, $running_environments );

$environment_choices['all'] = 'Stop all environments';

// More than one environment running, let user choose which one to stop
$helper = new QuestionHelper();
$question = new ChoiceQuestion(
'Please select the environment to stop (defaults to the first):',
'Please select the environment to stop (or choose to stop all):',
$environment_choices,
array_key_first( array_slice( $environment_choices, 0, 1 ) )
'all'
);
$question->setErrorMessage( 'Environment %s is invalid.' );

$selectedEnvironment = $helper->ask( $input, $output, $question );
$this->stop_environment( $this->environment_monitor->get_env_info_by_id( $selectedEnvironment ), $output );
if ( $selectedEnvironment === 'all' ) {
foreach ( $running_environments as $environment ) {
$this->stop_environment( $environment, $output );
}
} else {
$this->stop_environment( $this->environment_monitor->get_env_info_by_id( $selectedEnvironment ), $output );
}

return Command::SUCCESS;
}
Expand Down
5 changes: 5 additions & 0 deletions src/src/Environment/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function run_inside_docker( EnvInfo $env_info, array $command, array $env
$process = new Process( $docker_command );
$process->setTty( true );

if ( $this->output->isVerbose() ) {
// Print the command that will run.
$this->output->writeln( $process->getCommandLine() );
}

$process->run( function ( $type, $buffer ) {
$this->output->write( $buffer );
} );
Expand Down
2 changes: 0 additions & 2 deletions src/src/Environment/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ protected function up_docker_compose( EnvInfo $env_info ) {

$this->environment_monitor->environment_added_or_updated( $env_info );

return;

$this->post_up( $env_info );
}

Expand Down
20 changes: 10 additions & 10 deletions src/src/Environment/Environments/E2EEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ protected function post_generate_docker_compose( EnvInfo $env_info ): void {
}

protected function post_up( EnvInfo $env_info ): void {
/**
* : ${QIT_ENV_ID:?Please set the QIT_ENV_ID environment variable}
* : ${PHP_EXTENSIONS:?Please set the PHP_EXTENSIONS environment variable}
* : ${WORDPRESS_VERSION:?Please set the WORDPRESS_VERSION environment variable}
* : ${WOOCOMMERCE_VERSION:?Please set the WOOCOMMERCE_VERSION environment variable}
* : ${SUT_SLUG:?Please set the SUT_SLUG environment variable}
*/
$this->docker->run_inside_docker( $env_info, [ '/bin/bash', '/qit/bin/environment-bootstrap.sh' ], [
'PHP_EXTENSIONS' => json_encode( '' ),
$php_extensions = [];

if ( ! empty( $php_extensions ) ) {
$this->docker->run_inside_docker( $env_info, [ '/bin/bash', '/qit/bin/php-extensions.sh' ], [
'PHP_EXTENSIONS' => '', // Space-separated list of PHP extensions.
], '0:0' );
}

$this->docker->run_inside_docker( $env_info, [ '/bin/bash', '/qit/bin/wordpress-setup.sh' ], [
'WORDPRESS_VERSION' => 'latest',
'WOOCOMMERCE_VERSION' => '8.6.0',
'SUT_SLUG' => 'automatewoo',
'SITE_URL' => 'http://qit.test:' . $this->get_nginx_port( $env_info ),
], '0:0' );
] );
}
}

0 comments on commit b1f2a85

Please sign in to comment.