From 3fec9f96c4c7936764b0b4f111d12d72b28e438f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Wed, 29 Mar 2023 13:39:13 +0200 Subject: [PATCH] feat(docker-build): add way to use Docker BuildKit --- packages/docker-build/README.md | 4 ++++ packages/docker-build/src/commands/build.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/docker-build/README.md b/packages/docker-build/README.md index 4e788c9..da33845 100644 --- a/packages/docker-build/README.md +++ b/packages/docker-build/README.md @@ -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/ diff --git a/packages/docker-build/src/commands/build.ts b/packages/docker-build/src/commands/build.ts index 1f43e4b..9bd1da6 100644 --- a/packages/docker-build/src/commands/build.ts +++ b/packages/docker-build/src/commands/build.ts @@ -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', @@ -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', + ], ], }); @@ -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,