diff --git a/README.md b/README.md index caaf5978..847fde9d 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,12 @@ If set to `true` it will mount onto `/workdir`, unless `workdir` is set, in whic Default: `false` +### `buildkit-inline-cache` (optional, build-only, boolean) + +Whether to pass the `BUILDKIT_INLINE_CACHE=1` build arg when building an image. Can be safely used in combination with `args`. + +Default: `false` + #### `pull-retries` (run only, integer) A number of times to retry failed docker pull. Defaults to 0. diff --git a/commands/build.sh b/commands/build.sh index 6da04b0c..0903829d 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -89,6 +89,10 @@ if [[ "$(plugin_read_config BUILD_PARALLEL "false")" == "true" ]] ; then build_params+=(--parallel) fi +if [[ "$(plugin_read_config BUILDKIT_INLINE_CACHE "false")" == "true" ]] ; then + build_params+=("--build-arg" "BUILDKIT_INLINE_CACHE=1") +fi + # Parse the list of secrets to pass on to build command while read -r line ; do [[ -n "$line" ]] && build_params+=("--secret" "$line") @@ -113,4 +117,4 @@ while read -r arg ; do done <<< "$(plugin_read_list ARGS)" echo "${group_type} :docker: Building services ${services[*]}" -run_docker_compose "${build_params[@]}" "${services[@]}" \ No newline at end of file +run_docker_compose "${build_params[@]}" "${services[@]}" diff --git a/plugin.yml b/plugin.yml index ede4255f..2dbe8d26 100644 --- a/plugin.yml +++ b/plugin.yml @@ -27,6 +27,8 @@ configuration: type: boolean buildkit: type: boolean + buildkit-inline-cache: + type: boolean cache-from: type: [ string, array ] minimum: 1 @@ -138,6 +140,7 @@ configuration: build-alias: [ push ] build-parallel: [ build ] buildkit: [ build ] + buildkit-inline-cache: [ build ] cache-from: [ build ] command: [ run ] dependencies: [ run ] diff --git a/tests/build.bats b/tests/build.bats index cb9a51f7..af9174f9 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -327,3 +327,19 @@ setup_file() { unstub docker } + +@test "Build with buildkit-inline-cache" { + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_0=MYARG=0 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_1=MYARG=1 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT_INLINE_CACHE=true + + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + + run $PWD/hooks/command + + assert_success + assert_output --partial "built myservice" + unstub docker +}