Skip to content

Commit 6a9f72c

Browse files
authored
Create image-publishing.yml
First attempt to automatically build WfExS-backend docker images
1 parent aca41e7 commit 6a9f72c

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Based on https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
2+
name: Create and publish WfExS-backend Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
workflow_dispatch:
7+
push:
8+
tags:
9+
# Push events to every tag not containing /
10+
# based on https://stackoverflow.com/a/61892639
11+
- '*'
12+
13+
# 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.
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
19+
jobs:
20+
build-and-push-image:
21+
runs-on: ubuntu-latest
22+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
23+
permissions:
24+
contents: read
25+
packages: write
26+
attestations: write
27+
id-token: write
28+
#
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@v3.3.0
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
# 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.
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v5.5.1
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
# 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.
46+
# 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.
47+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
48+
- name: Build and push Docker image
49+
id: push
50+
uses: docker/build-push-action@v6.7.0
51+
with:
52+
context: container_recipes
53+
build_args: |
54+
wfexs_checkout=${{ github.sha }}
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
59+
# 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)."
60+
- name: Generate artifact attestation
61+
uses: actions/attest-build-provenance@v1
62+
with:
63+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
64+
subject-digest: ${{ steps.push.outputs.digest }}
65+
push-to-registry: true
66+

0 commit comments

Comments
 (0)