Skip to content

Commit

Permalink
Specify Environment Dockerfile Path In Manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Crisafulli committed Apr 2, 2022
1 parent 08ea61b commit 097bfe5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static function build($path, $project, $environment, $cliBuildArgs)
*/
public static function buildCommand($project, $environment, $cliBuildArgs, $manifestBuildArgs)
{
return sprintf('docker build --pull --file=%s.Dockerfile --tag=%s %s.',
$environment,
return sprintf('docker build --pull --file=%s --tag=%s %s.',
Manifest::dockerfile($environment),
Str::slug($project).':'.$environment,
Collection::make($manifestBuildArgs)
->merge(Collection::make($cliBuildArgs)
Expand Down
11 changes: 11 additions & 0 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public static function dockerBuildArgs($environment)
return static::current()['environments'][$environment]['docker-build-args'] ?? [];
}

/**
* Get the Dockerfile.
*
* @param string $environment
* @return string
*/
public static function dockerfile($environment)
{
return static::current()['environments'][$environment]['dockerfile'] ?? "{$environment}.Dockerfile";
}

/**
* Determine if the environment uses a database proxy.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public static function vapor()
*/
public static function dockerfile($environment)
{
return getcwd().'/'.$environment.'.Dockerfile';
return getcwd().'/'.Manifest::dockerfile($environment);
}
}
32 changes: 32 additions & 0 deletions tests/DockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

namespace Laravel\VaporCli\Tests;

use Illuminate\Container\Container;
use Laravel\VaporCli\Docker;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

class DockerTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
touch($testManifest = getcwd().'/test.vapor.yml');
Container::getInstance()->offsetSet('manifest', $testManifest);
}

protected function tearDown(): void
{
@unlink(Container::getInstance()->offsetGet('manifest'));
parent::tearDown();
}

public function test_build_command_no_build_args()
{
$command = Docker::buildCommand('my-project', 'production', [], []);
Expand Down Expand Up @@ -41,4 +56,21 @@ public function test_build_command_cli_and_manifest_build_args()
"--build-arg='FOO=BAR' --build-arg='FIZZ=BAZZ' --build-arg='BAR=FOO' .";
$this->assertEquals($expectedCommand, $command);
}

public function test_dockerfile_from_manifest()
{
file_put_contents(Container::getInstance()->offsetGet('manifest'), Yaml::dump([
'id' => 1,
'name' => 'Test',
'environments' => [
'production' => [
'runtime' => 'docker',
'dockerfile' => 'docker/shared.Dockerfile',
],
],
]));
$command = Docker::buildCommand('my-project', 'production', [], []);
$expectedCommand = 'docker build --pull --file=docker/shared.Dockerfile --tag=my-project:production .';
$this->assertEquals($expectedCommand, $command);
}
}

0 comments on commit 097bfe5

Please sign in to comment.