Skip to content

Commit 326ae4f

Browse files
damiantwDamian Crisafullitaylorotwell
authored
Specify Environment Dockerfile Path In Manifest (#178)
* Specify Environment Dockerfile Path In Manifest * formatting Co-authored-by: Damian Crisafulli <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 08ea61b commit 326ae4f

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

src/Docker.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static function build($path, $project, $environment, $cliBuildArgs)
3838
*/
3939
public static function buildCommand($project, $environment, $cliBuildArgs, $manifestBuildArgs)
4040
{
41-
return sprintf('docker build --pull --file=%s.Dockerfile --tag=%s %s.',
42-
$environment,
41+
return sprintf('docker build --pull --file=%s --tag=%s %s.',
42+
Manifest::dockerfile($environment),
4343
Str::slug($project).':'.$environment,
4444
Collection::make($manifestBuildArgs)
4545
->merge(Collection::make($cliBuildArgs)

src/Manifest.php

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public static function buildCommands($environment)
5555
return static::current()['environments'][$environment]['build'] ?? [];
5656
}
5757

58+
/**
59+
* Get the Dockerfile for the given environment.
60+
*
61+
* @param string $environment
62+
* @return string
63+
*/
64+
public static function dockerfile($environment)
65+
{
66+
return static::current()['environments'][$environment]['dockerfile'] ?? "{$environment}.Dockerfile";
67+
}
68+
5869
/**
5970
* Get the Docker build arguments.
6071
*

src/Path.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@ public static function vapor()
112112
*/
113113
public static function dockerfile($environment)
114114
{
115-
return getcwd().'/'.$environment.'.Dockerfile';
115+
return getcwd().'/'.Manifest::dockerfile($environment);
116116
}
117117
}

tests/DockerTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22

33
namespace Laravel\VaporCli\Tests;
44

5+
use Illuminate\Container\Container;
56
use Laravel\VaporCli\Docker;
67
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Yaml\Yaml;
79

810
class DockerTest extends TestCase
911
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
touch($testManifest = getcwd().'/test.vapor.yml');
16+
Container::getInstance()->offsetSet('manifest', $testManifest);
17+
}
18+
19+
protected function tearDown(): void
20+
{
21+
@unlink(Container::getInstance()->offsetGet('manifest'));
22+
parent::tearDown();
23+
}
24+
1025
public function test_build_command_no_build_args()
1126
{
1227
$command = Docker::buildCommand('my-project', 'production', [], []);
@@ -41,4 +56,21 @@ public function test_build_command_cli_and_manifest_build_args()
4156
"--build-arg='FOO=BAR' --build-arg='FIZZ=BAZZ' --build-arg='BAR=FOO' .";
4257
$this->assertEquals($expectedCommand, $command);
4358
}
59+
60+
public function test_dockerfile_from_manifest()
61+
{
62+
file_put_contents(Container::getInstance()->offsetGet('manifest'), Yaml::dump([
63+
'id' => 1,
64+
'name' => 'Test',
65+
'environments' => [
66+
'production' => [
67+
'runtime' => 'docker',
68+
'dockerfile' => 'docker/shared.Dockerfile',
69+
],
70+
],
71+
]));
72+
$command = Docker::buildCommand('my-project', 'production', [], []);
73+
$expectedCommand = 'docker build --pull --file=docker/shared.Dockerfile --tag=my-project:production .';
74+
$this->assertEquals($expectedCommand, $command);
75+
}
4476
}

0 commit comments

Comments
 (0)