Skip to content

Commit e88d05b

Browse files
authored
Merge pull request #486 from buildkite-plugins/toote_require_all_images
`require-prebuild` affects all images
2 parents 6e0d27a + 60d92d4 commit e88d05b

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Sets the `--entrypoint` argument when running `docker compose`, can be set to an
332332

333333
#### `require-prebuild` (run only, boolean)
334334

335-
If no prebuilt image is found for the run step, it will cause the plugin to fail the step.
335+
Make sure that images for the service being run and all specified in `pull` are found for the run step, fail the step otherwise. Note that specifying a `run-image` will skip this check for the service being run.
336336

337337
The default is `false`.
338338

commands/run.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ for service_name in "${prebuilt_candidates[@]}" ; do
4949
prebuilt_image="$prebuilt_image_override"
5050
elif prebuilt_image=$(get_prebuilt_image "$prebuilt_image_namespace" "$service_name") ; then
5151
echo "~~~ :docker: Found a pre-built image for $service_name"
52+
else
53+
echo "+++ 🚨 No pre-built image found from a previous 'build' step for service ${service_name} and config file."
54+
55+
if [[ "${BUILDKITE_PLUGIN_DOCKER_COMPOSE_REQUIRE_PREBUILD:-}" =~ ^(true|on|1)$ ]]; then
56+
echo "The step specified that it was required"
57+
exit 1
58+
fi
5259
fi
5360

5461
if [[ -n "$prebuilt_image" ]] ; then
@@ -350,15 +357,6 @@ fi
350357

351358
run_params+=("$run_service")
352359

353-
if [[ ! -f "$override_file" ]] ; then
354-
echo "+++ 🚨 No pre-built image found from a previous 'build' step for this service and config file."
355-
356-
if [[ "${BUILDKITE_PLUGIN_DOCKER_COMPOSE_REQUIRE_PREBUILD:-}" =~ ^(true|on|1)$ ]]; then
357-
echo "The step specified that it was required"
358-
exit 1
359-
fi
360-
fi
361-
362360
up_params+=("up") # this ensures that the array has elements to avoid issues with bash 4.3
363361

364362
if [[ "$(plugin_read_config WAIT "false")" == "true" ]] ; then

tests/run.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ teardown() {
5959
unstub buildkite-agent
6060
}
6161

62+
@test "Fail running without a prebuilt image for pull service and require-prebuild" {
63+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
64+
export BUILDKITE_COMMAND="echo hello world"
65+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_REQUIRE_PREBUILD=true
66+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PULL=other-service
67+
68+
stub buildkite-agent \
69+
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
70+
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myservice-image" \
71+
"meta-data exists docker-compose-plugin-built-image-tag-other-service : exit 1"
72+
73+
run "$PWD"/hooks/command
74+
75+
assert_failure
76+
77+
assert_output --partial "Found a pre-built image for myservice"
78+
assert_output --partial "No pre-built image found"
79+
80+
unstub buildkite-agent
81+
}
82+
6283
@test "Run without a prebuilt image and an empty command" {
6384
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
6485
export BUILDKITE_COMMAND=""

0 commit comments

Comments
 (0)