Skip to content

Commit b09c1e1

Browse files
authored
Create containerfile-upload.yml
1 parent d3ef897 commit b09c1e1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/containerfile-upload.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#name: Create and publish a Docker image
2+
3+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
4+
on:
5+
push:
6+
branches: ['main']
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+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
14+
jobs:
15+
build-and-push-image:
16+
runs-on: ubuntu-latest
17+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
18+
permissions:
19+
contents: read
20+
packages: write
21+
attestations: write
22+
id-token: write
23+
#
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
# 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.
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+
# 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.
35+
- name: Extract metadata (tags, labels) for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
# 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.
41+
# 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.
42+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
43+
- name: Build and push Docker image
44+
id: push
45+
uses: docker/build-push-action@v6
46+
with:
47+
context: .
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
52+
# 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).
53+
- name: Generate artifact attestation
54+
uses: actions/attest-build-provenance@v2
55+
with:
56+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
57+
subject-digest: ${{ steps.push.outputs.digest }}
58+
push-to-registry: true
59+

0 commit comments

Comments
 (0)