Skip to content

Commit

Permalink
Docker builds with Buildkit (consolidation#942)
Browse files Browse the repository at this point in the history
* allow enabling DOCKER_BUILDKIT

* add missing comment

* Update Docker.md

* drop buildkit argument

* Update DockerTest.php
  • Loading branch information
saitho authored May 22, 2020
1 parent 30e78de commit e3fc58c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/tasks/Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Class Build
* `option($option, $value = null, $separator = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter.
* `options(array $options, $separator = null)` Pass multiple options to executable. The associative array contains
* `optionList($option, $value = null, $separator = null)` Pass an option with multiple values to executable. Value can be a string or array.
* `enableBuildKit()` Build with [Docker Buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/)

## Commit

Expand Down
20 changes: 19 additions & 1 deletion src/Task/Docker/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Build extends Base
* @var string
*/
protected $path;

/**
* @var bool
*/
protected $buildKit = false;

/**
* @param string $path
Expand All @@ -41,7 +46,11 @@ public function __construct($path = '.')
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments . ' ' . $this->path;
$command = $this->command;
if ($this->buildKit) {
$command = 'DOCKER_BUILDKIT=1 ' . $command;
}
return $command . ' ' . $this->arguments . ' ' . $this->path;
}

/**
Expand All @@ -53,4 +62,13 @@ public function tag($tag)
{
return $this->option('-t', $tag);
}

/**
* @return $this
*/
public function enableBuildKit()
{
$this->buildKit = true;
return $this;
}
}
3 changes: 3 additions & 0 deletions tests/unit/Task/DockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function testDockerBuild()

(new \Robo\Task\Docker\Build())->tag('something')->run();
$docker->verifyInvoked('executeCommand', ['docker build -t something .']);

(new \Robo\Task\Docker\Build())->enableBuildKit()->tag('something')->run();
$docker->verifyInvoked('executeCommand', ['DOCKER_BUILDKIT=1 docker build -t something .']);
}

public function testDockerCommit()
Expand Down

0 comments on commit e3fc58c

Please sign in to comment.