-
Notifications
You must be signed in to change notification settings - Fork 1
171 lines (151 loc) · 5.01 KB
/
docker-multiarch-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: CI/CD Pipeline
on:
schedule:
- cron: '0 1 * * *' # Daily security scans
push:
tags:
- "[1-9]+.[0-9]+.[0-9]+"
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Top-level permissions used as default for all jobs
permissions:
contents: write
packages: write
issues: write
pull-requests: write
security-events: write # Required for uploading Trivy scan results
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
security-scan:
runs-on: ubuntu-latest
# Job-specific permissions override - this job only needs security-events
permissions:
security-events: write # Required for github/codeql-action/upload-sarif
contents: read # Required for actions/checkout
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
lint:
runs-on: ubuntu-latest
permissions:
contents: read # Only needs read access for checkout
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run hadolint
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
- name: Run shellcheck
uses: ludeeus/action-shellcheck@master
with:
scandir: './scripts'
build-and-push:
needs: [security-scan, lint]
runs-on: ubuntu-latest
permissions:
contents: write # Changed from 'read' to 'write' for changelog commits
packages: write # For pushing to GHCR
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
docker.io/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=sha,format=long
type=ref,event=branch
type=ref,event=pr
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate changelog
if: github.event_name != 'pull_request'
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --verbose --tag ${{ steps.meta.outputs.version }}
env:
OUTPUT: CHANGELOG.md
- name: Commit and push changelog
if: github.event_name != 'pull_request'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'docs: update changelog for ${{ steps.meta.outputs.version }}'
file_pattern: CHANGELOG.md
branch: main
push_options: '--force'
notify:
needs: build-and-push
runs-on: ubuntu-latest
if: always()
permissions:
issues: write # Required for creating issue comments
pull-requests: write # Required for creating PR comments
steps:
- name: Notify status
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { repo, owner } = context.repo;
const run_id = context.runId;
const run_url = `https://github.com/${owner}/${repo}/actions/runs/${run_id}`;
const status = '${{ needs.build-and-push.result }}' === 'success' ? '✅' : '❌';
if (context.issue.number) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.issue.number,
body: `Build status: ${status}\nDetails: ${run_url}`
});
}