From 4a5b5a8317aaecc259f94e8113350e15475a451b Mon Sep 17 00:00:00 2001 From: mslacken Date: Thu, 24 Nov 2022 15:06:48 +0100 Subject: [PATCH] added source file for podman --- Dockerfile | 75 +++++++++++++++++++++++++++++++ container-scripts/label-install | 75 +++++++++++++++++++++++++++++++ container-scripts/label-purge | 33 ++++++++++++++ container-scripts/label-uninstall | 20 +++++++++ 4 files changed, 203 insertions(+) create mode 100644 Dockerfile create mode 100644 container-scripts/label-install create mode 100644 container-scripts/label-purge create mode 100644 container-scripts/label-uninstall diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..42e56129 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,75 @@ +FROM bci/bci-init:latest + +LABEL Description="Warewulf Base Container" +LABEL maintainer="Christian Goll " + + +RUN zypper -n install \ + cpio \ + gzip \ + pigz \ + rsync \ + openssh-clients \ + less \ + dhcp-server \ + tftp \ + go1.18 \ + git \ + && \ + zypper -n install -t pattern devel_basis && \ + zypper clean -a && \ + systemctl enable dhcpd && \ + systemctl enable tftp.socket + +# now build the warewulf +COPY . /warewulf-src +RUN cd /warewulf-src &&\ + make clean &&\ + make lint &&\ + make + +# Our dhcpd will listen on ANY interface, limits will be handled by container runtime +RUN export DHCPDCONF=/etc/sysconfig/dhcpd; test -e $DHCPDCONF && \ + sed -i 's/^DHCPD_INTERFACE=""/DHCPD_INTERFACE="ANY"/' $DHCPDCONF && \ + sed -i 's/^DHCPD_RUN_CHROOTED="yes"/DHCPD_RUN_CHROOTED="no"/' $DHCPDCONF && \ + WW4CONF=/etc/warewulf/warewulf.conf; test -e $WW4CONF && \ + sed -i 's/^ipaddr:.*/ipaddr: EMPTY/' $WW4CONF && \ + sed -i 's/^netmask:.*/netmask: EMPTY/' $WW4CONF && \ + sed -i 's/^network:.*/network: EMPTY/' $WW4CONF && \ + sed -i 's/^ range start:.*/ range start: EMPTY/' $WW4CONF && \ + sed -i 's/^ range end:.*/ range end: EMPTY/' $WW4CONF + + +# We need the configs on the host as these files are quite important +RUN mkdir -p /container/warewulf && cp -rv /etc/warewulf/* /container/warewulf +COPY warewulf.service \ + warewulf-container-manage.sh \ + wwctl \ + label-install \ + label-uninstall \ + label-purge \ + /container + +# Add a service which will create a porper config on the startup +COPY ww4-config.service \ + /etc/systemd/system/ + +RUN systemctl enable ww4-config + + +RUN chmod +x \ + /container/wwctl \ + /container/warewulf-container-manage.sh \ + /container/label-* + +# need systemd for tftp and dhcpd +#ENTRYPOINT [ "/container/label-run" ] +CMD [ "/usr/sbin/init" ] + +#EXPOSE 67/udp 68/udp 69/udp 9873 + +LABEL INSTALL="/usr/bin/docker run --env IMAGE=IMAGE --rm --privileged -v /:/host IMAGE /bin/bash /container/label-install" +LABEL UNINSTALL="/usr/bin/docker run --rm --privileged -v /:/host IMAGE /bin/bash /container/label-uninstall" +LABEL PURGE="/usr/bin/docker run -ti --rm --privileged -v /:/host IMAGE /bin/bash /container/label-purge" +LABEL RUN="/usr/bin/docker run -d --replace --name \${NAME} --privileged --net=host -v /:/host -v /etc/warewulf:/etc/warewulf -v /var/lib/warewulf/:/var/lib/warewulf/ -e NAME=\${NAME} -e IMAGE=\${IMAGE} \${IMAGE}" + diff --git a/container-scripts/label-install b/container-scripts/label-install new file mode 100644 index 00000000..8f54ab42 --- /dev/null +++ b/container-scripts/label-install @@ -0,0 +1,75 @@ +#!/bin/sh -eu + +# This is the install script for warewulf when run in a privileged +# container. + +cd / +PATH="/usr/bin:/usr/sbin" +CONTAINER=warewulf +BINSCRIPT=${CONTAINER}-container-manage.sh +WWCTL=wwctl +OVERLAYDIR=/var/lib/warewulf/overlays +CHROOTDIR=/var/lib/warewulf/chroots +CONTAINERDIR=/var/lib/warewulf/container +WAREWULFCONF=/etc/warewulf +BASHCOMPLETION=/usr/share/bash-completion/completions/wwctl + +echo "LABEL INSTALL" +# ensure all scripts will be present on the host +copy_to_usr_local_bin() { +SCRIPT=$1 +BASEDIR=`dirname $SCRIPT` +mkdir -p $BASEDIR +if [ ! -e /host/usr/local/bin/${SCRIPT} ]; then + echo "copy /container/${SCRIPT} in /host/usr/local/bin/" + rsync -u /container/${SCRIPT} /host/usr/local/bin/${SCRIPT} +else + echo "/host/usr/local/bin/${SCRIPT} already exist, will not update it" +fi +} + +copy_to_etc() { +CONF=$1 +BASEDIR=`dirname $CONF` +mkdir -p $BASEDIR +if [ ! -e /host/etc/${CONF} ]; then + echo "copy /container/${CONF} in /host/etc/" + rsync -u /container/${CONF} /host/etc/${CONF} +else + echo "/host/etc/${CONF} already exist, will not update it" +fi +} +sync_dir() { + DIR=$1 + test -e /host/${DIR} || mkdir -pv /host/${DIR} + test -e /host/${DIR} && (rsync -au ${DIR} `dirname /host/${DIR}`; echo "updating $DIR") +} + +# For podman, cp a systemd unit for starting on boot +if [ ! -e /host/etc/systemd/system/${CONTAINER}.service ]; then + mkdir -p /host/etc/systemd/system/ + rsync -u /container/${CONTAINER}.service /host/etc/systemd/system/${CONTAINER}.service +else + echo "/host/etc/systemd/system/${CONTAINER}.service already exist" +fi + +# create the dirs +mkdir -p /host/etc/warewulf +mkdir -p /host/var/lib/warewulf + +copy_to_usr_local_bin ${WWCTL} +copy_to_usr_local_bin ${BINSCRIPT} + +# now sync hosts and overlays +sync_dir $OVERLAYDIR +sync_dir $CHROOTDIR +sync_dir $WAREWULFCONF + +# bash completion +if [ ! -e /host/etc/bash_completion.d/wwctl ] ; then + mkdir -p /host/etc/bash_completion.d + cp $BASHCOMPLETION /host/etc/bash_completion.d/ +fi + +# containerdir +mkdir -p /host/$CONTAINERDIR diff --git a/container-scripts/label-purge b/container-scripts/label-purge new file mode 100644 index 00000000..95568309 --- /dev/null +++ b/container-scripts/label-purge @@ -0,0 +1,33 @@ +#!/bin/bash +OVERLAYDIR=/var/lib/warewulf/overlays +CHROOTDIR=/var/lib/warewulf/chroots +CONTAINERDIR=/var/lib/warewulf/container +WAREWULFCONF=/etc/warewulf +BASEDIR=/var/lib/warewulf +cat >&2 << EOF +WARNING: +Purging all warewulf configurations, containers aka node images and overlays +Wating for 10s, press any key to abort +EOF + +count=0 +while true ; do + if read -t 0; then # Input ready + read -n 1 char + echo "Aborting purge" + exit 0 + else # No input + echo -n '.' + sleep 1 + count=$(( $count + 1)) + if [ $count -eq 10 ] ; then + echo + break + fi + fi +done +echo "PURGING" +/container/label-uninstall +rm -rv /host/$WAREWULFCONF /host/$OVERLAYDIR /host/$CHROOTDIR /host/$CONTAINERDIR +rmdir /host/$BASEDIR + diff --git a/container-scripts/label-uninstall b/container-scripts/label-uninstall new file mode 100644 index 00000000..16d9b411 --- /dev/null +++ b/container-scripts/label-uninstall @@ -0,0 +1,20 @@ +#!/bin/sh -eu + +# This is the uninstall script for grafana when run in a privileged +# container. + +CONTAINER=warewulf +cd / +PATH="/usr/bin:/usr/sbin" + +if [ ! -d /host/etc ] || [ ! -d /host/usr/local/bin ]; then + echo "${CONTAINER}-uninstall: host file system is not mounted at /host" + exit 1 +fi + +# removing installed files +echo "LABEL UNINSTALL: Removing all files" +rm -vf /host/usr/local/bin/wwctl +rm -vf /host/usr/local/bin/warewulf-container-manage.sh +rm -vf /host/etc/systemd/system/${CONTAINER}.service +rm -vf /host/usr/share/bash-completion/completions/wwctl