Skip to content

Commit c9f2c8d

Browse files
committed
feat: appply slopus#7
feat: add GitHub Actions Docker workflo
1 parent 5ba780c commit c9f2c8d

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

.github/workflows/docker.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main, master, develop ]
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build-and-push:
17+
name: Build and Push Multi-Architecture Docker Image
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
id-token: write
23+
attestations: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set up QEMU
32+
uses: docker/setup-qemu-action@v3
33+
with:
34+
platforms: linux/amd64,linux/arm64
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
with:
39+
platforms: linux/amd64,linux/arm64
40+
41+
- name: Log in to Container Registry
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Extract metadata
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+
tags: |
55+
# set latest tag for default branch
56+
type=ref,event=branch
57+
type=ref,event=pr
58+
type=semver,pattern={{version}}
59+
type=semver,pattern={{major}}.{{minor}}
60+
type=semver,pattern={{major}}
61+
type=raw,value=latest,enable={{is_default_branch}}
62+
type=sha,prefix={{branch}}-,enable={{is_default_branch}}
63+
type=sha,prefix=sha-,enable=${{ github.event_name == 'pull_request' }}
64+
65+
- name: Build and push Docker image
66+
id: build
67+
uses: docker/build-push-action@v5
68+
with:
69+
context: .
70+
file: ./Dockerfile
71+
platforms: linux/amd64,linux/arm64
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
cache-from: type=gha
76+
cache-to: type=gha,mode=max
77+
provenance: false
78+
79+
- name: Generate artifact attestation
80+
if: github.event_name != 'pull_request'
81+
uses: actions/attest-build-provenance@v1
82+
with:
83+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
84+
subject-digest: ${{ steps.build.outputs.digest }}
85+
push-to-registry: true

0 commit comments

Comments
 (0)