-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from buildkite-plugins/fix-broken-image-prebuild
Fix broken prebuild, closes #50
- Loading branch information
Showing
10 changed files
with
142 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
readonly META_IMAGE_COUNT=built-image-count | ||
readonly META_IMAGE_TAG_IDX=built-image-tag- | ||
readonly META_IMAGE_TAG=built-image-tag- | ||
|
||
# Read agent metadata for the plugin | ||
function plugin_get_metadata() { | ||
local key="docker-compose-plugin-$1" | ||
plugin_prompt buildkite-agent meta-data get "$key" | ||
buildkite-agent meta-data get "$key" | ||
} | ||
|
||
# Write agent metadata for the plugin | ||
function plugin_set_metadata() { | ||
local key="docker-compose-plugin-$1" | ||
local value="$2" | ||
plugin_prompt_and_must_run buildkite-agent meta-data set "$key" "$value" | ||
} | ||
|
||
# Gets a list of service / image pairs, each pair on a newline, delimited by space | ||
function get_prebuilt_images_from_metadata() { | ||
local service | ||
local image | ||
local count | ||
count=$(plugin_get_metadata "$META_IMAGE_COUNT") | ||
|
||
[[ $count -gt 0 ]] || return 0 | ||
|
||
for i in $(seq 0 $((count-1))) ; do | ||
service="$(plugin_get_metadata "${META_IMAGE_TAG_IDX}${i}")" | ||
image="$(plugin_get_metadata "${META_IMAGE_TAG}${service}")" | ||
echo "$service $image" | ||
i=$((i+1)) | ||
done | ||
} | ||
|
||
# Helper for use with get_prebuilt_images_from_metadata | ||
function get_services_from_map() { | ||
for ((n=1;n<$#;n++)) ; do | ||
if (( $((n % 2)) == 1 )) ; then | ||
echo ${!n} | ||
fi | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#!/usr/bin/env bats | ||
|
||
load '/usr/local/lib/bats/load.bash' | ||
load '../lib/shared' | ||
load '../lib/metadata' | ||
|
||
@test "Get prebuilt images from agent metadata (two images)" { | ||
stub buildkite-agent \ | ||
"meta-data get docker-compose-plugin-built-image-count : echo 2" \ | ||
"meta-data get docker-compose-plugin-built-image-tag-0 : echo service1" \ | ||
"meta-data get docker-compose-plugin-built-image-tag-service1 : echo image" \ | ||
"meta-data get docker-compose-plugin-built-image-tag-1 : echo service2" \ | ||
"meta-data get docker-compose-plugin-built-image-tag-service2 : echo image " | ||
|
||
run get_prebuilt_images_from_metadata | ||
|
||
assert_success | ||
assert_output --partial "service1 image" | ||
assert_output --partial "service2 image" | ||
unstub buildkite-agent | ||
} | ||
|
||
@test "Get prebuilt images from agent metadata (no images)" { | ||
stub buildkite-agent \ | ||
"meta-data get docker-compose-plugin-built-image-count : echo 0" | ||
|
||
run get_prebuilt_images_from_metadata | ||
|
||
assert_success | ||
unstub buildkite-agent | ||
} | ||
|
||
@test "Get services from an image map" { | ||
image_map=( | ||
"myservice1" "myimage1" | ||
"myservice2" "myimage2" | ||
) | ||
run get_services_from_map "${image_map[@]}" | ||
|
||
assert_success | ||
assert_equal "${#lines[@]}" "2" | ||
assert_equal "${lines[0]}" "myservice1" | ||
assert_equal "${lines[1]}" "myservice2" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters