-
Notifications
You must be signed in to change notification settings - Fork 21
269 lines (229 loc) · 7.46 KB
/
Copy pathbuild-scan-push.yml
File metadata and controls
269 lines (229 loc) · 7.46 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: Build, Scan, and Publish Docker Image
on:
push:
branches: [main]
tags: ['v*.*.*']
pull_request:
branches: [main]
workflow_dispatch:
schedule:
- cron: '0 6 * * 1' # Weekly security scan on Mondays
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
IMAGE_NAME: docker-bitlbee
DOCKERHUB_NAMESPACE: ${{ secrets.DOCKER_USERNAME }}
GHCR_NAMESPACE: ghcr.io/${{ github.repository_owner }}
jobs:
lint:
name: Lint & Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Hadolint (Dockerfile)
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
failure-threshold: warning
- name: yamllint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: docker-compose.yml .github/workflows/
config_data: |
extends: default
rules:
line-length:
max: 120
level: warning
- name: ShellCheck
uses: ludeeus/action-shellcheck@master
with:
severity: warning
- name: KubeLinter
if: hashFiles('k8s/**') != ''
uses: stackrox/kube-linter-action@v1
with:
directory: k8s
config: .kube-linter/config.yaml
build:
name: Build & Push Multi-Arch Image
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
packages: write
security-events: write
id-token: write
attestations: write
outputs:
image-digest: ${{ steps.build.outputs.digest }}
image-tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_NAMESPACE }}/${{ env.IMAGE_NAME }}
${{ env.GHCR_NAMESPACE }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix={{branch}}-
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
labels: |
org.opencontainers.image.title=BitlBee
org.opencontainers.image.description=BitlBee IRC gateway with plugins
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Build & Push
id: build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
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,scope=buildx-${{ github.workflow }}
cache-to: type=gha,mode=max,scope=buildx-${{ github.workflow }}
provenance: true
sbom: true
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Generate SBOM
if: github.event_name != 'pull_request'
uses: anchore/sbom-action@v0
with:
image: ${{ env.DOCKERHUB_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
format: cyclonedx-json
output-file: sbom.cyclonedx.json
- name: Upload SBOM artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.cyclonedx.json
retention-days: 30
security:
name: Security Scan
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
permissions:
security-events: write
contents: read
strategy:
matrix:
scanner: [trivy, grype]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
if: matrix.scanner == 'trivy'
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
format: sarif
output: trivy-results.sarif
ignore-unfixed: true
vuln-type: os,library
severity: CRITICAL,HIGH,MEDIUM
timeout: 10m
- name: Run Grype vulnerability scanner
if: matrix.scanner == 'grype'
uses: anchore/scan-action@v4
with:
image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
fail-build: false
severity-cutoff: high
output-format: sarif
output-file: grype-results.sarif
- name: Upload SARIF to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ matrix.scanner }}-results.sarif
category: ${{ matrix.scanner }}
test:
name: Integration Tests
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Pull image
run: |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
- name: Test container startup
run: |
docker run -d --name bitlbee-test \
-e UID=1000 -e GID=1000 \
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
# Wait for healthy status
for i in {1..30}; do
if docker inspect --format='{{.State.Health.Status}}' bitlbee-test | grep -q healthy; then
echo "Container is healthy"
exit 0
fi
echo "Waiting for container to be healthy... ($i/30)"
sleep 2
done
echo "Container failed to become healthy"
docker logs bitlbee-test
exit 1
- name: Test IRC connection
run: |
# Simple connection test
timeout 10s docker exec bitlbee-test nc -zv localhost 6667 || exit 1
- name: Cleanup
if: always()
run: |
docker stop bitlbee-test || true
docker rm bitlbee-test || true
release-notes:
name: Generate Release Notes
runs-on: ubuntu-latest
needs: [build, security, test]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Release Notes
id: notes
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.notes.outputs.body }}
draft: false
prerelease: false