Skip to content

Commit

Permalink
Merge pull request #201 from buildkite-plugins/add-build-aliases
Browse files Browse the repository at this point in the history
Add build aliases
  • Loading branch information
lox committed Feb 24, 2019
2 parents 39cdabc + 302ec37 commit 270dc76
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -335,6 +335,10 @@ This option can also be configured on the agent machine using the environment va

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.

### `build-alias` (optional, build only)

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.

### `args` (optional, build only)

A list of KEY=VALUE that are passed through as build arguments when image is being built.
Expand Down
8 changes: 8 additions & 0 deletions commands/build.sh
Expand Up @@ -87,8 +87,16 @@ if [[ -n "$image_repository" ]] ; then
echo "~~~ :docker: Pushing built images to $image_repository"
retry "$push_retries" run_docker_compose -f "$override_file" push "${services[@]}"

# iterate over build images
while [[ ${#build_images[@]} -gt 0 ]] ; do
set_prebuilt_image "${build_images[0]}" "${build_images[1]}"

# set aliases
for service_alias in $(plugin_read_list BUILD_ALIAS) ; do
set_prebuilt_image "$service_alias" "${build_images[1]}"
done

# pop-off the last build image
build_images=("${build_images[@]:3}")
done
fi
3 changes: 3 additions & 0 deletions plugin.yml
Expand Up @@ -29,6 +29,9 @@ configuration:
args:
type: [ string, array ]
minimum: 1
build-alias:
type: [ string, array ]
minimum: 1
image-repository:
type: string
image-name:
Expand Down
30 changes: 30 additions & 0 deletions tests/build.bats
Expand Up @@ -82,6 +82,36 @@ load '../lib/shared'
unstub buildkite-agent
}

@test "Build with a repository and multiple build aliases" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY=my.repository/llamas
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_0=myservice-1
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_1=myservice-2
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull myservice : echo built myservice" \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml push myservice : echo pushed myservice" \

stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice" \
"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" \
"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"

run $PWD/hooks/command

assert_success
assert_output --partial "built myservice"
assert_output --partial "pushed myservice"
assert_output --partial "set image metadata for myservice"
assert_output --partial "set image metadata for myservice-1"
assert_output --partial "set image metadata for myservice-2"
unstub docker-compose
unstub buildkite-agent
}

@test "Build with a repository and push retries" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
Expand Down

0 comments on commit 270dc76

Please sign in to comment.