From e24ce8f3f51d605b9c8da11f3de522f2b995fe7f Mon Sep 17 00:00:00 2001 From: Jared Quick Date: Fri, 23 Feb 2024 10:03:38 -0500 Subject: [PATCH 1/4] add inline cache env Signed-off-by: Jared Quick --- README.md | 6 ++++++ commands/build.sh | 6 +++++- plugin.yml | 3 +++ tests/build.bats | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) 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..4049f96f 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -327,3 +327,22 @@ setup_file() { unstub docker } + +@test "Build with buildkit-inline-cache" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + 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 -f docker-compose.buildkite-1-override.yml 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-compose +} From 5f618290da4f6e7a0ba2defb665421338869dd9c Mon Sep 17 00:00:00 2001 From: Jared Quick Date: Fri, 23 Feb 2024 14:01:14 -0500 Subject: [PATCH 2/4] fix tests Signed-off-by: Jared Quick --- tests/build.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/build.bats b/tests/build.bats index 4049f96f..0742beb4 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -337,8 +337,8 @@ setup_file() { 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 -f docker-compose.buildkite-1-override.yml build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" run $PWD/hooks/command From 53adabf1b1cef65442a1793018cb085fde269d0b Mon Sep 17 00:00:00 2001 From: Jared Quick Date: Fri, 23 Feb 2024 14:05:08 -0500 Subject: [PATCH 3/4] bats! Signed-off-by: Jared Quick --- tests/build.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/build.bats b/tests/build.bats index 0742beb4..5758efb4 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -344,5 +344,5 @@ setup_file() { assert_success assert_output --partial "built myservice" - unstub docker-compose + unstub docker } From bac6762d3a24f6d18238683c3ba7c1978d4ef91d Mon Sep 17 00:00:00 2001 From: Jared Quick Date: Fri, 23 Feb 2024 14:11:51 -0500 Subject: [PATCH 4/4] fix tests for real Signed-off-by: Jared Quick --- tests/build.bats | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/build.bats b/tests/build.bats index 5758efb4..af9174f9 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -329,16 +329,13 @@ setup_file() { } @test "Build with buildkit-inline-cache" { - export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 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 -f docker-compose.buildkite-1-override.yml build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + "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