Skip to content

Commit 028842e

Browse files
committed
publish docker images
1 parent ffdd393 commit 028842e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
17+
permissions:
18+
contents: read
19+
packages: write
20+
attestations: write
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v5
26+
27+
# Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
28+
- name: Log in to the Container registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
# 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.
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
# tag event
43+
type=ref,event=tag
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
47+
48+
# 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.
49+
# 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.
50+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
51+
- name: Build and push Docker image
52+
id: push
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
target: package
57+
push: true
58+
platforms: linux/amd64,linux/arm64
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
62+
# 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 [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
63+
- name: Generate artifact attestation
64+
uses: actions/attest-build-provenance@v3
65+
with:
66+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
67+
subject-digest: ${{ steps.push.outputs.digest }}
68+
push-to-registry: true

0 commit comments

Comments
 (0)