Skip to content

Commit 7dda87a

Browse files
committed
ci: add docker security scan and lint workflow
1 parent 2d0ef19 commit 7dda87a

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

.github/workflows/docker-lint.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Docker lint
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
lint:
10+
name: Lint Dockerfiles and Compose
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install yamllint
22+
run: pip install yamllint
23+
24+
- name: Find and run yamllint on compose files
25+
run: |
26+
set -euo pipefail
27+
files=$(git ls-files "**/docker-compose*.yml" "**/docker-compose*.yaml" || true)
28+
if [ -n "$files" ]; then
29+
echo "$files" | xargs yamllint || true
30+
else
31+
echo "No compose files found"
32+
fi
33+
34+
- name: Prepare .env files for compose
35+
run: |
36+
set -euo pipefail
37+
files=$(git ls-files "**/docker-compose*.yml" "**/docker-compose*.yaml" || true)
38+
if [ -n "$files" ]; then
39+
for f in $files; do
40+
dir=$(dirname "$f")
41+
if [ -f "$dir/.env" ]; then
42+
echo ".env already present in $dir"
43+
elif [ -f "$dir/.env.example" ]; then
44+
echo "Copying $dir/.env.example -> $dir/.env"
45+
cp "$dir/.env.example" "$dir/.env"
46+
elif [ -f ".env.example" ] && [ ! -f ".env" ]; then
47+
echo "Copying root .env.example -> $dir/.env"
48+
cp ".env.example" "$dir/.env"
49+
else
50+
echo "No .env found for $f (expected $dir/.env or $dir/.env.example or root .env.example)."
51+
fi
52+
done
53+
else
54+
echo "No compose files found"
55+
fi
56+
57+
- name: Validate docker compose config
58+
run: |
59+
set -euo pipefail
60+
files=$(git ls-files "**/docker-compose*.yml" "**/docker-compose*.yaml" || true)
61+
if [ -n "$files" ]; then
62+
for f in $files; do
63+
echo "Validating $f"
64+
docker compose -f "$f" config > /dev/null
65+
done
66+
else
67+
echo "No compose files found"
68+
fi
69+
70+
- name: Hadolint (Docker image)
71+
run: |
72+
set -euo pipefail
73+
files=$(git ls-files "**/Dockerfile" || true)
74+
if [ -n "$files" ]; then
75+
for df in $files; do
76+
echo "Linting $df"
77+
docker run --rm -v "${{ github.workspace }}:/workdir" -w /workdir hadolint/hadolint hadolint "$df" || true
78+
done
79+
else
80+
echo "No Dockerfiles found"
81+
fi

.github/workflows/docker-scan.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Docker security scan
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
trivy-scan:
10+
name: Run Trivy filesystem scan
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Run Trivy Action
16+
uses: aquasecurity/trivy-action@0.32.0
17+
with:
18+
format: 'table'
19+
scan-type: 'fs'
20+
severity: 'HIGH,CRITICAL'
21+
exit-code: '1'
22+
ignore-unfixed: true

0 commit comments

Comments
 (0)