Skip to content

Commit

Permalink
Merge pull request #430 from jquick/jq/prebuilt-image-override
Browse files Browse the repository at this point in the history
Add run-image option
  • Loading branch information
pzeballos authored Mar 1, 2024
2 parents b83f97f + 7fe965f commit d262dbd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ None of the following are mandatory.

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.

#### `run-image` (run only, string)

Set the service image to pull during a run. This can be useful if the image was created outside of the plugin.

#### `collapse-logs` (boolean)

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.
Expand Down
11 changes: 9 additions & 2 deletions commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ prebuilt_service_overrides=()
prebuilt_services=()

# We look for a prebuilt images for all the pull services and the run_service.
prebuilt_image_override="$(plugin_read_config RUN_IMAGE)"
for service_name in "${prebuilt_candidates[@]}" ; do
if prebuilt_image=$(get_prebuilt_image "$service_name") ; then
echo "~~~ :docker: Found a pre-built image for $service_name"
if [[ -n "$prebuilt_image_override" ]] && [[ "$service_name" == "$run_service" ]] ; then
echo "~~~ :docker: Overriding run image for $service_name"
prebuilt_image="$prebuilt_image_override"
elif prebuilt_image=$(get_prebuilt_image "$service_name") ; then
echo "~~~ :docker: Found a pre-built image for $service_name"
fi

if [[ -n "$prebuilt_image" ]] ; then
prebuilt_service_overrides+=("$service_name" "$prebuilt_image" "" 0 0)
prebuilt_services+=("$service_name")

Expand Down
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ configuration:
type: boolean
rm:
type: boolean
run-image:
type: string
run-labels:
type: boolean
secrets:
Expand Down Expand Up @@ -167,6 +169,7 @@ configuration:
push-retries: [ push ]
quiet-pull: [ run ]
rm: [ run ]
run-image: [ run ]
run-labels: [ run ]
service-ports: [ run ]
skip-pull: [ build, run ]
Expand Down
19 changes: 19 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,22 @@ cmd3"
assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!"
unstub buildkite-agent
}

@test "Run with a run image override" {
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_COMMAND="echo hello world"
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN_IMAGE=docker.buildkite.com/myservice:123

stub docker \
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
"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"

run "$PWD"/hooks/command

assert_success
assert_output --partial "image: docker.buildkite.com/myservice:123"
assert_output --partial "ran myservice"

unstub docker
}

0 comments on commit d262dbd

Please sign in to comment.