Skip to content

Commit 733d7cc

Browse files
committed
add prebuilt-image option
Signed-off-by: Jared Quick <jared.quick@salesforce.com>
1 parent b83f97f commit 733d7cc

4 files changed

Lines changed: 41 additions & 1 deletion

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +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+
prebuilt_image=$(get_prebuilt_image "$service_name") || :
46+
47+
# override run_service prebuilt_image if set
48+
if [[ -n "$prebuilt_image_override" ]] && [[ "$service_name" == "$run_service" ]] ; then
49+
prebuilt_image="$prebuilt_image_override"
50+
fi
51+
52+
if [[ -n "$prebuilt_image" ]] ; then
4553
echo "~~~ :docker: Found a pre-built image for $service_name"
4654
prebuilt_service_overrides+=("$service_name" "$prebuilt_image" "" 0 0)
4755
prebuilt_services+=("$service_name")

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,28 @@ 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 wit 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+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
1289+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
1290+
1291+
stub docker \
1292+
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
1293+
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
1294+
"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"
1295+
1296+
stub buildkite-agent \
1297+
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"
1298+
1299+
run "$PWD"/hooks/command
1300+
1301+
assert_success
1302+
assert_output --partial "image: docker.buildkite.com/myservice:123"
1303+
assert_output --partial "ran myservice"
1304+
1305+
unstub docker
1306+
unstub buildkite-agent
1307+
}

0 commit comments

Comments
 (0)