diff --git a/payload/dev/docker-compose-osx.yml b/payload/dev/docker-compose-osx.yml index 6da2204..a4d8330 100644 --- a/payload/dev/docker-compose-osx.yml +++ b/payload/dev/docker-compose-osx.yml @@ -1,4 +1,4 @@ -version: '2.1' +version: '2.2' services: engine: volumes: diff --git a/payload/dev/docker-compose.yml b/payload/dev/docker-compose.yml index 5f9ff75..3e74fb6 100644 --- a/payload/dev/docker-compose.yml +++ b/payload/dev/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2.1' +version: '2.2' services: nginx: image: nginx:stable-alpine diff --git a/src/Command/Docker/Initialize.php b/src/Command/Docker/Initialize.php index eca89b7..b9d0c1b 100644 --- a/src/Command/Docker/Initialize.php +++ b/src/Command/Docker/Initialize.php @@ -126,8 +126,8 @@ protected function execute(InputInterface $input, OutputInterface $output): void // eZ Platform <3 only support solr 6. Replace unsupported solr 7.7 by 6.6.2 if ( - ( (1 === (int) str_replace(['^', '~'], '', $normalizedVersion)) || - (2 === (int) str_replace(['^', '~'], '', $normalizedVersion)) ) && + ((1 === (int) str_replace(['^', '~'], '', $normalizedVersion)) || + (2 === (int) str_replace(['^', '~'], '', $normalizedVersion))) && $compose->hasService('solr') ) { $composeFilePath = "{$provisioningFolder}/dev/{$composeFileName}"; diff --git a/src/Core/DockerCommand.php b/src/Core/DockerCommand.php index f47afa6..f60c262 100644 --- a/src/Core/DockerCommand.php +++ b/src/Core/DockerCommand.php @@ -35,7 +35,14 @@ abstract class DockerCommand extends Command protected function configure(): void { - $this->addOption('env', 'env', InputOption::VALUE_REQUIRED, 'Docker Env', 'dev'); + $this->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'); + $this->addOption( + 'docker-env', + 'd', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'Docker environment variables', + [] + ); } public function getDockerClient(): Docker @@ -73,7 +80,8 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $this->taskExecutor = new TaskExecutor( $this->dockerClient, $this->projectConfiguration, - $this->requiredRecipes + $this->requiredRecipes, + $input->getOption('docker-env') ); } } diff --git a/src/Core/TaskExecutor.php b/src/Core/TaskExecutor.php index 0136185..49b0f8c 100644 --- a/src/Core/TaskExecutor.php +++ b/src/Core/TaskExecutor.php @@ -32,11 +32,21 @@ class TaskExecutor */ protected $recipes; - public function __construct(DockerClient $dockerClient, ProjectConfiguration $configuration, Collection $recipes) - { + /** + * @var array Docker environment variables + */ + protected $dockerEnvVars; + + public function __construct( + DockerClient $dockerClient, + ProjectConfiguration $configuration, + Collection $recipes, + array $dockerEnvVars = [] + ) { $this->dockerClient = $dockerClient; $this->projectConfiguration = $configuration; $this->recipes = $recipes; + $this->dockerEnvVars = $dockerEnvVars; } protected function checkRecipeAvailability(string $recipe): void @@ -177,6 +187,12 @@ protected function execute(string $command, string $user = 'www-data', string $s protected function globalExecute(string $command, string $user = 'www-data', string $service = 'engine') { - return $this->dockerClient->exec($command, ['--user', $user], $service); + $args = ['--user', $user]; + + foreach ($this->dockerEnvVars as $envVar) { + $args = array_merge($args, ['--env', $envVar]); + } + + return $this->dockerClient->exec($command, $args, $service); } }