Skip to content

Commit 82891fd

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: Adding a DOCKER_SUPPORT env var to permanently activate docker support
2 parents ee7d282 + 90ee9dd commit 82891fd

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

src/Configurator/DockerComposeConfigurator.php

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,34 +111,14 @@ public static function shouldConfigureDockerRecipe(Composer $composer, IOInterfa
111111
return false;
112112
}
113113

114-
$warning = $io->isInteractive() ? 'WARNING' : 'IGNORING';
115-
$io->writeError(sprintf(' - <warning> %s </> %s', $warning, $recipe->getFormattedOrigin()));
116-
$question = ' The recipe for this package contains some Docker configuration.
117-
118-
This may create/update <comment>docker-compose.yml</comment> or update <comment>Dockerfile</comment> (if it exists).
119-
120-
Do you want to include Docker configuration from recipes?
121-
[<comment>y</>] Yes
122-
[<comment>n</>] No
123-
[<comment>p</>] Yes permanently, never ask again for this project
124-
[<comment>x</>] No permanently, never ask again for this project
125-
(defaults to <comment>y</>): ';
126-
$answer = $io->askAndValidate(
127-
$question,
128-
function ($value) {
129-
if (null === $value) {
130-
return 'y';
131-
}
132-
$value = strtolower($value[0]);
133-
if (!\in_array($value, ['y', 'n', 'p', 'x'], true)) {
134-
throw new \InvalidArgumentException('Invalid choice.');
135-
}
114+
if (!isset($_SERVER['SYMFONY_DOCKER'])) {
115+
$answer = self::askDockerSupport($io, $recipe);
116+
} elseif (filter_var($_SERVER['SYMFONY_DOCKER'], \FILTER_VALIDATE_BOOLEAN)) {
117+
$answer = 'p';
118+
} else {
119+
$answer = 'x';
120+
}
136121

137-
return $value;
138-
},
139-
null,
140-
'y'
141-
);
142122
if ('n' === $answer) {
143123
self::$configureDockerRecipes = false;
144124

@@ -368,4 +348,37 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe,
368348

369349
return $updatedContents;
370350
}
351+
352+
private static function askDockerSupport(IOInterface $io, Recipe $recipe): string
353+
{
354+
$warning = $io->isInteractive() ? 'WARNING' : 'IGNORING';
355+
$io->writeError(sprintf(' - <warning> %s </> %s', $warning, $recipe->getFormattedOrigin()));
356+
$question = ' The recipe for this package contains some Docker configuration.
357+
358+
This may create/update <comment>docker-compose.yml</comment> or update <comment>Dockerfile</comment> (if it exists).
359+
360+
Do you want to include Docker configuration from recipes?
361+
[<comment>y</>] Yes
362+
[<comment>n</>] No
363+
[<comment>p</>] Yes permanently, never ask again for this project
364+
[<comment>x</>] No permanently, never ask again for this project
365+
(defaults to <comment>y</>): ';
366+
367+
return $io->askAndValidate(
368+
$question,
369+
function ($value) {
370+
if (null === $value) {
371+
return 'y';
372+
}
373+
$value = strtolower($value[0]);
374+
if (!\in_array($value, ['y', 'n', 'p', 'x'], true)) {
375+
throw new \InvalidArgumentException('Invalid choice.');
376+
}
377+
378+
return $value;
379+
},
380+
null,
381+
'y'
382+
);
383+
}
371384
}

tests/Configurator/DockerComposeConfiguratorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ public function getInteractiveDockerPreferenceTests()
257257
yield 'no_forever' => ['x', false, true];
258258
}
259259

260+
public function testEnvVarUsedForDockerConfirmation()
261+
{
262+
$composerJsonPath = FLEX_TEST_DIR.'/composer.json';
263+
file_put_contents($composerJsonPath, json_encode(['name' => 'test/app']));
264+
265+
$this->package->setExtra(['symfony' => []]);
266+
$this->recipeDb->method('getJob')->willReturn('install');
267+
$this->io->expects($this->never())->method('askAndValidate');
268+
269+
$_SERVER['SYMFONY_DOCKER'] = 1;
270+
$this->configurator->configure($this->recipeDb, self::CONFIG_DB, $this->lock);
271+
unset($_SERVER['SYMFONY_DOCKER']);
272+
273+
$this->assertFileExists(FLEX_TEST_DIR.'/docker-compose.yml');
274+
275+
$composerJsonData = json_decode(file_get_contents($composerJsonPath), true);
276+
$this->assertArrayHasKey('extra', $composerJsonData);
277+
$this->assertTrue($composerJsonData['extra']['symfony']['docker']);
278+
}
279+
260280
public function testConfigureFileWithExistingVolumes()
261281
{
262282
$originalContent = self::ORIGINAL_CONTENT.<<<'YAML'

0 commit comments

Comments
 (0)