diff options
author | 2020-02-21 21:25:31 -0800 | |
---|---|---|
committer | 2020-02-21 22:39:27 -0800 | |
commit | ed43d568651fc6c68e7aebd95680486ee95bc6f4 (patch) | |
tree | 9b87fecec3ba36c1b4d2495eb49ac70686c2f0cb | |
parent | CI: fix base image build condition (diff) |
CI: create a function to check if an image can be pulled
-rwxr-xr-x | scripts/check_dockerfiles.sh | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/scripts/check_dockerfiles.sh b/scripts/check_dockerfiles.sh index a0294b1..f2b8512 100755 --- a/scripts/check_dockerfiles.sh +++ b/scripts/check_dockerfiles.sh @@ -32,6 +32,31 @@ get_build() { fi } +can_pull() { + local image="${1:?"can_pull: argument 1 'image' is unset"}" + + local master_commit + if master_commit="$( + get_build "refs/heads/master" \ + | jq -re '.value[0].sourceVersion' + )" \ + && git diff --quiet "${master_commit}" -- "${@:2}" + then + printf \ + '%s\n' \ + "Can pull ${image} image from Docker Hub; no changes since master." + + printf '%s\n' "##vso[task.setvariable variable=${image^^}_PULL]True" + else + printf \ + '%s\n' \ + "Cannot pull ${image} image from Docker Hub due to detected " \ + "changes; the ${image} image will be built." + + return 1 + fi +} + # Get the previous commit if [[ "${BUILD_REASON}" = "PullRequest" ]]; then if ! prev_commit="$( @@ -80,17 +105,5 @@ else "the venv image will be built." # Though base image hasn't changed, it's still needed to build the venv. - if master_commit="$( - get_build "refs/heads/master" \ - | jq -re '.value[0].sourceVersion' - )" \ - && git diff --quiet "${master_commit}" -- docker/base.Dockerfile - then - echo "Can pull base image from Docker Hub; no changes since master." - echo "##vso[task.setvariable variable=BASE_PULL]True" - else - echo \ - "Cannot pull base image from Docker Hub due to detected changes;" \ - "the base image will be built." - fi + can_pull base docker/base.Dockerfile fi |