From c8a6cde98890ff1feed2f7d5776a30ab817aa8a5 Mon Sep 17 00:00:00 2001 From: Lar Van Der Jagt Date: Fri, 7 Apr 2023 14:52:37 -0400 Subject: [PATCH] Add skip-pull support to build phase Reuses the existing `skip-pull` option to conditionally remove the `--pull` flag from the generated docker compose command. --- README.md | 2 +- commands/build.sh | 6 +++++- plugin.yml | 2 +- tests/build.bats | 19 ++++++++++++++++++- tests/v2/build.bats | 19 ++++++++++++++++++- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a9fb55da..9de1b4fc 100644 --- a/README.md +++ b/README.md @@ -486,7 +486,7 @@ Whether to skip the repository checkout phase. This is useful for steps that use **Important**: as the code repository will not be available in the step, you need to ensure that the docker compose file(s) are present in some way (like using artifacts) -### `skip-pull` (optional, run only) +### `skip-pull` (optional, build and run only) Completely avoid running any `pull` command. Images being used will need to be present in the machine from before or have been built in the same step. Could be useful to avoid hitting rate limits when you can be sure the operation is unnecessary. Note that it is possible other commands run in the plugin's lifecycle will trigger a pull of necessary images. diff --git a/commands/build.sh b/commands/build.sh index 0ad9a025..ae6fb95f 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -148,7 +148,11 @@ while read -r line ; do [[ -n "$line" ]] && services+=("$line") done <<< "$(plugin_read_list BUILD)" -build_params=(build --pull) +build_params=(build) + +if [[ ! "$(plugin_read_config SKIP_PULL "false")" == "true" ]] ; then + build_params+=(--pull) +fi if [[ "$(plugin_read_config NO_CACHE "false")" == "true" ]] ; then build_params+=(--no-cache) diff --git a/plugin.yml b/plugin.yml index 9cf6dab7..0da0b270 100644 --- a/plugin.yml +++ b/plugin.yml @@ -141,7 +141,7 @@ configuration: pull: [ run ] push-retries: [ push ] service-ports: [ run ] - skip-pull: [ run ] + skip-pull: [ build, run ] secrets: [ buildkit, build ] ssh: [ buildkit ] target: [ build ] diff --git a/tests/build.bats b/tests/build.bats index 1b8b0ffa..144dce30 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -881,4 +881,21 @@ load '../lib/shared' assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR" unstub docker-compose -} \ No newline at end of file +} + +@test "Build without pull" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build myservice : echo built myservice" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "built myservice" + unstub docker-compose +} diff --git a/tests/v2/build.bats b/tests/v2/build.bats index 9fc590e1..10f99913 100644 --- a/tests/v2/build.bats +++ b/tests/v2/build.bats @@ -673,4 +673,21 @@ setup_file() { assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR" unstub docker -} \ No newline at end of file +} + +@test "Build without pull" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build myservice : echo built myservice" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "built myservice" + unstub docker +}