Skip to content

Commit

Permalink
Merge pull request #428 from jquick/jq/add_inline_cache_env
Browse files Browse the repository at this point in the history
Add buildkite inline cache env
  • Loading branch information
pzeballos authored Feb 23, 2024
2 parents 3987929 + bac6762 commit 8d5db9f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion commands/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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[@]}"
run_docker_compose "${build_params[@]}" "${services[@]}"
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ configuration:
type: boolean
buildkit:
type: boolean
buildkit-inline-cache:
type: boolean
cache-from:
type: [ string, array ]
minimum: 1
Expand Down Expand Up @@ -138,6 +140,7 @@ configuration:
build-alias: [ push ]
build-parallel: [ build ]
buildkit: [ build ]
buildkit-inline-cache: [ build ]
cache-from: [ build ]
command: [ run ]
dependencies: [ run ]
Expand Down
16 changes: 16 additions & 0 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8d5db9f

Please sign in to comment.