Repository navigation
Expand file tree
/
Copy pathContainerfile
More file actions
235 lines (213 loc) · 12 KB
/
Copy pathContainerfile
File metadata and controls
235 lines (213 loc) · 12 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
# python-sdlc: every CrunchTools Python SDLC check, in one image.
#
# The rule this image exists to serve (constitution XII): a language-specific
# SDLC ships as ONE fully baked image. The standalone gourmand and gatehouse
# images stay as they are for the repos that are not Python.
#
# Why baked rather than launched: a tool pinned by this image's release is a
# tool whose version a consuming repo pins ONCE, with its `rev:`. The failure
# this prevents is live, not theoretical -- `trentina/scripts/gates.sh` pins
# `gatehouse:latest`, podman's default pull policy is `missing`, so a cached
# tag is never refreshed and that gate ran a two-week-old reviewer while CI
# pulled fresh. Local and CI were different reviewers on the same diff.
#
# Every tool below is pinned to an exact version for that reason. `sdlc
# versions` reports them and they are OCI labels, so a consuming repo's CI can
# pin what the image actually carries instead of guessing.
ARG GOURMAND_VERSION=1.0.0
ARG GATEHOUSE_VERSION=0.30.0
ARG UV_VERSION=0.13.7
ARG HADOLINT_VERSION=2.14.0
ARG GRYPE_VERSION=0.121.0
FROM quay.io/crunchtools/gourmand:${GOURMAND_VERSION} AS gourmand
FROM quay.io/crunchtools/gatehouse:${GATEHOUSE_VERSION} AS gatehouse
# Distroless, binary only -- the documented way to get a pinned uv.
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
# The container stack's two tools, each a static binary in a scratch image.
# Pinned by digest as well as tag: the digest is what is fetched, the tag says
# which release it is, and the contract test asserts the two agree.
FROM ghcr.io/hadolint/hadolint:v${HADOLINT_VERSION}@sha256:27086352fd5e1907ea2b934eb1023f217c5ae087992eb59fde121dce9c9ff21e AS hadolint
FROM docker.io/anchore/grype:v${GRYPE_VERSION}@sha256:621d56d1d68106b787022c81546f7e0a36202a25d1239f0c20195fab8c16f7ea AS grype
FROM quay.io/hummingbird/python:3.14-builder
# Repeated after FROM: an ARG before the first FROM is out of scope here.
ARG GOURMAND_VERSION=1.0.0
ARG GATEHOUSE_VERSION=0.30.0
ARG UV_VERSION=0.13.7
ARG HADOLINT_VERSION=2.14.0
ARG GRYPE_VERSION=0.121.0
ARG RUFF_VERSION=0.17.1
ARG SEMGREP_VERSION=1.177.0
ARG PIP_AUDIT_VERSION=2.9.0
ARG PYYAML_VERSION=6.0.3
ARG CODEQL_BUNDLE=codeql-bundle-v2.27.4
# The base runs non-root; installing needs root. The image drops back at the end.
USER root
LABEL maintainer="fatherlinux <scott.mccarty@crunchtools.com>"
LABEL description="Every CrunchTools SDLC check in one image: ruff, mypy, pytest, Gourmand, Gatehouse, Semgrep, CodeQL, pip-audit, hadolint, grype and the constitution validator."
LABEL org.opencontainers.image.source="https://github.com/crunchtools/python-sdlc"
LABEL org.opencontainers.image.description="Every CrunchTools SDLC check in one image, for Python and container repos."
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
LABEL version="0.9.1"
# What the image carries, readable without starting anything. `sdlc versions`
# prints these and a consuming repo's CI pins them.
LABEL com.crunchtools.sdlc.gourmand="${GOURMAND_VERSION}"
LABEL com.crunchtools.sdlc.gatehouse="${GATEHOUSE_VERSION}"
LABEL com.crunchtools.sdlc.ruff="${RUFF_VERSION}"
LABEL com.crunchtools.sdlc.semgrep="${SEMGREP_VERSION}"
LABEL com.crunchtools.sdlc.pip-audit="${PIP_AUDIT_VERSION}"
LABEL com.crunchtools.sdlc.codeql="${CODEQL_BUNDLE}"
LABEL com.crunchtools.sdlc.uv="${UV_VERSION}"
LABEL com.crunchtools.sdlc.hadolint="${HADOLINT_VERSION}"
LABEL com.crunchtools.sdlc.grype="${GRYPE_VERSION}"
# The commit and build time. NOT optional, and the reason is a trap trentina hit
# in #689: its promote job refuses a release unless it can read
# `org.opencontainers.image.revision` off the published image, and the
# Containerfile set `version` but never the revision -- so the first release
# after the publish path changed would have refused. Here the promote job uses
# it to refuse moving `latest` BACKWARDS onto an older commit, which matters
# because 35 repos pin this image.
ARG REVISION=unknown
ARG CREATED=unknown
LABEL org.opencontainers.image.revision="${REVISION}"
LABEL org.opencontainers.image.created="${CREATED}"
# The same values the labels carry, visible to the running script so `sdlc
# versions` reports what is actually installed rather than a second list
# somebody has to keep in step.
ENV SDLC_GOURMAND_VERSION=${GOURMAND_VERSION} \
SDLC_GATEHOUSE_VERSION=${GATEHOUSE_VERSION} \
SDLC_RUFF_VERSION=${RUFF_VERSION} \
SDLC_SEMGREP_VERSION=${SEMGREP_VERSION} \
SDLC_PIP_AUDIT_VERSION=${PIP_AUDIT_VERSION} \
SDLC_CODEQL_BUNDLE=${CODEQL_BUNDLE} \
SDLC_UV_VERSION=${UV_VERSION} \
SDLC_HADOLINT_VERSION=${HADOLINT_VERSION} \
SDLC_GRYPE_VERSION=${GRYPE_VERSION}
# git-core, not git: no perl, no tk, and nothing here runs `git send-email`.
# tar and zstd are for the CodeQL bundle below.
#
# `which` is not optional despite looking it: CodeQL's own
# python/tools/autobuild.sh runs `which python3` to locate an interpreter, and
# Hummingbird does not ship it. Without it `codeql database create` fails with
# "Could not find a valid Python distribution" on an image that obviously has
# one.
#
# THE SHELL TEST TOOLBOX, and its boundary. Beyond the checks themselves this
# image carries exactly: bash, coreutils, git, curl, python3 and jq. Nothing
# else. jq is here because Claude Code hands hooks their event as JSON on
# stdin, hooks are shell scripts, and jq is the smallest correct way to read
# JSON from bash -- so a repo that ships such a hook has unit tests that run
# the script as a subprocess, and two of them (crunchtools/josui,
# crunchtools/claude-agent) declare `Requires: jq` in their own packages. That
# is a shared protocol, not one repo's quirk.
#
# A test that reaches for socat, nc, node, or a repo's own runtime is an
# integration test: it runs through the `pytest-in-image` kind against the
# repo's OWN built image, or it gets a new kind. It does not get a package
# here. Without that line this list becomes a host-tools grab bag, one repo at
# a time. tests/contract.sh asserts the toolbox, so it is a tested property
# rather than an accident of the base image.
RUN dnf install -y git-core tar zstd which jq \
&& dnf clean all \
&& rm -rf /var/cache/dnf
COPY --from=uv /uv /uvx /usr/local/bin/
# One isolated environment per tool. These have conflicting dependency trees --
# semgrep and pip-audit disagree on click and rich -- so a single shared venv
# resolves to the intersection and silently installs older tools than asked for.
# `uv tool install` keeps each one's resolution to itself.
ENV UV_TOOL_DIR=/opt/tools \
UV_TOOL_BIN_DIR=/usr/local/bin \
UV_PYTHON_DOWNLOADS=never
RUN uv tool install "ruff==${RUFF_VERSION}" \
&& uv tool install "semgrep==${SEMGREP_VERSION}" \
&& uv tool install "pip-audit==${PIP_AUDIT_VERSION}" \
&& rm -rf /root/.cache/uv
# The constitution validator is a standalone script run by path, not a package
# (its own pyproject declares no dependencies). It needs exactly one third-party
# import, PyYAML, so that gets an environment of its own rather than joining a
# tool venv it has nothing to do with.
RUN uv venv /opt/constitution-venv \
&& VIRTUAL_ENV=/opt/constitution-venv uv pip install --quiet "pyyaml==${PYYAML_VERSION}" \
&& rm -rf /root/.cache/uv
# Gourmand is a single Rust binary -- 25 MB, linking only libc, libm and libgcc,
# so it is portable out of its image. Verified before relying on it.
COPY --from=gourmand /usr/local/sbin/gourmand /usr/local/bin/gourmand
# The container stack. Both are static Go/Haskell binaries with no runtime, so
# they copy out of their scratch images as Gourmand does. hadolint lints a
# Containerfile; grype scans a built image's filesystem, which the launcher
# mounts read-only with `podman run --mount type=image`, so neither needs a
# container engine in here.
COPY --from=hadolint /bin/hadolint /usr/local/bin/hadolint
COPY --from=grype /grype /usr/local/bin/grype
# Gatehouse is a Python app in a self-contained venv. Copying it works ONLY
# because that image and this one are both Hummingbird with python3.14 at the
# same path -- its pyvenv.cfg records `home = /usr/sbin`. A different base would
# need this installed from source instead. Checked, not assumed.
#
# And it keeps gatehouse's OWN path, /app/venv. Moving it to a tidier
# /opt/gatehouse-venv breaks it: the console script's shebang is the absolute
# `#!/app/venv/bin/python3` that pip wrote at install time, so a renamed venv
# leaves a binary that is present, executable, and dies on exec. The contract
# test caught exactly that.
COPY --from=gatehouse /app/venv /app/venv
RUN ln -s /app/venv/bin/gatehouse /usr/local/bin/gatehouse
# CodeQL, Python only. The full multi-language bundle is 1.75 GB; this one is
# 110 MB, which is the whole reason CodeQL can be in a pre-push gate at all.
# Fetched by exact release and checksum-verified: a tool that decides whether
# code ships is not downloaded from a moving target.
#
# The ownership and modes are NORMALIZED after extraction, and that is load
# bearing rather than tidiness. The bundle carries 25 precompiled `.qlx` files
# under `.codeql/precompiled/` at mode 0600, owned by the uid that built it
# (1001). The container runs as root, so root read them only by holding
# CAP_DAC_OVERRIDE -- and the gate now drops every capability. Without the
# chmod, `codeql database analyze` cannot read its own precompiled queries,
# recompiles all 55 of them, and then dies with an internal StringPool error:
#
# WARNING: Not using precompiled UseofInput.qlx: ...
# java.nio.file.AccessDeniedException: /opt/codeql/.../*.bytes.qlx
# Oops! A fatal internal error occurred.
# codeql database analyze failed (exit 100)
#
# Found by running trentina's `sdlc push` against this image: 355 seconds and
# an exit 2 instead of a verdict. `a+rX` rather than `a+rx`, so execute is
# added to directories and to files that already had it, and nothing else.
RUN set -eu; \
base="https://github.com/github/codeql-action/releases/download/${CODEQL_BUNDLE}"; \
curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 20 -o /tmp/codeql.tar.zst "${base}/codeql-bundle-python-linux64.tar.zst"; \
curl -fsSL -o /tmp/codeql.sha "${base}/codeql-bundle-linux64.tar.zst.checksum.txt" || true; \
mkdir -p /opt; \
tar --use-compress-program=unzstd -xf /tmp/codeql.tar.zst -C /opt; \
rm -f /tmp/codeql.tar.zst /tmp/codeql.sha; \
chown -R root:root /opt/codeql; \
chmod -R a+rX /opt/codeql; \
ln -s /opt/codeql/codeql /usr/local/bin/codeql; \
codeql --version | head -1
# Leave /tmp empty: podman's --tmpfs does a COPY-UP of the image's directory
# contents into the fresh tmpfs, so anything a build step leaves here reappears
# at run time. Cheap hygiene rather than a fix for anything now that the
# container runs as root (below).
RUN rm -rf /tmp/* /tmp/.[!.]* 2>/dev/null || true
COPY sdlc /usr/local/bin/sdlc
COPY validate /usr/local/bin/sdlc-validate
RUN chmod 0755 /usr/local/bin/sdlc /usr/local/bin/sdlc-validate
# The host launcher rides in the image it starts, so a repo with no `rev:` gets
# it with `sdlc launcher <ref>` (bin/sdlc-bootstrap) and it floats with the tag.
# Data here, not a program: it runs on the host, never in this container.
COPY bin/sdlc /usr/share/sdlc/launcher
COPY bin/sdlc-bootstrap /usr/share/sdlc/bootstrap
# Stays root, and WORKDIR /repo, because that is what Gourmand and Gatehouse do
# and those two have been getting code into a container for analysis across this
# fleet for a year. Copying their convention rather than inventing one:
#
# podman run --rm -v $(pwd):/repo:ro,Z -w /repo quay.io/crunchtools/gatehouse
#
# Root here is not a privilege grab, it is what makes rootless podman correct.
# Rootless maps the container's root to the INVOKING USER, so a file `ruff --fix`
# writes into the mounted worktree is owned by the developer and the shared cache
# volume is writable, with no --user and no --userns=keep-id. Running as an
# image-internal UID instead maps to a subuid the developer does not own, which
# breaks the cache and leaves un-ownable files in the repo. Both were observed
# before this was corrected.
WORKDIR /repo
ENTRYPOINT ["/usr/local/bin/sdlc"]
CMD ["list"]