-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (101 loc) · 3.8 KB
/
Copy pathdockerfile-lint.yml
File metadata and controls
115 lines (101 loc) · 3.8 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
name: Dockerfile Lint
on:
push:
branches: [main]
paths:
- 'apps/api/Dockerfile*'
- 'apps/web/Dockerfile*'
- '.hadolint.yaml'
- '.github/workflows/dockerfile-lint.yml'
pull_request:
branches: [main]
paths:
- 'apps/api/Dockerfile*'
- 'apps/web/Dockerfile*'
- '.hadolint.yaml'
- '.github/workflows/dockerfile-lint.yml'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
hadolint:
name: hadolint — ${{ matrix.dockerfile }}
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
dockerfile:
- apps/api/Dockerfile
- apps/web/Dockerfile
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Run hadolint
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
with:
dockerfile: ${{ matrix.dockerfile }}
config: .hadolint.yaml
failure-threshold: warning
# Custom regression guard for FARM-S537. hadolint does not natively
# support a rule that blocks hardcoded `apk add ... ">="` version
# constraints, which have broken CI repeatedly when Alpine repushed
# patched packages under new version strings. This grep enforces the
# policy: rely on `apk upgrade --no-cache` plus the Trivy CVE gate
# rather than fragile hardcoded floor versions.
- name: Guard against hardcoded apk version pins
run: |
set -euo pipefail
if grep -E -i -n 'apk[[:space:]]+add[^#]*>=' "${{ matrix.dockerfile }}"; then
echo "::error file=${{ matrix.dockerfile }}::Hardcoded apk version pins ('apk add ... \">=...\"') are not allowed. Use 'apk upgrade --no-cache' and rely on the Trivy CVE gate plus base-image digest bumps. See FARM-S537."
exit 1
fi
echo "No hardcoded apk version pins found in ${{ matrix.dockerfile }}."
runtime-uid-check:
name: runtime uid check — ${{ matrix.image.name }}
# FARM-S540: the production runtime UID must be 1001 in both images so
# that file ownership lines up with the Helm chart
# `securityContext.runAsUser: 1001` and with any shared volumes.
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
image:
- name: farm-api
dockerfile: apps/api/Dockerfile
target: production
- name: farm-web
dockerfile: apps/web/Dockerfile
target: runner
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Build image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: ${{ matrix.image.dockerfile }}
target: ${{ matrix.image.target }}
load: true
tags: ${{ matrix.image.name }}:uidcheck
cache-from: type=gha,scope=${{ matrix.image.name }}-uidcheck
cache-to: type=gha,scope=${{ matrix.image.name }}-uidcheck,mode=max
- name: Assert runtime UID is 1001
run: |
set -euo pipefail
uid="$(docker run --rm --entrypoint id "${{ matrix.image.name }}:uidcheck" -u)"
echo "Runtime UID for ${{ matrix.image.name }} = ${uid}"
if [ "${uid}" != "1001" ]; then
echo "::error file=${{ matrix.image.dockerfile }}::Expected runtime UID 1001, got ${uid}. See FARM-S540."
exit 1
fi