Skip to content

Commit a8cef24

Browse files
committedAug 13, 2024
Add dockertag.yaml workflow
1 parent 735ca4e commit a8cef24

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
 

‎.github/workflows/dockertag.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Create and publish a Docker image
2+
on:
3+
push:
4+
branches: ["main"]
5+
env:
6+
REGISTRY: ghcr.io
7+
IMAGE_NAME: ${{ github.repository }}
8+
jobs:
9+
build-and-push-image:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
attestations: write
15+
id-token: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
- name: Log in to the Container registry
20+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
21+
with:
22+
registry: ${{ env.REGISTRY }}
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
26+
- name: Extract metadata (tags, labels) for Docker
27+
id: meta
28+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
29+
with:
30+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
31+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
32+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
33+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
34+
- name: Build and push Docker image
35+
id: push
36+
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85
37+
with:
38+
context: .
39+
push: true
40+
tags: ${{ steps.meta.outputs.tags }}
41+
labels: ${{ steps.meta.outputs.labels }}
42+
43+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
44+
- name: Generate artifact attestation
45+
uses: actions/attest-build-provenance@310b0a4a3b0b78ef57ecda988ee04b132db73ef8
46+
with:
47+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
48+
subject-digest: ${{ steps.push.outputs.digest }}
49+
push-to-registry: true

0 commit comments

Comments
 (0)
Failed to load comments.