Skip to content

Commit 4f45784

Browse files
authored
build: release container image with github action (#246)
* build: release container image with github action * build: use semver
1 parent 19fc95d commit 4f45784

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/image.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: image build
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
20+
steps:
21+
- name: Get commit to build
22+
id: ref
23+
run: |-
24+
if [[ -z "${{ github.event.inputs.tag }}" ]]; then
25+
ref="${{ github.ref_name }}"
26+
else
27+
ref="${{ github.event.inputs.tag }}"
28+
fi
29+
echo "ref=$ref"
30+
echo "ref=$ref" >> $GITHUB_OUTPUT
31+
if [[ $ref == *"-"* ]]; then
32+
latest=latest-beta
33+
else
34+
latest=latest
35+
fi
36+
echo "latest=$latest"
37+
echo "latest=$latest" >> $GITHUB_OUTPUT
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
with:
41+
ref: ${{ steps.ref.outputs.ref }}
42+
- name: Set up QEMU
43+
uses: docker/setup-qemu-action@v3
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Extract metadata (tags, labels) for Docker
53+
id: meta
54+
uses: docker/metadata-action@v5
55+
with:
56+
images: ghcr.io/${{ env.IMAGE_NAME }}
57+
tags: |
58+
type=ref,event=pr
59+
type=ref,event=branch
60+
type=semver,pattern={{version}}
61+
type=semver,pattern={{major}}.{{minor}}
62+
- name: Build and push Docker image
63+
id: push
64+
uses: docker/build-push-action@v6
65+
with:
66+
platforms: linux/amd64,linux/arm64
67+
context: .
68+
push: true
69+
tags: ${{ steps.meta.outputs.tags }}
70+
target: runner

0 commit comments

Comments
 (0)