From 1676c1cfe4c3073d1fb44f73adb0266171eb2997 Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Sun, 24 Feb 2019 07:58:37 +1100 Subject: [PATCH 1/4] Add support for build aliases --- commands/build.sh | 8 ++++++++ tests/build.bats | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/commands/build.sh b/commands/build.sh index d375b580..8587a1c1 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -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 ALIAS) ; do + set_prebuilt_image "$service_alias" "${build_images[1]}" + done + + # pop-off the last build image build_images=("${build_images[@]:3}") done fi diff --git a/tests/build.bats b/tests/build.bats index fa0bebb9..54d3cd6f 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -82,6 +82,36 @@ load '../lib/shared' unstub buildkite-agent } +@test "Build with a repository and multiple 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_ALIAS_0=myservice-1 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_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 From 67931409bb50236e6b776bb8408569295b7a387a Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Sun, 24 Feb 2019 08:01:41 +1100 Subject: [PATCH 2/4] Document alias option --- README.md | 4 ++++ plugin.yml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 7d494761..45e11b9c 100644 --- a/README.md +++ b/README.md @@ -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. +### `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. diff --git a/plugin.yml b/plugin.yml index 296a5421..b531953c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -29,6 +29,9 @@ configuration: args: type: [ string, array ] minimum: 1 + alias: + type: [ string, array ] + minimum: image-repository: type: string image-name: From 739343208b7eb1b82be4495c5c2987df07fc439b Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Sun, 24 Feb 2019 08:07:16 +1100 Subject: [PATCH 3/4] Fix schema typo --- plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index b531953c..e1708277 100644 --- a/plugin.yml +++ b/plugin.yml @@ -31,7 +31,7 @@ configuration: minimum: 1 alias: type: [ string, array ] - minimum: + minimum: 1 image-repository: type: string image-name: From 302ec37fb82659df54974cf75d9f63813fe7d6b1 Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Sun, 24 Feb 2019 08:59:17 +1100 Subject: [PATCH 4/4] Update to build-alias --- README.md | 2 +- commands/build.sh | 2 +- plugin.yml | 2 +- tests/build.bats | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 45e11b9c..6b95e0b1 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ 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. -### `alias` (optional, build only) +### `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. diff --git a/commands/build.sh b/commands/build.sh index 8587a1c1..fdd8b000 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -92,7 +92,7 @@ if [[ -n "$image_repository" ]] ; then set_prebuilt_image "${build_images[0]}" "${build_images[1]}" # set aliases - for service_alias in $(plugin_read_list ALIAS) ; do + for service_alias in $(plugin_read_list BUILD_ALIAS) ; do set_prebuilt_image "$service_alias" "${build_images[1]}" done diff --git a/plugin.yml b/plugin.yml index e1708277..95ae4e0d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -29,7 +29,7 @@ configuration: args: type: [ string, array ] minimum: 1 - alias: + build-alias: type: [ string, array ] minimum: 1 image-repository: diff --git a/tests/build.bats b/tests/build.bats index 54d3cd6f..e7b30971 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -82,12 +82,12 @@ load '../lib/shared' unstub buildkite-agent } -@test "Build with a repository and multiple aliases" { +@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_ALIAS_0=myservice-1 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ALIAS_1=myservice-2 + 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