Skip to content

Commit 10670ca

Browse files
author
Divanshu
authored
Merge pull request #3 from dvanhu/fix-ghcr-tagging-docs-final-3
Update container image tagging strategy and workflow
2 parents ac663e8 + fa6e471 commit 10670ca

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

content/packages/working-with-a-github-packages-registry/working-with-the-container-registry.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ The easiest way to connect a repository to a container package is to publish the
9292

9393
To connect a repository when publishing an image from the command line, and to ensure your `GITHUB_TOKEN` has appropriate permissions when using a GitHub Actions workflow, we recommend adding the label `org.opencontainers.image.source` to your `Dockerfile`. For more information, see “[Labelling container images](#labelling-container-images)” in this article and “[AUTOTITLE](/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions).”
9494

95-
## Pulling container images
96-
## CI/CD tagging strategy for multi-environment deployments
95+
## CI/CD tagging strategy for container images
9796

9897
A consistent tagging strategy helps trace container images back to their source commits, simplify environment promotion, and improve rollback reliability.
9998

@@ -102,7 +101,7 @@ A consistent tagging strategy helps trace container images back to their source
102101
Apply multiple tags to the same image digest during each build so deployments can reference images by stability level or exact provenance.
103102

104103
| Tag pattern | Example | Purpose |
105-
|---|---|---|
104+
| --- | --- | --- |
106105
| Commit SHA (short) | `sha-a1b2c3d` | Immutable reference suitable for production rollbacks |
107106
| Branch name | `main`, `release-1.4` | Mutable tag that tracks the latest build for a branch |
108107
| Semantic version | `v1.4.2` | Human-readable release version |
@@ -112,10 +111,15 @@ Apply multiple tags to the same image digest during each build so deployments ca
112111
> Avoid relying solely on the `latest` tag in automated deployment pipelines. Because `latest` is mutable, it does not provide reliable traceability between deployments and source revisions.
113112
114113
### Applying multiple tags in a GitHub Actions workflow
114+
> [!NOTE]
115+
> Avoid relying solely on the `latest` tag in automated deployment pipelines. Because `latest` is mutable, it does not provide reliable traceability between deployments and source revisions.
115116
116-
Use the `docker/metadata-action` action to generate image tags automatically from Git context and pass them to `docker/build-push-action`.
117+
### Applying multiple tags in a GitHub Actions workflow
117118

119+
Use the `docker/metadata-action` action to generate image tags automatically from Git context and pass them to `docker/build-push-action`.
118120
```yaml
121+
{% data reusables.actions.actions-not-certified-by-github-comment %}
122+
119123
jobs:
120124
build-and-push:
121125
runs-on: ubuntu-latest
@@ -126,35 +130,33 @@ jobs:
126130

127131
steps:
128132
- name: Check out repository
129-
uses: actions/checkout@v4
133+
uses: {% data reusables.actions.action-checkout %}
130134

131135
- name: Log in to the Container registry
132-
uses: docker/login-action@v3
136+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
133137
with:
134138
registry: ghcr.io
135-
username: ${{ github.actor }}
136-
password: ${{ secrets.GITHUB_TOKEN }}
139+
username: {% raw %}${{ github.actor }}{% endraw %}
140+
password: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
137141

138142
- name: Extract Docker metadata
139143
id: meta
140-
uses: docker/metadata-action@v5
144+
uses: docker/metadata-action@902fa8ecf8ec1ac25377c6f6f4d8d0623f8b3f5f
141145
with:
142-
images: ghcr.io/${{ github.repository }}
146+
images: ghcr.io/{% raw %}${{ github.repository }}{% endraw %}
143147
tags: |
144148
type=sha,prefix=sha-,format=short
145149
type=ref,event=branch
146150
type=semver,pattern={{version}}
147-
type=raw,value=staging,enable=${{ github.ref == 'refs/heads/main' }}
148151
149152
- name: Build and push Docker image
150-
uses: docker/build-push-action@v5
153+
uses: docker/build-push-action@3b5e8027fcad23fda98b5c0ddc7d1f9d7d8d4f3b
151154
with:
152155
context: .
153156
push: true
154-
tags: ${{ steps.meta.outputs.tags }}
155-
labels: ${{ steps.meta.outputs.labels }}
157+
tags: {% raw %}${{ steps.meta.outputs.tags }}{% endraw %}
158+
labels: {% raw %}${{ steps.meta.outputs.labels }}{% endraw %}
156159
```
157-
158160
All tags generated during the workflow reference the same image digest. This allows deployments to promote existing images between environments without rebuilding the container image.
159161
160162
### Verifying tag-to-digest traceability

0 commit comments

Comments
 (0)