Skip to content

Commit

Permalink
Merge pull request #343 from buildkite-plugins/toote_periods_in_servi…
Browse files Browse the repository at this point in the history
…ces_issue-293

Periods in services
  • Loading branch information
pzeballos authored Oct 10, 2022
2 parents b2588fb + 183a1b6 commit 9c707dc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
13 changes: 11 additions & 2 deletions commands/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ push_retries="$(plugin_read_config PUSH_RETRIES "0")"
override_file="docker-compose.buildkite-${BUILDKITE_BUILD_NUMBER}-override.yml"
build_images=()

normalize_var_name() {
local orig_value="$1"
# POSIX variable names should match [a-zA-Z_][a-zA-Z0-9_]*
# service names and the like also allow periods and dashes
no_periods="${orig_value//./_}"
no_dashes="${no_periods//-/_}"
echo "${no_dashes}"
}

service_name_cache_from_var() {
local service_name="$1"
echo "cache_from__${service_name//-/_}"
echo "cache_from__$(normalize_var_name "${service_name}")"
}

service_name_group_name_cache_from_var() {
local service_name="$1"
local group_index="$2"
echo "group_cache_from__${service_name//-/_}__${group_index//-/_}"
echo "group_cache_from__$(normalize_var_name "${service_name}")__$(normalize_var_name "${group_index}")"
}

count_of_named_array() {
Expand Down
25 changes: 25 additions & 0 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,31 @@ load '../lib/shared'
unstub docker-compose
}

@test "Build with a service name and cache-from with period" {
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml"
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=hello.world
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=hello.world:my.repository/my-service_cache:latest
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1

stub docker \
"pull my.repository/my-service_cache:latest : echo pulled cache image"

stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \$9"

run $PWD/hooks/command

assert_success
assert_output --partial "pulled cache image"
assert_output --partial "- my.repository/my-service_cache:latest"
assert_output --partial "built hello.world"
unstub docker
unstub docker-compose
}


@test "Build with a cache-from image retry on failing pull" {
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml"
export BUILDKITE_JOB_ID=1111
Expand Down
21 changes: 21 additions & 0 deletions tests/v2/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,27 @@ setup_file() {
unstub docker
}

@test "Build with a service name and cache-from with period" {
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml"
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=hello.world
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=hello.world:my.repository/my-service_cache:latest
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1

stub docker \
"pull my.repository/my-service_cache:latest : echo pulled cache image" \
"compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${10}"

run $PWD/hooks/command

assert_success
assert_output --partial "pulled cache image"
assert_output --partial "- my.repository/my-service_cache:latest"
assert_output --partial "built hello.world"
unstub docker
}

@test "Build with a cache-from image retry on failing pull" {
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml"
export BUILDKITE_JOB_ID=1111
Expand Down

0 comments on commit 9c707dc

Please sign in to comment.