diff --git a/README.md b/README.md index 0c9b787f..577b2a3b 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 1a4f336f..1c0dcedd 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 631fc311..606936ff 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 074c9d0d..b30614c4 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -902,4 +902,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 4b6e961f..21ca38ec 100644 --- a/tests/v2/build.bats +++ b/tests/v2/build.bats @@ -692,4 +692,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 +}