Skip to content

Instantly share code, notes, and snippets.

@tonylea
Created July 6, 2023 19:05
Show Gist options
  • Save tonylea/daa3a0ad56bcd7955dbaa353ca75decf to your computer and use it in GitHub Desktop.
Save tonylea/daa3a0ad56bcd7955dbaa353ca75decf to your computer and use it in GitHub Desktop.
Dockerfile.j2 template for Ansible Molecule tests
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}
RUN \
if [ $(command -v apt-get) ]; then \
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
apt-transport-https \
aptitude \
bash \
curl \
dirmngr \
iproute2 \
python3 \
python3-apt \
procps \
software-properties-common \
sudo \
systemd \
systemd-sysv \
vim \
wget \
xz-utils \
&& apt-get clean; \
elif [ $(command -v dnf) ]; then \
dnf makecache \
&& dnf --assumeyes install bash iproute sudo /usr/bin/dnf-3 /usr/bin/python3 /usr/bin/python3-config vim \
&& dnf clean all; \
elif [ $(command -v yum) ]; then \
yum makecache fast \
&& yum install -y bash iproute initscripts sudo /usr/bin/python /usr/bin/python2-config vim yum-plugin-ovl \
&& yum install -y http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-copr-1.1.31-54.el7_8.noarch.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/libseccomp-2.3.1-4.el7.x86_64.rpm \
&& yum copr enable -y jsynacek/systemd-backports-for-centos-7 \
&& yum update --disableplugin=priorities -y systemd \
&& sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf \
&& yum clean all; \
elif [ $(command -v zypper) ]; then \
zypper refresh \
&& zypper install -y bash iproute2 python3 sudo systemd systemd-sysvinit vim \
&& zypper clean -a; \
elif [ $(command -v apk) ]; then \
apk update \
&& apk add --no-cache bash curl openrc python3 sudo vim; \
echo 'rc_provide="loopback net"' >> /etc/rc.conf; \
elif [ $(command -v xbps-install) ]; then \
xbps-install -Syu \
&& xbps-install -y bash iproute2 python3 sudo vim \
&& xbps-remove -O; \
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment