-
-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (203 loc) · 6.73 KB
/
Copy pathci.yml
File metadata and controls
228 lines (203 loc) · 6.73 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
name: CI (lint, build, scan, e2e)
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
security-events: write # für SARIF Upload (Trivy)
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dockerfile:
- Dockerfile-loganalyzer
- Dockerfile-syslogng
- Dockerfile-dbcleanup
# optional: falls du zusätzlich einen "Dockerfile" im Root hast
# - Dockerfile
steps:
- uses: actions/checkout@v7
- name: Hadolint
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: ${{ matrix.dockerfile }} # <-- genau 1 Datei
config: .hadolint.yaml
failure-threshold: warning
# ShellCheck (alle Shell-Skripte)
- name: ShellCheck
uses: ludeeus/action-shellcheck@2.0.0
with:
scandir: .
# Beispiel-Excludes – falls du welche brauchst:
ignore_names: |
*.log
*.sql
# Yamllint (.yml/.yaml)
- name: Yamllint
uses: ibiqlik/action-yamllint@v3
with:
config_file: .yamllint.yaml
file_or_dir: |
.
strict: true
build_and_scan:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: lint
strategy:
fail-fast: false
matrix:
image:
- name: loganalyzer
dockerfile: Dockerfile-loganalyzer
context: .
- name: syslogng
dockerfile: Dockerfile-syslogng
context: .
- name: dbcleanup
dockerfile: Dockerfile-dbcleanup
context: .
steps:
- uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Docker meta (tags + labels)
id: meta
uses: docker/metadata-action@v6
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.image.name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Build (multi-arch, no push)
uses: docker/build-push-action@v7
with:
context: ${{ matrix.image.context }}
file: ${{ matrix.image.dockerfile }}
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Trivy Image Scan (SARIF)
- name: Trivy scan
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: image
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
format: sarif
output: trivy-${{ matrix.image.name }}.sarif
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH,MEDIUM'
ignore-unfixed: true
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: trivy-${{ matrix.image.name }}.sarif
trivy-pr-local:
name: Trivy (PR, local image scan)
if: github.event_name == 'pull_request' # läuft NUR bei PRs (inkl. Dependabot)
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
include:
- name: syslogng
file: Dockerfile-syslogng
context: .
- name: loganalyzer
file: Dockerfile-loganalyzer
context: .
- name: dbcleanup
file: Dockerfile-dbcleanup
context: .
env:
LOCAL_TAG: ${{ matrix.name }}:pr-${{ github.event.number || github.run_number }}
steps:
- uses: actions/checkout@v7
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
# Build ins lokale Docker laden (kein Push!)
- name: Build (no push, load to daemon)
uses: docker/build-push-action@v7
with:
context: ${{ matrix.context }}
file: ${{ matrix.file }}
push: false
load: true
tags: ${{ env.LOCAL_TAG }}
# Trivy scannt das lokale Image (kein GHCR-Pull nötig)
- name: Trivy scan (local image)
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: image
image-ref: ${{ env.LOCAL_TAG }}
format: 'table'
ignore-unfixed: true
output: trivy-${{ matrix.image.name }}.sarif
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH,MEDIUM'
e2e:
runs-on: ubuntu-latest
needs: build_and_scan
steps:
- uses: actions/checkout@v7
- name: Write CI .env (override)
run: |
cat > .env.ci <<'EOF'
TZ=Europe/Berlin
DB_NAME=syslogdb
DB_USER=syslog
DB_PASSWORD=ciPassw0rd!
DB_ROOT_PASSWORD=ciRootPassw0rd!
SYSLOG_UDP_PORT=514
SYSLOG_TCP_PORT=514
LOGANALYZER_HTTP_PORT=8181
LOG_RETENTION_DAYS=7
DBCLEANUP_CRON=*/2 * * * *
EOF
- name: Compose up (detached, build)
run: |
docker compose --env-file .env.ci up -d --build
# Warten bis DB & syslogng healthy (max 90s)
for i in {1..30}; do
unhealthy=$(docker compose ps --format json | jq -r '.[] | select(.Health!="" and .Health!="healthy") | .Name' | wc -l)
[ "$unhealthy" -eq 0 ] && break
sleep 3
done
docker compose ps
- name: Send test log via busybox logger (UDP)
run: |
NET=$(docker network ls --format '{{.Name}}' | grep syslogserver || true)
MSG="ci-test-$(date +%s)"
docker run --rm --network ${NET:-bridge} debian:trixie-slim bash -c \
"logger -n syslogng -P 514 -d \"$MSG\" || nc -u -w1 syslogng 514 <<<\"<14>$MSG\""
echo "TEST_MSG=$MSG" >> $GITHUB_ENV
- name: Verify DB contains the test log
run: |
docker compose exec -T -e TEST_MSG="$TEST_MSG" database sh -lc '
mariadb -u"$MARIADB_USER" --password="$MARIADB_PASSWORD" -D "$MARIADB_DATABASE" -Nse \
"SELECT COUNT(*) AS cnt
FROM SystemEvents
WHERE Message LIKE '\''%'"$TEST_MSG"'%'\''\G"
' | tee /tmp/db_check.txt
grep -q " 1. row" /tmp/db_check.txt
- name: Show logs on failure
if: failure()
run: |
docker compose logs --no-color > compose-logs.txt || true
sed -n '1,400p' compose-logs.txt
- name: Tear down
if: always()
run: docker compose down -v