Skip to content

Commit 171d62d

Browse files
committed
Containerfile: avoid modifying pycache files
A lot of history here, but essentially today the pycache files generated at compose time are invalid because they're of course created before the epoch mtime canonicalization ostree does and pyc files include the mtime in their headers to know if they're out of date. Since `/usr` is not read-only in the layering flow, Python will happily regenerate the cache files as Python code gets executed. This isn't necessarily a big deal and actually would make dnf faster, but it's also awkward and confusing to have only a subset of Python code in the OS cached correctly and sloshing that diff around in container layers when what we really want is having it fixed correctly at base compose time. So let's just avoid it for consistency and to reduce the diff with the legacy variants. We do this by moving the base ones out of the way and then moving them back in place, possibly overwriting regenerated ones. Note that using `ENV PYTHONDONTWRITEBYTECODE=1` is not sufficient here; that doesn't seem to reach RPM scriptlets which use Python. See also: ostreedev/ostree#1469
1 parent 2e03d4b commit 171d62d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Containerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030

3131
FROM quay.io/openshift-release-dev/ocp-v4.0-art-dev:c9s-coreos
3232
ARG OPENSHIFT_CI=0
33+
# Avoid shipping modified .pyc files. Due to https://github.com/ostreedev/ostree/issues/1469,
34+
# any Python apps that run (e.g. dnf) will cause pyc creation.
3335
RUN --mount=type=bind,target=/run/src \
36+
find /usr -name '*.pyc' -exec mv {} {}.bak \; && \
3437
if [ "${OPENSHIFT_CI}" != 0 ]; then /run/src/ci/get-ocp-repo.sh --ocp-layer /run/src/packages-openshift.yaml; fi && \
3538
/run/src/scripts/apply-manifest /run/src/packages-openshift.yaml && \
39+
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \; && \
3640
ostree container commit

0 commit comments

Comments
 (0)