Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Service/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Model\DockerContainer;
use App\Model\DockerData;
use App\Model\DockerNetwork;
use App\StaticVars;
use App\Traits\ExecTrait;
use splitbrain\phpcli\Exception;

Expand Down Expand Up @@ -501,9 +502,12 @@ public function buildImageWithCompose(string $composeFile, DockerData $dockerDat
$dockerBuildKit = $usesSsh ? 'DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 ' : '';
$composeCmd = $this->getComposeCommand();
$baseArgs = "--project-directory {$projectDirEscaped} -f {$composeFileEscaped} build";
if (StaticVars::$ciMode) {
$baseArgs .= ' --no-cache';
}
$cmd = "{$dockerBuildKit}{$composeCmd} {$baseArgs}";
$errorMsg = "Failed to build image with docker compose";
$this->exec($cmd, $errorMsg);
$this->execPassthru($cmd, $errorMsg);

// Get the built image name from compose and tag it with our custom name
// This is a bit tricky - we need to inspect what compose built and rename it
Expand Down
10 changes: 9 additions & 1 deletion src/Tests/DockerComposeBuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ protected function exec(string $cmd, ?string $errorMsg = null, ?bool $silent = f
$this->commands[] = $cmd;
return '';
}

protected function execPassthru(string $cmd, ?string $errorMsg = null): void {
$this->commands[] = $cmd;
}
};

$configurator = $this->getMockBuilder(Configurator::class)
Expand Down Expand Up @@ -60,11 +64,15 @@ public function __construct() {
}

protected function exec(string $cmd, ?string $errorMsg = null, ?bool $silent = false): string {
$this->commands[] = $cmd;
return '';
}

protected function execPassthru(string $cmd, ?string $errorMsg = null): void {
$this->commands[] = $cmd;
if (str_contains($cmd, ' build')) {
throw new ExecFailed('build fails', 0, $cmd);
}
return '';
}
};

Expand Down
Loading