Skip to content

Commit

Permalink
Merge pull request #41 from karolsojko/custom_command
Browse files Browse the repository at this point in the history
feat(docker-build): add way to use Docker BuildKit
  • Loading branch information
tommy351 authored Apr 10, 2023
2 parents c4d0a44 + 2607faa commit 5ed7230
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/docker-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ Copy additional files to a Docker image. This is useful for secret keys or confi
#### `--production`

Install production dependencies only.

#### `--buildkit`

Build the Docker image using Docker BuildKit, please check the Docker docs for more info: https://docs.docker.com/engine/reference/commandline/buildx_build/
11 changes: 10 additions & 1 deletion packages/docker-build/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default class DockerBuildCommand extends BaseCommand {
@Command.Boolean('--production')
public production?: boolean;

@Command.Boolean('--buildkit')
public buildKit?: boolean;

public static usage = Command.Usage({
category: 'Docker-related commands',
description: 'Build a Docker image for a workspace',
Expand All @@ -65,6 +68,10 @@ export default class DockerBuildCommand extends BaseCommand {
'Install production dependencies only',
'yarn docker build --production @foo/bar',
],
[
'Build a Docker image using BuildKit',
'yarn docker build --buildkit @foo/bar',
],
],
});

Expand Down Expand Up @@ -200,9 +207,11 @@ export default class DockerBuildCommand extends BaseCommand {
);
}

const buildCommand = this.buildKit ? ['buildx', 'build'] : ['build'];

await execUtils.pipevp(
'docker',
['build', ...this.args, '-f', dockerFilePath, '.'],
[...buildCommand, ...this.args, '-f', dockerFilePath, '.'],
{
cwd,
strict: true,
Expand Down

0 comments on commit 5ed7230

Please sign in to comment.