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 1/3] 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, From eceab7e5cd7db6550975a50472a7672633b5af9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Sun, 2 Apr 2023 12:00:27 +0200 Subject: [PATCH 2/3] Update packages/docker-build/src/commands/build.ts Co-authored-by: Tommy Chen --- packages/docker-build/src/commands/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docker-build/src/commands/build.ts b/packages/docker-build/src/commands/build.ts index 9bd1da6..1081fd3 100644 --- a/packages/docker-build/src/commands/build.ts +++ b/packages/docker-build/src/commands/build.ts @@ -207,7 +207,7 @@ export default class DockerBuildCommand extends BaseCommand { ); } - const buildCommand = this.buildKit ? 'buildx build' : 'build'; + const buildCommand = this.buildKit ? ['buildx', 'build'] : ['build']; await execUtils.pipevp( 'docker', From 2607faa380001d7a3173264fdc0519242bc8c3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Sun, 9 Apr 2023 07:49:19 +0200 Subject: [PATCH 3/3] Update packages/docker-build/src/commands/build.ts Co-authored-by: Tommy Chen --- packages/docker-build/src/commands/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docker-build/src/commands/build.ts b/packages/docker-build/src/commands/build.ts index 1081fd3..c9b4199 100644 --- a/packages/docker-build/src/commands/build.ts +++ b/packages/docker-build/src/commands/build.ts @@ -211,7 +211,7 @@ export default class DockerBuildCommand extends BaseCommand { await execUtils.pipevp( 'docker', - [buildCommand, ...this.args, '-f', dockerFilePath, '.'], + [...buildCommand, ...this.args, '-f', dockerFilePath, '.'], { cwd, strict: true,