From be871aa4d9612678567f882e0a75f1f14c95b02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 17 Oct 2022 18:27:02 -0300 Subject: [PATCH 1/2] Allow for tag-less cache-from --- commands/build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/build.sh b/commands/build.sh index b382a771..bf69d673 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -51,7 +51,11 @@ if [[ "$(plugin_read_config NO_CACHE "false")" == "false" ]] ; then IFS=':' read -r -a tokens <<< "$line" service_name=${tokens[0]} service_image=$(IFS=':'; echo "${tokens[*]:1:2}") - service_tag=${tokens[2]} + if [ ${#tokens[@]} -gt 2 ]; then + service_tag=${tokens[2]} + else + service_tag="latest" + fi if ! validate_tag "$service_tag"; then echo "🚨 cache-from ${service_image} has an invalid tag so it will be ignored" From 1b0913111038b260a19f5a2550bc66c1d8f03fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 17 Oct 2022 18:27:16 -0300 Subject: [PATCH 2/2] Added tests for tag-less cache-from --- tests/build.bats | 25 +++++++++++++++++++++++++ tests/v2/build.bats | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tests/build.bats b/tests/build.bats index 30efdf35..d0af63a5 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -330,6 +330,31 @@ load '../lib/shared' unstub docker-compose } +@test "Build with a cache-from image with no tag" { + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PIPELINE_SLUG=test + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" + + stub docker \ + "pull my.repository/myservice_cache : 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 helloworld : echo built helloworld" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "pulled cache image" + assert_output --partial "- my.repository/myservice_cache" + assert_output --partial "built helloworld" + unstub docker + unstub docker-compose +} + @test "Build with several cache-from images for one service" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" export BUILDKITE_JOB_ID=1111 diff --git a/tests/v2/build.bats b/tests/v2/build.bats index a61bed27..298a3d74 100644 --- a/tests/v2/build.bats +++ b/tests/v2/build.bats @@ -293,6 +293,28 @@ setup_file() { unstub docker } +@test "Build with a cache-from image with no tag" { + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PIPELINE_SLUG=test + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" + + stub docker \ + "pull my.repository/myservice_cache : echo pulled cache image" \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "pulled cache image" + assert_output --partial "- my.repository/myservice_cache" + assert_output --partial "built helloworld" + unstub docker +} + @test "Build with a cache-from image with no-cache also set" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" export BUILDKITE_JOB_ID=1111