Skip to content

Commit 4c79828

Browse files
committed
chore: handle docker args flags as well as long flags
1 parent 43c376a commit 4c79828

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Docker.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,27 @@ public static function buildCommand($project, $environment, $cliDockerArgs, $man
6262
return '--build-arg='.escapeshellarg("{$key}={$value}").' ';
6363
})->implode('')),
6464
trim(Collection::make($manifestDockerArgs)
65+
->mapWithKeys(function ($value) {
66+
if (is_array($value)) {
67+
return $value;
68+
}
69+
70+
return [$value => null];
71+
})
6572
->merge(Collection::make($cliDockerArgs)
6673
->mapWithKeys(function ($value) {
67-
[$key, $value] = explode('=', $value, 2);
74+
if (!str_contains($value, '=')) {
75+
return [$value => null];
76+
}
6877

78+
[$key, $value] = explode('=', $value, 2);
6979
return [$key => $value];
7080
})
7181
)->map(function ($value, $key) {
82+
if ($value === null) {
83+
return "--${key} ";
84+
}
85+
7286
return "--${key}=".escapeshellarg($value).' ';
7387
})->implode(''))
7488
);

tests/DockerTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,29 @@ public function test_build_command_cli_and_manifest_build_args()
5959

6060
public function test_build_command_cli_docker_args()
6161
{
62-
$cliDockerArgs = ['FOO=BAR', 'FIZZ=BUZZ'];
62+
$cliDockerArgs = ['BAR=FOO', 'FIZZ=BAZZ', 'FIZZLE', 'BUZZLE'];
6363
$command = Docker::buildCommand('my-project', 'production', $cliDockerArgs, [], [], []);
6464
$expectedCommand = 'docker build --pull --file=production.Dockerfile --tag=my-project:production '.
65-
"--FOO='BAR' --FIZZ='BUZZ' .";
65+
"--BAR='FOO' --FIZZ='BAZZ' --FIZZLE --BUZZLE .";
6666
$this->assertEquals($expectedCommand, $command);
6767
}
6868

6969
public function test_build_command_manifest_docker_args()
7070
{
71-
$manifestDockerArgs = ['FOO' => 'BAR', 'FIZZ' => 'BUZZ'];
71+
$manifestDockerArgs = [['FOO' => 'BAR'], ['FIZZ' => 'BUZZ'], 'FIZZLE', 'BUZZLE'];
7272
$command = Docker::buildCommand('my-project', 'production', [], $manifestDockerArgs, [], []);
7373
$expectedCommand = 'docker build --pull --file=production.Dockerfile --tag=my-project:production '.
74-
"--FOO='BAR' --FIZZ='BUZZ' .";
74+
"--FOO='BAR' --FIZZ='BUZZ' --FIZZLE --BUZZLE .";
7575
$this->assertEquals($expectedCommand, $command);
7676
}
7777

7878
public function test_build_command_cli_and_manifest_docker_args()
7979
{
80-
$cliDockerArgs = ['BAR=FOO', 'FIZZ=BAZZ'];
81-
$manifestDockerArgs = ['FOO' => 'BAR', 'FIZZ' => 'BUZZ'];
80+
$cliDockerArgs = ['BAR=FOO', 'FIZZ=BAZZ', 'FIZZLE', 'BUZZLE'];
81+
$manifestDockerArgs = [['FOO' => 'BAR'], ['FIZZ' => 'BUZZ'], 'FIZZLY', 'BUZZLY'];
8282
$command = Docker::buildCommand('my-project', 'production', $cliDockerArgs, $manifestDockerArgs, [], []);
8383
$expectedCommand = 'docker build --pull --file=production.Dockerfile --tag=my-project:production '.
84-
"--FOO='BAR' --FIZZ='BAZZ' --BAR='FOO' .";
84+
"--FOO='BAR' --FIZZ='BAZZ' --FIZZLY --BUZZLY --BAR='FOO' --FIZZLE --BUZZLE .";
8585
$this->assertEquals($expectedCommand, $command);
8686
}
8787

0 commit comments

Comments
 (0)