Skip to content

Commit f966c51

Browse files
authored
Merge pull request #455 from buildkite-plugins/toote_prebuild_clarifications
Pre-build image clarifications
2 parents ec45125 + 9827b53 commit f966c51

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ The name of the service the command should be run within. If the docker-compose
3232

3333
A list of services to push. You can specify just the service name to push or the format `service:registry:tag` to override where the service's image is pushed to. Needless to say, the image for the service must have been built in the very same step or built and pushed previously to ensure it is available for pushing.
3434

35-
:warning: The `push` command will fail if a `login` command has not previously been used or the agent has not been authenticated for an image registry.
35+
:warning: If a service does not have an `image` configuration and no registry/tag are specified in the `push` option, pushing of the service will be skipped by docker.
36+
37+
:warning: The `push` command will fail when the image refers to a remote registry that requires a login and the agent has not been authenticated for it (for example, using the [ecr](https://github.com/buildkite-plugins/ecr-buildkite-plugin) or [docker-login](https://github.com/buildkite-plugins/docker-login-buildkite-plugin) plugins).
3638

3739
### Other options
3840

@@ -294,6 +296,12 @@ Note that [the effect of this option changes depending on your docker compose CL
294296

295297
Sets the `--entrypoint` argument when running `docker compose`.
296298

299+
#### `require-prebuild` (run only, boolean)
300+
301+
If no prebuilt image is found for the run step, it will cause the plugin to fail the step.
302+
303+
The default is `false`.
304+
297305
#### `service-ports` (run only, boolean)
298306

299307
If set to true, docker compose will run with the service ports enabled and mapped to the host. Equivalent to `--service-ports` in docker-compose.

docs/examples.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ steps:
194194
plugins:
195195
- docker-compose#v5.3.0:
196196
run: app
197+
require-prebuild: true
197198
```
198199

199-
All `run` steps for the service `app` will automatically pull and use the pre-built image. Without this, each `Test %n` job would build its own instead.
200+
All `run` steps for the service `app` will automatically pull and use the pre-built image. Note that, for the example to work as-is, the `app` service needs to have an `image` element defined or the build/push step needs to be changed to `push: app:the_registry:the_tag` (and the agent running all the steps need to be authenticated against the registry if required).
201+
202+
Note that the `require-prebuild` option means that if no prebuilt image is found, all `Test %n` jobs will fail. Without it, if the agent the `Test %n` is running on has ever built such an image and has it appropriately tagged it may still run.
200203

201204
### Building multiple images
202205

plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ configuration:
9393
type: integer
9494
quiet-pull:
9595
type: boolean
96+
require-prebuild:
97+
type: boolean
9698
rm:
9799
type: boolean
98100
run-image:
@@ -168,6 +170,7 @@ configuration:
168170
pull-retries: [ run ]
169171
push-retries: [ push ]
170172
quiet-pull: [ run ]
173+
require-prebuild: [ run ]
171174
rm: [ run ]
172175
run-image: [ run ]
173176
run-labels: [ run ]

tests/run.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ teardown() {
4343
unstub buildkite-agent
4444
}
4545

46+
@test "Fail running without a prebuilt image and require-prebuild" {
47+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
48+
export BUILDKITE_COMMAND="echo hello world"
49+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_REQUIRE_PREBUILD=true
50+
51+
stub buildkite-agent \
52+
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"
53+
54+
run "$PWD"/hooks/command
55+
56+
assert_failure
57+
assert_output --partial "No pre-built image found"
58+
59+
unstub buildkite-agent
60+
}
61+
4662
@test "Run without a prebuilt image and an empty command" {
4763
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
4864
export BUILDKITE_COMMAND=""

0 commit comments

Comments
 (0)