Skip to content

Commit

Permalink
Merge pull request #384 from supaspoida/skip-pull-build
Browse files Browse the repository at this point in the history
Add skip-pull support to build phase
  • Loading branch information
pzeballos authored Apr 10, 2023
2 parents 1d9c570 + c8a6cde commit ebd8d8f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion commands/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
19 changes: 18 additions & 1 deletion tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,21 @@ load '../lib/shared'
assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR"

unstub docker-compose
}
}

@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
}
19 changes: 18 additions & 1 deletion tests/v2/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,21 @@ setup_file() {
assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR"

unstub docker
}
}

@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
}

0 comments on commit ebd8d8f

Please sign in to comment.