Skip to content

Commit d262dbd

Browse files
authored
Merge pull request #430 from jquick/jq/prebuilt-image-override
Add run-image option
2 parents b83f97f + 7fe965f commit d262dbd

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ None of the following are mandatory.
4040

4141
Pull down multiple pre-built images. By default only the service that is being run will be pulled down, but this allows multiple images to be specified to handle prebuilt dependent images. Note that pulling will be skipped if the `skip-pull` option is activated.
4242

43+
#### `run-image` (run only, string)
44+
45+
Set the service image to pull during a run. This can be useful if the image was created outside of the plugin.
46+
4347
#### `collapse-logs` (boolean)
4448

4549
Whether to collapse or expand the log group that is created for the output of the main commands (`run`, `build` and `push`). When this setting is `true`, the output is collected into a `---` group, when `false` the output is collected into a `+++` group. Setting this to `true` can be useful to de-emphasize plugin output if your command creates its own `+++` group.

commands/run.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ prebuilt_service_overrides=()
4040
prebuilt_services=()
4141

4242
# We look for a prebuilt images for all the pull services and the run_service.
43+
prebuilt_image_override="$(plugin_read_config RUN_IMAGE)"
4344
for service_name in "${prebuilt_candidates[@]}" ; do
44-
if prebuilt_image=$(get_prebuilt_image "$service_name") ; then
45-
echo "~~~ :docker: Found a pre-built image for $service_name"
45+
if [[ -n "$prebuilt_image_override" ]] && [[ "$service_name" == "$run_service" ]] ; then
46+
echo "~~~ :docker: Overriding run image for $service_name"
47+
prebuilt_image="$prebuilt_image_override"
48+
elif prebuilt_image=$(get_prebuilt_image "$service_name") ; then
49+
echo "~~~ :docker: Found a pre-built image for $service_name"
50+
fi
51+
52+
if [[ -n "$prebuilt_image" ]] ; then
4653
prebuilt_service_overrides+=("$service_name" "$prebuilt_image" "" 0 0)
4754
prebuilt_services+=("$service_name")
4855

plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ configuration:
9393
type: boolean
9494
rm:
9595
type: boolean
96+
run-image:
97+
type: string
9698
run-labels:
9799
type: boolean
98100
secrets:
@@ -167,6 +169,7 @@ configuration:
167169
push-retries: [ push ]
168170
quiet-pull: [ run ]
169171
rm: [ run ]
172+
run-image: [ run ]
170173
run-labels: [ run ]
171174
service-ports: [ run ]
172175
skip-pull: [ build, run ]

tests/run.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,22 @@ cmd3"
12801280
assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!"
12811281
unstub buildkite-agent
12821282
}
1283+
1284+
@test "Run with a run image override" {
1285+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
1286+
export BUILDKITE_COMMAND="echo hello world"
1287+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN_IMAGE=docker.buildkite.com/myservice:123
1288+
1289+
stub docker \
1290+
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
1291+
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
1292+
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice"
1293+
1294+
run "$PWD"/hooks/command
1295+
1296+
assert_success
1297+
assert_output --partial "image: docker.buildkite.com/myservice:123"
1298+
assert_output --partial "ran myservice"
1299+
1300+
unstub docker
1301+
}

0 commit comments

Comments
 (0)