forked from netmanagers/salt-image-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.emg
72 lines (66 loc) · 3.73 KB
/
Dockerfile.emg
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
ARG DISTRO_NAME
ARG DISTRO_VERSION
# Name the portage image
# hadolint ignore=DL3007
FROM gentoo/portage:latest as portage
FROM $DISTRO_NAME:$DISTRO_VERSION
# copy the entire portage volume in
COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
LABEL maintainer="[email protected]"
# Both args before the `FROM` are repeated here so that they can be used below, as required
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG DISTRO_NAME
ARG DISTRO_VERSION
ARG SALT_INSTALL_METHOD
ARG SALT_VERSION
ARG PYTHON_VERSION
ARG EXTRA_PACKAGES=""
# Provide packages used by `kitchen-docker` to speed up testing
# These are now expected by the `ssf` customised `kitchen-docker` being used:
# - https://gitlab.com/saltstack-formulas/infrastructure/kitchen-docker/-/compare/master...ssf
ARG KITCHEN_DOCKER_PACKAGES="app-admin/sudo net-misc/openssh"
ARG PKGS="${KITCHEN_DOCKER_PACKAGES} dev-python/pip dev-vcs/git ${EXTRA_PACKAGES}"
ARG SALT_REPO_URL=""
SHELL ["/bin/bash", "-x", "-o", "pipefail", "-c"]
RUN mkdir --parents /etc/portage/repos.conf \
&& cp /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf \
# Adjust portage configuration to avoid syncing the package tree when Salt's `pkg.refresh_db` runs `emaint sync -a`
# The idea is to never run a sync in containers when running tests, due to it taking ~15 minutes each time
# We're already keeping the portage repository, as mentioned below
# Since these images are built every week, this essentially "simulates" a weekly version of `portage:sync_wait_one_day`
&& sed -i -e "/^\(auto-sync = \)yes$/s//\1no/" /etc/portage/repos.conf/gentoo.conf \
&& emerge --noreplace --quiet --with-bdeps-auto=n ${PKGS} \
# Install Salt using the bootstrap script (removing the 10 seconds delay to cancel the bootstrap)
&& curl -L https://raw.githubusercontent.com/saltstack/salt-bootstrap/develop/bootstrap-salt.sh | \
sed -e '/^\s\+echowarn "You have 10 seconds to cancel and stop the bootstrap process..."/,+2d' | \
sh -s -- ${SALT_REPO_URL} -XUdfPD -x python$PYTHON_VERSION $SALT_INSTALL_METHOD $SALT_VERSION \
# Generate locales
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen \
# Enable sshd and disable Salt's service as we don't need it running
&& if [ "${DISTRO_VERSION}" = "systemd" ]; then \
(systemctl enable sshd.service > /dev/null 2>&1; \
systemctl disable salt-minion.service > /dev/null 2>&1) \
|| true; \
else \
(/sbin/rc-update add sshd default > /dev/null 2>&1; \
/sbin/rc-update del salt-minion default > /dev/null 2>&1) \
|| true; \
fi \
# Similar to Fedora, Arch Linux & Tumbleweed, enable the `ssh-rsa` keypair
# type since Kitchen testing currently relies on this
&& echo "PubkeyAcceptedAlgorithms +ssh-rsa" | tee -a /etc/ssh/sshd_config \
# Remove unnecessary getty and udev targets that result in high CPU usage when using
# multiple containers with Molecule or Kitchen https://github.com/ansible/molecule/issues/1104
# Remove binary packages and downloaded sources
# Was also removing the portage repository until (844ec6dee01cd8e06b45906e81f7f058b3399a5e):
# https://gitlab.com/saltstack-formulas/infrastructure/salt-image-builder/-/merge_requests/55#note_427462634
&& rm -rf /var/cache/{salt,binpkgs,distfiles} \
/lib/systemd/system/systemd*udev* \
/lib/systemd/system/getty.target \
/tmp/* \
&& (find / ! -path "/{proc,sys,dev}" -name "*.pyc"; \
find / ! -path "/{proc,sys,dev}" -name "__pycache__"; \
find /var/log -type f) \
| grep -v ^/proc | xargs rm -rf \
# Also obscure any `getty` binaries https://github.com/moby/moby/issues/4040#issuecomment-339022455
&& cp /bin/true /sbin/agetty