Support externally maintained DNF cache

Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
This commit is contained in:
Chris Evich
2022-11-18 21:50:34 -05:00
parent b4dd3c667c
commit 0e51bfdf8e
2 changed files with 30 additions and 18 deletions

View File

@@ -37,16 +37,20 @@ ARG EXCLUDE_PACKAGES="\
# Base-image runs as user 'podman', temporarily switch to root
# for installation/setup.
USER root
# Not a real build-arg. Avoiding addition of an env. layer
# only to help prevent some extra typing.
ARG dnfcmd="dnf --setopt=tsflags=nodocs -y"
# Helper for comparison in future RUN operations (DO NOT USE)
ARG _DNFCMD="dnf --setopt=tsflags=nodocs -y"
# Set this instead, if (for example) you want to volume-mount in /var/cache/dnf
ARG DNFCMD="${_DNFCMD}"
# Avoid installing any documentation to keep image small
# During install, excluding packages is meaningless if already installed
RUN set -x && \
rm -f /etc/dnf/protected.d/sudo.conf && \
rm -f /etc/dnf/protected.d/yum.conf && \
$dnfcmd remove ${EXCLUDE_PACKAGES} && \
dnf clean all && \
rm -rf /var/cache/dnf
$DNFCMD remove ${EXCLUDE_PACKAGES} && \
if [[ "${DNFCMD}" == "${_DNFCMD}" ]]; then
dnf clean all && \
rm -rf /var/cache/dnf; \
fi
# Enable callers to customize the runner version as needed, otherwise
# assume this image will be version-tagged, so it's fine to grab the latest.
@@ -56,11 +60,13 @@ ARG TARGETARCH="amd64"
ENV RUNNER_RPM_URL=https://gitlab-runner-downloads.s3.amazonaws.com/${RUNNER_VERSION}/rpm/gitlab-runner_${TARGETARCH}.rpm
RUN for rpm in ${EXCLUDE_PACKAGES}; do x+="--exclude=$rpm "; done && \
set -x && \
$dnfcmd update && \
$dnfcmd install $x $RUNNER_RPM_URL && \
$dnfcmd upgrade && \
dnf clean all && \
rm -rf /var/cache/dnf
$DNFCMD update && \
$DNFCMD install $x $RUNNER_RPM_URL && \
$DNFCMD upgrade && \
if [[ "${DNFCMD}" == "${_DNFCMD}" ]]; then
dnf clean all && \
rm -rf /var/cache/dnf; \
fi
# In case of a runner escape, prevent easy installation of packages.
RUN rm -f /etc/dnf/protected.d/* && \