Skip to content

Commit 2886831

Browse files
committed
Redo release workflow
1 parent 4f05b73 commit 2886831

File tree

1 file changed

+50
-61
lines changed

1 file changed

+50
-61
lines changed

.github/workflows/release.yml

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,73 @@
1-
name: Release
2-
# Controls when the workflow will run
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`.
34
on:
4-
release:
5-
types:
6-
- published
5+
pull_request:
6+
branches: main
7+
push:
8+
branches: main
9+
tags: v.*
10+
11+
# 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.
12+
env:
13+
REGISTRY: ghcr.io
714

15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
816
jobs:
9-
buildpush:
17+
build-and-push-image:
1018
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
1120
permissions:
21+
id-token: write
1222
contents: read
1323
packages: write
24+
attestations: write
25+
1426
steps:
15-
- # Get the repository's code
16-
name: Checkout
17-
uses: actions/checkout@v2
18-
- # https://github.com/vegardit/docker-gitea-act-runner/issues/23
19-
name: Fix docker sock permissions
20-
run: sudo chmod 666 /var/run/docker.sock
21-
- # https://github.com/docker/setup-qemu-action
22-
name: Set up QEMU
23-
uses: docker/setup-qemu-action@v1
24-
- # https://github.com/docker/setup-buildx-action
25-
name: Set up Docker Buildx
26-
id: buildx
27-
uses: docker/setup-buildx-action@v1
28-
- # https://github.com/docker/login-action
29-
name: Log in to the Container registry
30-
uses: docker/login-action@v2
27+
- name: Set image name
28+
run: |
29+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
# 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.
34+
- name: Log in to the Container registry
35+
uses: docker/login-action@v3
3136
with:
32-
# Maybe there is a default env var for this?
33-
registry: git.maronato.dev
34-
username: ${{ github.repository_owner }}}
35-
# Ideally, we should only need to set "permissions: package: write", but
36-
# Gitea is having issues with that. For now, this is a manually created
37-
# token available user-wise, with the "package:write" permission.
38-
password: ${{ secrets.PACKAGE_WRITE_TOKEN }}
39-
- # https://github.com/docker/metadata-action
40-
# Generate tags and labels for the image
41-
# according to the commit and the branch
42-
name: Docker meta
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
# 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.
41+
- name: Extract metadata (tags, labels) for Docker
4342
id: meta
44-
uses: docker/metadata-action@v4
43+
uses: docker/metadata-action@v5
4544
with:
46-
# The container image name needs the custom registry in it.
47-
# Maybe there is a default env var for this?
48-
images: git.maronato.dev/${{ github.repository }}
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4946
tags: |
5047
type=ref,event=branch
5148
type=ref,event=pr
5249
type=semver,pattern={{version}}
5350
type=semver,pattern={{major}}.{{minor}}
54-
- # httos://github.com/actions/cache
55-
name: Cache Docker layers
56-
uses: actions/cache@v3
57-
with:
58-
path: |
59-
/go/pkg/mod/
60-
/tmp/.go-build-cache
61-
/tmp/.buildx-cache
62-
key: ${{ runner.os }}-buildx-${{ github.sha }}
63-
restore-keys: |
64-
${{ runner.os }}-buildx-
65-
- # https://github.com/docker/build-push-action
66-
name: Build and push
67-
uses: docker/build-push-action@v2
51+
52+
# 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.
53+
# 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.
54+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
55+
- name: Build and push Docker image
56+
id: push
57+
uses: docker/build-push-action@v6
6858
with:
6959
context: .
7060
build-args: |
7161
VERSION=${{ steps.meta.outputs.version }}
7262
platforms: linux/amd64,linux/arm64
73-
push: ${{ github.event_name != 'pull_request' }}
63+
push: true
7464
tags: ${{ steps.meta.outputs.tags }}
7565
labels: ${{ steps.meta.outputs.labels }}
76-
cache-from: type=local,src=/tmp/.buildx-cache
77-
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
78-
- # Temp fix
79-
# https://github.com/docker/build-push-action/issues/252
80-
# https://github.com/moby/buildkit/issues/1896
81-
name: Move cache
82-
run: |
83-
rm -rf /tmp/.buildx-cache
84-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
66+
67+
# 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)."
68+
- name: Generate artifact attestation
69+
uses: actions/attest-build-provenance@v1
70+
with:
71+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
72+
subject-digest: ${{ steps.push.outputs.digest }}
73+
push-to-registry: true

0 commit comments

Comments
 (0)