Skip to content

Commit 270dc76

Browse files
authored
Merge pull request buildkite-plugins#201 from buildkite-plugins/add-build-aliases
Add build aliases
2 parents 39cdabc + 302ec37 commit 270dc76

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ This option can also be configured on the agent machine using the environment va
335335

336336
The name to use when tagging pre-built images. If multiple images are built in the build phase, you must provide an array of image names.
337337

338+
### `build-alias` (optional, build only)
339+
340+
Other docker-compose services that should be aliased to the main service that was built. This is for when different docker-compose services share the same prebuilt image.
341+
338342
### `args` (optional, build only)
339343

340344
A list of KEY=VALUE that are passed through as build arguments when image is being built.

commands/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ if [[ -n "$image_repository" ]] ; then
8787
echo "~~~ :docker: Pushing built images to $image_repository"
8888
retry "$push_retries" run_docker_compose -f "$override_file" push "${services[@]}"
8989

90+
# iterate over build images
9091
while [[ ${#build_images[@]} -gt 0 ]] ; do
9192
set_prebuilt_image "${build_images[0]}" "${build_images[1]}"
93+
94+
# set aliases
95+
for service_alias in $(plugin_read_list BUILD_ALIAS) ; do
96+
set_prebuilt_image "$service_alias" "${build_images[1]}"
97+
done
98+
99+
# pop-off the last build image
92100
build_images=("${build_images[@]:3}")
93101
done
94102
fi

plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ configuration:
2929
args:
3030
type: [ string, array ]
3131
minimum: 1
32+
build-alias:
33+
type: [ string, array ]
34+
minimum: 1
3235
image-repository:
3336
type: string
3437
image-name:

tests/build.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ load '../lib/shared'
8282
unstub buildkite-agent
8383
}
8484

85+
@test "Build with a repository and multiple build aliases" {
86+
export BUILDKITE_JOB_ID=1111
87+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
88+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY=my.repository/llamas
89+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_0=myservice-1
90+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_1=myservice-2
91+
export BUILDKITE_PIPELINE_SLUG=test
92+
export BUILDKITE_BUILD_NUMBER=1
93+
94+
stub docker-compose \
95+
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull myservice : echo built myservice" \
96+
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml push myservice : echo pushed myservice" \
97+
98+
stub buildkite-agent \
99+
"meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice" \
100+
"meta-data set docker-compose-plugin-built-image-tag-myservice-1 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-1" \
101+
"meta-data set docker-compose-plugin-built-image-tag-myservice-2 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-2"
102+
103+
run $PWD/hooks/command
104+
105+
assert_success
106+
assert_output --partial "built myservice"
107+
assert_output --partial "pushed myservice"
108+
assert_output --partial "set image metadata for myservice"
109+
assert_output --partial "set image metadata for myservice-1"
110+
assert_output --partial "set image metadata for myservice-2"
111+
unstub docker-compose
112+
unstub buildkite-agent
113+
}
114+
85115
@test "Build with a repository and push retries" {
86116
export BUILDKITE_JOB_ID=1111
87117
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice

0 commit comments

Comments
 (0)