Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
217 lines (180 loc) · 7.57 KB
/
Copy pathDockerfile
File metadata and controls
217 lines (180 loc) · 7.57 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
# Dockerfile for local Linux testing
# Usage: docker compose run --rm test
# docker compose run --rm full
# docker compose run --rm fresh-install
#
# Multi-stage build for different test scenarios
# =============================================================================
# Base image with common dependencies
# =============================================================================
FROM ubuntu:24.04 AS base-ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
git \
curl \
wget \
ca-certificates \
make \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for realistic testing
RUN useradd -m -s /bin/bash tester \
&& mkdir -p /home/tester/.config \
&& chown -R tester:tester /home/tester
# =============================================================================
# Ubuntu with gitleaks pre-installed (for quick tests)
# =============================================================================
FROM base-ubuntu AS ubuntu-with-gitleaks
ARG GITLEAKS_VERSION=8.30.1
RUN ARCH="$(dpkg --print-architecture)" && \
case "$ARCH" in \
amd64) GITLEAKS_ARCH="x64" ;; \
arm64) GITLEAKS_ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
wget --no-check-certificate -q -O /tmp/gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_${GITLEAKS_ARCH}.tar.gz" && \
tar xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks && \
rm /tmp/gitleaks.tar.gz && \
chmod +x /usr/local/bin/gitleaks && \
gitleaks version
WORKDIR /caulking
COPY --chown=tester:tester . .
USER tester
RUN git config --global user.name "Caulking Test" \
&& git config --global user.email "test@gsa.gov" \
&& git config --global init.defaultBranch main
CMD ["make", "test"]
# =============================================================================
# Fresh install test (no gitleaks pre-installed, simulates new user)
# =============================================================================
FROM base-ubuntu AS fresh-install
WORKDIR /caulking
COPY --chown=tester:tester . .
USER tester
RUN git config --global user.name "Caulking Test" \
&& git config --global user.email "test@gsa.gov" \
&& git config --global init.defaultBranch main
# Fresh install will fail without gitleaks - tests the error messaging
CMD ["bash", "-c", "echo '=== Fresh Install Test (no gitleaks) ===' && make install 2>&1; echo 'Exit code:' $?"]
# =============================================================================
# Debian testing
# =============================================================================
FROM debian:12-slim AS debian
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
git \
curl \
wget \
ca-certificates \
make \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m -s /bin/bash tester \
&& mkdir -p /home/tester/.config \
&& chown -R tester:tester /home/tester
ARG GITLEAKS_VERSION=8.30.1
RUN ARCH="$(dpkg --print-architecture)" && \
case "$ARCH" in \
amd64) GITLEAKS_ARCH="x64" ;; \
arm64) GITLEAKS_ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
wget --no-check-certificate -q -O /tmp/gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_${GITLEAKS_ARCH}.tar.gz" && \
tar xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks && \
rm /tmp/gitleaks.tar.gz && \
chmod +x /usr/local/bin/gitleaks
WORKDIR /caulking
COPY --chown=tester:tester . .
USER tester
RUN git config --global user.name "Caulking Test" \
&& git config --global user.email "test@gsa.gov" \
&& git config --global init.defaultBranch main
CMD ["make", "test"]
# =============================================================================
# Alpine Linux (musl libc - good for catching glibc assumptions)
# =============================================================================
FROM alpine:3.20 AS alpine
RUN apk add --no-cache \
bash \
git \
curl \
wget \
make \
ca-certificates
RUN adduser -D -s /bin/bash tester \
&& mkdir -p /home/tester/.config \
&& chown -R tester:tester /home/tester
# Note: gitleaks provides musl builds
ARG GITLEAKS_VERSION=8.30.1
# Update CA certs and download gitleaks
RUN update-ca-certificates && \
ARCH="$(uname -m)" && \
case "$ARCH" in \
x86_64) GITLEAKS_ARCH="x64" ;; \
aarch64) GITLEAKS_ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
wget --no-check-certificate -q -O /tmp/gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_${GITLEAKS_ARCH}.tar.gz" && \
tar xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks && \
rm /tmp/gitleaks.tar.gz && \
chmod +x /usr/local/bin/gitleaks
WORKDIR /caulking
COPY --chown=tester:tester . .
USER tester
RUN git config --global user.name "Caulking Test" \
&& git config --global user.email "test@gsa.gov" \
&& git config --global init.defaultBranch main
CMD ["make", "test"]
# =============================================================================
# GitHub Actions CI simulation (ubuntu-latest equivalent)
# =============================================================================
FROM ubuntu:22.04 AS ci-simulation
ENV DEBIAN_FRONTEND=noninteractive
ENV CI=true
ENV GITHUB_ACTIONS=true
ENV RUNNER_OS=Linux
# Match GitHub Actions runner packages
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
git \
curl \
wget \
ca-certificates \
make \
jq \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m -s /bin/bash runner \
&& mkdir -p /home/runner/.config \
&& chown -R runner:runner /home/runner
ARG GITLEAKS_VERSION=8.30.1
ARG GITLEAKS_SHA256_LINUX_X64=551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
# Use wget with --no-check-certificate for Docker build environments with SSL proxy issues
RUN ARCH="$(dpkg --print-architecture)" && \
case "$ARCH" in \
amd64) GITLEAKS_ARCH="x64" ;; \
arm64) GITLEAKS_ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
wget --no-check-certificate -q -O /tmp/gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_${GITLEAKS_ARCH}.tar.gz" && \
if [ "$ARCH" = "amd64" ]; then \
echo "${GITLEAKS_SHA256_LINUX_X64} /tmp/gitleaks.tar.gz" | sha256sum -c - ; \
fi && \
tar xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks && \
rm /tmp/gitleaks.tar.gz && \
chmod +x /usr/local/bin/gitleaks
WORKDIR /github/workspace
COPY --chown=runner:runner . .
USER runner
RUN git config --global user.name "GitHub Actions" \
&& git config --global user.email "actions@github.com" \
&& git config --global init.defaultBranch main
# Simulate the CI workflow steps
CMD ["bash", "-c", "set -euo pipefail && echo '=== CI Simulation ===' && echo 'Step 1: Install' && make install && echo 'Step 2: Verify' && make verify && echo 'Step 3: Test' && make test && echo '=== CI Simulation PASSED ==='"]
# =============================================================================
# Default target (ubuntu with gitleaks)
# =============================================================================
FROM ubuntu-with-gitleaks AS default