Skip to content

Commit f81cd95

Browse files
committed
Tag Docker images with Git SHA
PR #230 updated the action to pull Docker images from GHCR instead of building Docker images each time the workflow runs. As part of this PR, a new GitHub Actions workflow was added that builds Docker images and pushes them to GitHub Container Registry (GHCR). Actions can be referenced in various ways. The Docker build workflow covers most of the action references, but does not push Docker images tagged with the Git commit ID (Git SHA). This commit will add Docker tags for referencing the action with a Git SHA. GitHub Actions only supports references by the full 40 character SHA. If users try to reference the action by a short SHA like `1234567`, they will get an error like, "Unable to resolve action `pypa/gh-action-pypi-publish@1234567`, the provided ref `1234567` is the shortened version of a commit SHA, which is not supported. Please use the full commit SHA `1234567890123456789012345678901234567890` instead." #230 #290 https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-pre-written-building-blocks-in-your-workflow#using-shas
1 parent 15c56db commit f81cd95

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: .github/workflows/build-and-push-docker-image.yml

+4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ jobs:
3232
IMAGE="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG}"
3333
IMAGE_MAJOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR}"
3434
IMAGE_MAJOR_MINOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR_MINOR}"
35+
IMAGE_SHA="ghcr.io/$GITHUB_REPOSITORY:${GITHUB_SHA}"
3536
echo "IMAGE=$IMAGE" >>"$GITHUB_ENV"
3637
echo "IMAGE_MAJOR=$IMAGE_MAJOR" >>"$GITHUB_ENV"
3738
echo "IMAGE_MAJOR_MINOR=$IMAGE_MAJOR_MINOR" >>"$GITHUB_ENV"
39+
echo "IMAGE_SHA=$IMAGE_SHA" >>"$GITHUB_ENV"
3840
docker build . \
3941
--build-arg BUILDKIT_INLINE_CACHE=1 \
4042
--cache-from $IMAGE \
4143
--tag $IMAGE
4244
docker tag $IMAGE $IMAGE_MAJOR
4345
docker tag $IMAGE $IMAGE_MAJOR_MINOR
46+
docker tag $IMAGE $IMAGE_SHA
4447
env:
4548
DOCKER_TAG: ${{ inputs.tag || github.ref_name }}
4649
- name: Log in to GHCR
@@ -52,3 +55,4 @@ jobs:
5255
docker push $IMAGE
5356
docker push $IMAGE_MAJOR
5457
docker push $IMAGE_MAJOR_MINOR
58+
docker push $IMAGE_SHA

0 commit comments

Comments
 (0)