diff --git a/entrypoint.sh b/entrypoint.sh index 6032f93..1ba1a63 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,8 +45,9 @@ if [ ! -z "${INPUT_DOCKERFILE}" ]; then fi if [ ! -z "${INPUT_CACHE}" ]; then - docker pull ${DOCKERNAME} - BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}" + if docker pull ${DOCKERNAME} 2>/dev/null; then + BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}" + fi fi if [ "${INPUT_SNAPSHOT}" = "true" ]; then diff --git a/stub.sh b/stub.sh index 36eb9b2..0558bfc 100755 --- a/stub.sh +++ b/stub.sh @@ -1,3 +1,7 @@ #!/bin/sh -echo "Called mock with: $@" +parameters="$@" +echo "Called mock with: ${parameters}" +if [ "${MOCK_ERROR_CONDITION}" = "${parameters}" ]; then + exit 1 +fi exit 0 diff --git a/test.bats b/test.bats index 67f83cb..ac484d0 100755 --- a/test.bats +++ b/test.bats @@ -14,6 +14,7 @@ teardown() { unset INPUT_CACHE unset GITHUB_SHA unset INPUT_PULL_REQUESTS + unset MOCK_ERROR_CONDITION } @test "it pushes master branch to latest" { @@ -115,6 +116,25 @@ Called mock with: logout" [ "$output" = "$expected" ] } +@test "it does not use the cache for building when pulling the former image failed" { + export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7' + export MOCK_DATE='197001010101' + export INPUT_SNAPSHOT='true' + export INPUT_CACHE='true' + export MOCK_ERROR_CONDITION='pull my/repository:latest' + + run /entrypoint.sh + + local expected="Called mock with: login -u USERNAME --password-stdin +Called mock with: pull my/repository:latest +Called mock with: build -t my/repository:latest -t my/repository:19700101010112169e . +Called mock with: push my/repository:latest +Called mock with: push my/repository:19700101010112169e +Called mock with: logout" + echo $output + [ "$output" = "$expected" ] +} + @test "it pushes branch by sha and date with specific Dockerfile" { export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7' export MOCK_DATE='197001010101'