Skip to content

Commit e91070d

Browse files
authored
calculate-docker-image: add optional ci-docker-hash input (#8048)
Prep change for migrating tagged docker builds to ARC. When set, optional `ci-docker-hash` input to the `calculate-docker-image` is validated against the hash computed from `git rev-parse HEAD:<docker-build-dir>` and the step fails on mismatch.
1 parent 8f3c1f2 commit e91070d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

.github/actions/calculate-docker-image/action.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ inputs:
4545
repo-name:
4646
description: The name of the repository containing the docker-build-dir.
4747
required: false
48+
ci-docker-hash:
49+
description: |
50+
If provided, the action validates this value against the computed docker
51+
hash (from `git rev-parse HEAD:<docker-build-dir>`) and fails if they do
52+
not match.
53+
required: false
54+
default: ""
4855

4956
outputs:
5057
docker-image:
@@ -66,6 +73,7 @@ runs:
6673
DOCKER_REGISTRY: ${{ inputs.docker-registry }}
6774
USE_CUSTOM_DOCKER_REGISTRY: ${{ inputs.use-custom-docker-registry }}
6875
CUSTOM_TAG_PREFIX: ${{ inputs.custom-tag-prefix }}
76+
EXPECTED_CI_DOCKER_HASH: ${{ inputs.ci-docker-hash }}
6977
run: |
7078
set -ex
7179
@@ -93,7 +101,12 @@ runs:
93101
CUSTOM_TAG_PREFIX=${DOCKER_IMAGE_NAME#*:}
94102
DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME%%:*}
95103
fi
96-
DOCKER_TAG=${CUSTOM_TAG_PREFIX:+${CUSTOM_TAG_PREFIX}-}$(git rev-parse HEAD:"${DOCKER_BUILD_DIR}")
104+
COMPUTED_CI_DOCKER_HASH=$(git rev-parse HEAD:"${DOCKER_BUILD_DIR}")
105+
if [[ -n "${EXPECTED_CI_DOCKER_HASH}" && "${EXPECTED_CI_DOCKER_HASH}" != "${COMPUTED_CI_DOCKER_HASH}" ]]; then
106+
echo "ERROR: ci-docker-hash mismatch: expected '${EXPECTED_CI_DOCKER_HASH}', computed '${COMPUTED_CI_DOCKER_HASH}' for '${DOCKER_BUILD_DIR}'"
107+
exit 1
108+
fi
109+
DOCKER_TAG=${CUSTOM_TAG_PREFIX:+${CUSTOM_TAG_PREFIX}-}${COMPUTED_CI_DOCKER_HASH}
97110
echo "docker-tag=${DOCKER_TAG}" >> "${GITHUB_OUTPUT}"
98111
echo "docker-image=${DOCKER_REGISTRY}/${REPO_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_TAG}" >> "${GITHUB_OUTPUT}"
99112
echo "custom-tag-prefix=${CUSTOM_TAG_PREFIX}" >> "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)