Skip to content

Commit e5f5ca3

Browse files
author
Divanshu
authored
Refactor GitHub Actions workflow for container registry
Updated GitHub Actions workflow to use reusable actions and raw syntax for variables.
1 parent ac663e8 commit e5f5ca3

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ Apply multiple tags to the same image digest during each build so deployments ca
114114
### Applying multiple tags in a GitHub Actions workflow
115115

116116
Use the `docker/metadata-action` action to generate image tags automatically from Git context and pass them to `docker/build-push-action`.
117-
118117
```yaml
118+
{% data reusables.actions.actions-not-certified-by-github-comment %}
119+
119120
jobs:
120121
build-and-push:
121122
runs-on: ubuntu-latest
@@ -126,35 +127,33 @@ jobs:
126127

127128
steps:
128129
- name: Check out repository
129-
uses: actions/checkout@v4
130+
uses: {% data reusables.actions.action-checkout %}
130131

131132
- name: Log in to the Container registry
132-
uses: docker/login-action@v3
133+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
133134
with:
134135
registry: ghcr.io
135-
username: ${{ github.actor }}
136-
password: ${{ secrets.GITHUB_TOKEN }}
136+
username: {% raw %}${{ github.actor }}{% endraw %}
137+
password: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
137138

138139
- name: Extract Docker metadata
139140
id: meta
140-
uses: docker/metadata-action@v5
141+
uses: docker/metadata-action@902fa8ecf8ec1ac25377c6f6f4d8d0623f8b3f5f
141142
with:
142-
images: ghcr.io/${{ github.repository }}
143+
images: ghcr.io/{% raw %}${{ github.repository }}{% endraw %}
143144
tags: |
144145
type=sha,prefix=sha-,format=short
145146
type=ref,event=branch
146147
type=semver,pattern={{version}}
147-
type=raw,value=staging,enable=${{ github.ref == 'refs/heads/main' }}
148148
149149
- name: Build and push Docker image
150-
uses: docker/build-push-action@v5
150+
uses: docker/build-push-action@3b5e8027fcad23fda98b5c0ddc7d1f9d7d8d4f3b
151151
with:
152152
context: .
153153
push: true
154-
tags: ${{ steps.meta.outputs.tags }}
155-
labels: ${{ steps.meta.outputs.labels }}
154+
tags: {% raw %}${{ steps.meta.outputs.tags }}{% endraw %}
155+
labels: {% raw %}${{ steps.meta.outputs.labels }}{% endraw %}
156156
```
157-
158157
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.
159158
160159
### Verifying tag-to-digest traceability

0 commit comments

Comments
 (0)