From 4a5b5a8317aaecc259f94e8113350e15475a451b Mon Sep 17 00:00:00 2001 From: mslacken Date: Thu, 24 Nov 2022 15:06:48 +0100 Subject: [PATCH 01/14] 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 From f831db1875e4953a334faceaa6f3229043140f27 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 25 Nov 2022 11:58:32 +0100 Subject: [PATCH 02/14] added more container scripts, smaller image --- container-scripts/warewulf.service | 25 +++++++++++++++++++++++++ container-scripts/ww4-config.service | 12 ++++++++++++ container-scripts/wwctl | 8 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 container-scripts/warewulf.service create mode 100644 container-scripts/ww4-config.service create mode 100644 container-scripts/wwctl diff --git a/container-scripts/warewulf.service b/container-scripts/warewulf.service new file mode 100644 index 00000000..41737835 --- /dev/null +++ b/container-scripts/warewulf.service @@ -0,0 +1,25 @@ +[Unit] +Description=warewulf daemon container +Documentation=https://build.opensuse.org/package/show/SUSE:ALP:Workloads/warewulf-container +After=network-online.target +After=local-fs.target +Wants=network-online.target +StartLimitIntervalSec=40 +StartLimitBurst=5 + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +Restart=always +RestartSec=1s +TimeoutStopSec=70 +#Environment=WAREWULF_IMAGE_PATH=registry.opensuse.org/suse/alp/workloads/tumbleweed_containerfiles/suse/alp/workloads/warewulf:latest +Environment=WAREWULF_IMAGE_PATH=warewulf:latest +ExecStartPre=-/usr/bin/podman container runlabel --name warewulf install ${WAREWULF_IMAGE_PATH} +ExecStart=/usr/bin/podman container runlabel --name warewulf run ${WAREWULF_IMAGE_PATH} +ExecStop=/usr/bin/podman container stop warewulf +ExecStopPost=/usr/bin/podman container rm warewulf +Type=notify +NotifyAccess=all + +[Install] +WantedBy=multi-user.target diff --git a/container-scripts/ww4-config.service b/container-scripts/ww4-config.service new file mode 100644 index 00000000..3d21a547 --- /dev/null +++ b/container-scripts/ww4-config.service @@ -0,0 +1,12 @@ +[Unit] +Description=Warewulf container configuration +After=local-fs.target +Before=warewulfd.service +Before=dhcpd + +[Service] +Type=oneshot +ExecStart=/container/config-warewulf + +[Install] +WantedBy=multi-user.target diff --git a/container-scripts/wwctl b/container-scripts/wwctl new file mode 100644 index 00000000..42fbf644 --- /dev/null +++ b/container-scripts/wwctl @@ -0,0 +1,8 @@ +#!/bin/bash + +source /etc/warewulf-container.conf + +set -euxo pipefail + +# Run the domain +podman exec -ti ${CONTAINER_NAME} wwctl $@ From 34a4846130992ea68bff9b2e901007ed22a3c436 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 25 Nov 2022 12:04:09 +0100 Subject: [PATCH 03/14] cleanup in Dockerfile --- Dockerfile | 71 +++++++++++++++++++++++++++++------------------------- Makefile | 8 +++--- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 42e56129..28206b0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM bci/bci-init:latest +FROM opensuse/tumbleweed:latest LABEL Description="Warewulf Base Container" LABEL maintainer="Christian Goll " -RUN zypper -n install \ +RUN zypper -n install --no-recommends \ cpio \ gzip \ pigz \ @@ -15,6 +15,7 @@ RUN zypper -n install \ tftp \ go1.18 \ git \ + systemd \ && \ zypper -n install -t pattern devel_basis && \ zypper clean -a && \ @@ -23,13 +24,29 @@ RUN zypper -n install \ # 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 && \ +RUN cd /warewulf-src &&\ + make contclean &&\ + make genconfig \ + PREFIX=/usr \ + BINDIRa=/usr/bin \ + SYSCONFDIR=/etc \ + DATADIR=/usr/share \ + LOCALSTATEDIR=/var/lib \ + SHAREDSTATEDIR=/var/lib \ + MANDIR=/usr/share/man \ + INFODIR=/usr/share/info \ + DOCDIR=/usr/share/doc \ + SRVDIR=/var/lib \ + TFTPDIR=/srv/tftpboot \ + SYSTEMDDIR=/usr/lib/systemd/system \ + BASHCOMPDIR=/etc/bash_completion.d/ \ + FIREWALLDDIR=/usr/lib/firewalld/services \ + WWCLIENTDIR=/warewulf &&\ + make lint &&\ + make &&\ + make install &&\ + 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 && \ @@ -37,36 +54,24 @@ RUN export DHCPDCONF=/etc/sysconfig/dhcpd; test -e $DHCPDCONF && \ 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 + sed -i 's/^ range end:.*/ range end: EMPTY/' $WW4CONF && \ + mkdir -p /container && \ + cp -vr container-scripts/label-* \ + container-scripts/wwctl \ + container-scripts/warewulf.service \ + /container &&\ + mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ + systemctl enable ww4-config + +# cleanup container +RUN zypper rm -yu go &&\ + rm -rf /warewulf-src -# 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 +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" diff --git a/Makefile b/Makefile index 23c42bae..c546eb87 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all +.PHONY: all clean contclean -include Defaults.mk @@ -289,7 +289,7 @@ wwapic: ## Build the sample wwapi client. wwapird: ## Build the rest api server (revese proxy to the grpc api server). go build -o ./wwapird internal/app/api/wwapird/wwapird.go -clean: +contclean: rm -f wwclient rm -f wwctl rm -rf .dist @@ -298,7 +298,6 @@ clean: rm -rf bash_completion.d rm -f man_page rm -rf man_pages - rm -rf vendor rm -f warewulf.spec rm -f config rm -f Defaults.mk @@ -307,6 +306,9 @@ clean: rm -f update_configuration rm -f print_defaults +clean: contclean + rm -rf vendor + install: files install_wwclient debinstall: files debfiles From 168865a93d992f9db8b0a599bfd83c464247c754 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 25 Nov 2022 17:03:30 +0100 Subject: [PATCH 04/14] added README.md --- container-scripts/README.md | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 container-scripts/README.md diff --git a/container-scripts/README.md b/container-scripts/README.md new file mode 100644 index 00000000..4d020015 --- /dev/null +++ b/container-scripts/README.md @@ -0,0 +1,61 @@ +# Warewulf on SUSE/openSUSE/ALP +This is the warewulf container including `tftp` and `dhcpd` services. It also shares the install run labels with the upstream container, but this container uses the rpm package of warewulf and not the upstream source. + +The containers used for deployment, the overlays and compressed images are stored not in the warewulf container but under `var/lib/warewulf` on the host. Also the configuration directory `/etc/warewulf`is created on the host. + +`dhpd` and `tftp` require systemd running also in the container. To provide these services the container must also run in the same network as the host and the container must also run in privileged mode. + +Additionally the `warewulf-container-manage.sh` script is included to manage the container via podman and the `wwctl` command to manage the warewulf itself. + +# Install the warewulf container + +## Prepare the host system + +It is heavlily advised that the host has a static ipv4 address. To configure this on ALP +you can use `nmcli` with the following command: +``` +nmcli connection modify "$(nmcli -t device | awk -F: '/ethernet/{print$4;exit}')" \ + ipv4.method manual \ + ipv4.addresses 192.168.1.250/24 \ + ipv4.gateway 192.168.1.1\ + ipv4.dns 182.168.1.1 +``` + +In order to run the warewulf container, you can just use the the '''runlable install''' on the container available in the registry. +``` +# podman container runlabel install registry.opensuse.org/suse/alp/workloads/tumbleweed_containerfiles/suse/alp/workloads/warewlf:latest +``` +This will create the directories `/var/lib/warewulf` and `/etc/warewulf` on the host system and populate it with necesarry configuraiton files, if this files are not present on the host. +On the first install the actual ip network settings are used as base values for the dynamic +network configuration in `warewulf.conf`. + +## Create the container + +The warewulf service is started with the command +``` +# podman container runlabel run registry.opensuse.org/suse/alp/workloads/tumbleweed_containerfiles/suse/alp/workloads/warewlf:latest +``` +Now the cluster can be managed with the `wwctl` command. + +## Remove the Container + +The container itself can be remove with the '''label uninstall''' which will remove the container and its scripts from the host. +``` +# podman container runlabel uninstall registry.opensuse.org/suse/alp/workloads/tumbleweed_containerfiles/suse/alp/workloads/warewlf:latest +``` + +This step *doesn't* remove the configuration of warewulf under `/etc/warewulf` and the containers with the overlays under `/var/lib/warewulf`. You can use the purge label to remove these directories. + +## Purge warewulf + +All components of warewulf including `/etc/warewulf` and `/var/lib/warewulf` can be removed the the '''label purge''' which can be called with +``` +# podman container runlabel purge registry.opensuse.org/suse/alp/workloads/tumbleweed_containerfiles/suse/alp/workloads/warewlf:latest +``` +Please note that the '''label purge''' inherits the label '''label uninstall'''. + + + +## More Info + +* [Warewulf](https://github.com/hpcng/warewulf) From 8446fd6c794258ce43dd5a60a37ec722cf47d49a Mon Sep 17 00:00:00 2001 From: mslacken Date: Fri, 25 Nov 2022 18:05:04 +0100 Subject: [PATCH 05/14] Using a builder container --- Dockerfile | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28206b0e..a1e806e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,39 @@ +FROM opensuse/tumbleweed:latest as builder + +RUN zypper -n install --no-recommends git go1.18 &&\ + zypper -n install -t pattern devel_basis + +# now build the warewulf +COPY . /warewulf-src + +RUN cd /warewulf-src &&\ + make contclean &&\ + make genconfig \ + PREFIX=/usr \ + BINDIRa=/usr/bin \ + SYSCONFDIR=/etc \ + DATADIR=/usr/share \ + LOCALSTATEDIR=/var/lib \ + SHAREDSTATEDIR=/var/lib \ + MANDIR=/usr/share/man \ + INFODIR=/usr/share/info \ + DOCDIR=/usr/share/doc \ + SRVDIR=/var/lib \ + TFTPDIR=/srv/tftpboot \ + SYSTEMDDIR=/usr/lib/systemd/system \ + BASHCOMPDIR=/etc/bash_completion.d/ \ + FIREWALLDDIR=/usr/lib/firewalld/services \ + WWCLIENTDIR=/warewulf &&\ + make lint &&\ + make &&\ + make install + +# now all again but just the bare install for running the stuff FROM opensuse/tumbleweed:latest LABEL Description="Warewulf Base Container" LABEL maintainer="Christian Goll " - RUN zypper -n install --no-recommends \ cpio \ gzip \ @@ -20,7 +50,25 @@ RUN zypper -n install --no-recommends \ zypper -n install -t pattern devel_basis && \ zypper clean -a && \ systemctl enable dhcpd && \ - systemctl enable tftp.socket + systemctl enable tftp.socket &&\ + 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 && \ + mkdir -p /container && \ + cp -vr container-scripts/label-* \ + container-scripts/wwctl \ + container-scripts/warewulf.service \ + /container &&\ + mkdir -p /usr/share/bash-completion/completions/ &&\ + cp -v /etc/bash_completion.d/warewulf /usr/share/bash-completion/completions/wwctl &&\ + mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ + systemctl enable ww4-config # now build the warewulf COPY . /warewulf-src @@ -60,12 +108,24 @@ RUN cd /warewulf-src &&\ container-scripts/wwctl \ container-scripts/warewulf.service \ /container &&\ + mkdir -p /usr/share/bash-completion/completions/ &&\ + cp -v /etc/bash_completion.d/warewulf /usr/share/bash-completion/completions/wwctl &&\ mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ systemctl enable ww4-config -# cleanup container -RUN zypper rm -yu go &&\ - rm -rf /warewulf-src + + + +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}" + + From 394574c734cd6924f680fc986c7c0273940e3091 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 28 Nov 2022 11:38:43 +0100 Subject: [PATCH 06/14] copy all the stuff to the application container --- Dockerfile | 75 +++++++----------------------------------------------- Makefile | 2 +- 2 files changed, 10 insertions(+), 67 deletions(-) diff --git a/Dockerfile b/Dockerfile index a1e806e0..40fa5e34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN cd /warewulf-src &&\ SRVDIR=/var/lib \ TFTPDIR=/srv/tftpboot \ SYSTEMDDIR=/usr/lib/systemd/system \ - BASHCOMPDIR=/etc/bash_completion.d/ \ + BASHCOMPDIR=/etc/warewulf/bash_completion.d/ \ FIREWALLDDIR=/usr/lib/firewalld/services \ WWCLIENTDIR=/warewulf &&\ make lint &&\ @@ -34,7 +34,12 @@ FROM opensuse/tumbleweed:latest LABEL Description="Warewulf Base Container" LABEL maintainer="Christian Goll " -RUN zypper -n install --no-recommends \ +COPY --from=builder /usr/bin/wwctl /usr/bin/wwctl +COPY --from=builder /var/lib/warewulf /var/lib/warewulf +COPY --from=builder /etc/warewulf /etc/warewulf +COPY --from=builder /warewulf-src/container-scripts /container-scripts + +RUN zypper -n install \ cpio \ gzip \ pigz \ @@ -43,11 +48,8 @@ RUN zypper -n install --no-recommends \ less \ dhcp-server \ tftp \ - go1.18 \ - git \ systemd \ && \ - zypper -n install -t pattern devel_basis && \ zypper clean -a && \ systemctl enable dhcpd && \ systemctl enable tftp.socket &&\ @@ -65,70 +67,11 @@ RUN zypper -n install --no-recommends \ container-scripts/wwctl \ container-scripts/warewulf.service \ /container &&\ - mkdir -p /usr/share/bash-completion/completions/ &&\ - cp -v /etc/bash_completion.d/warewulf /usr/share/bash-completion/completions/wwctl &&\ + mkdir -p /usr/share/bash_completion/completions/ &&\ + cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\ mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ systemctl enable ww4-config -# now build the warewulf -COPY . /warewulf-src - -RUN cd /warewulf-src &&\ - make contclean &&\ - make genconfig \ - PREFIX=/usr \ - BINDIRa=/usr/bin \ - SYSCONFDIR=/etc \ - DATADIR=/usr/share \ - LOCALSTATEDIR=/var/lib \ - SHAREDSTATEDIR=/var/lib \ - MANDIR=/usr/share/man \ - INFODIR=/usr/share/info \ - DOCDIR=/usr/share/doc \ - SRVDIR=/var/lib \ - TFTPDIR=/srv/tftpboot \ - SYSTEMDDIR=/usr/lib/systemd/system \ - BASHCOMPDIR=/etc/bash_completion.d/ \ - FIREWALLDDIR=/usr/lib/firewalld/services \ - WWCLIENTDIR=/warewulf &&\ - make lint &&\ - make &&\ - make install &&\ - 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 && \ - mkdir -p /container && \ - cp -vr container-scripts/label-* \ - container-scripts/wwctl \ - container-scripts/warewulf.service \ - /container &&\ - mkdir -p /usr/share/bash-completion/completions/ &&\ - cp -v /etc/bash_completion.d/warewulf /usr/share/bash-completion/completions/wwctl &&\ - mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ - systemctl enable ww4-config - - - - -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}" - - - - - CMD [ "/usr/sbin/init" ] EXPOSE 67/udp 68/udp 69/udp 9873 diff --git a/Makefile b/Makefile index c546eb87..55165968 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ else endif # OS-Specific Service Locations -VARLIST += TFTPDIR FIREWALLDDIR SYSTEMDDIR +VARLIST += TFTPDIR FIREWALLDDIR SYSTEMDDIR BASHCOMPDIR SYSTEMDDIR ?= /usr/lib/systemd/system BASHCOMPDIR ?= /etc/bash_completion.d FIREWALLDDIR ?= /usr/lib/firewalld/services From de4362f9b9f47f4dc0eca5e65f92267b16f08c0a Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 29 Nov 2022 16:18:11 +0100 Subject: [PATCH 07/14] added config-warewulf --- Dockerfile | 2 + Makefile | 2 +- container-scripts/config-warewulf | 73 ++++++++++++ container-scripts/label-install | 7 +- container-scripts/label-purge | 0 container-scripts/label-uninstall | 2 +- .../warewulf-container-manage.sh | 108 ++++++++++++++++++ container-scripts/wwctl | 2 - 8 files changed, 191 insertions(+), 5 deletions(-) create mode 100755 container-scripts/config-warewulf mode change 100644 => 100755 container-scripts/label-install mode change 100644 => 100755 container-scripts/label-purge mode change 100644 => 100755 container-scripts/label-uninstall create mode 100755 container-scripts/warewulf-container-manage.sh mode change 100644 => 100755 container-scripts/wwctl diff --git a/Dockerfile b/Dockerfile index 40fa5e34..c50b9a2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,8 @@ RUN zypper -n install \ cp -vr container-scripts/label-* \ container-scripts/wwctl \ container-scripts/warewulf.service \ + container-scripts/warewulf-container-manage.sh \ + container-scripts/config-warewul \ /container &&\ mkdir -p /usr/share/bash_completion/completions/ &&\ cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\ diff --git a/Makefile b/Makefile index 55165968..993c032e 100644 --- a/Makefile +++ b/Makefile @@ -254,7 +254,7 @@ warewulfconf: config_defaults ./config_defaults dist: vendor config - rm -rf .dist/$(WAREWULF)-$(VERSION) + rm -rf .dist/$(WAREWULF)-$(VERSION) $(WAREWULF)-$(VERSION).tar.gz mkdir -p .dist/$(WAREWULF)-$(VERSION) cp -rap * .dist/$(WAREWULF)-$(VERSION)/ find .dist/$(WAREWULF)-$(VERSION)/ -type f -name '*~' -delete diff --git a/container-scripts/config-warewulf b/container-scripts/config-warewulf new file mode 100755 index 00000000..c7074527 --- /dev/null +++ b/container-scripts/config-warewulf @@ -0,0 +1,73 @@ +#!/bin/sh +# Helper functions +# Get the mask form prefix +cdr2mask() +{ + # Number of args to shift, 255..255, first non-255 byte, zeroes + set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0 + [ $1 -gt 1 ] && shift $1 || shift + echo ${1-0}.${2-0}.${3-0}.${4-0} +} +# Get the ip4 address of the netork +network_address() { + declare address prefix_length + IFS=/ read address prefix_length <<< "$1" + + declare -a octets + IFS=. read -a octets <<< "$address" + + declare mask + mask=$( printf "%08x" $(( (1 << 32) - (1 << (32 - prefix_length)) )) ) + + declare -i i + for i in {0..3}; do octets[$i]=$(( octets[i] & 16#${mask:2*i:2} )); done + + echo $( IFS=.; echo "${octets[*]}" ) +} +echo "-- WW4 CONFIGURAION $* --" + +# Make sure that a ip address was defined for out network so that +# we can configure dhcpd correctly +IP4CIDR=`ip addr | awk '/scope global/ {print $2;exit}'` +IP4=${IP4CIDR%/*} +IP4PREFIX=${IP4CIDR#*/} +IP4MASK=$(cdr2mask $IP4PREFIX) +IP4NET=$(network_address "$IP4/$IP4PREFIX") + +if [ "$IP4PREFIX" -gt 25 ] ; then + echo "ERROR: warewulf does at least a /25 network for dynamic addresses" + exit 1 +fi + +DYNSIZE=100 +DYNSTART=${IP4#*.*.*.} +DYNPRE=${IP4%.*} +DYNEND=$(( $DYNSTART + $DYNSIZE )) +if [ $DYNEND -gt 254 ] ; then + DYNEND=$(( $IPNET + 2 + $DYNSIZE )) + DYNSTART=$(( $IPNET + 2 )) +fi +DYNSTART="${DYNPRE}.${DYNSTART}" +DYNEND="${DYNPRE}.${DYNEND}" + + +WW4CONF=/etc/warewulf/warewulf.conf +if [ -e $WW4CONF ] ; then + test -n $IP4 && sed -i 's/^ipaddr: EMPTY/ipaddr: '$IP4'/' $WW4CONF + test -n $IP4MASK && sed -i 's/^netmask: EMPTY/netmask: '$IP4MASK'/' $WW4CONF + test -n $IP4NET && sed -i 's/^network: EMPTY/network: '$IP4NET'/' $WW4CONF + test -n $DYNSTART && sed -i 's/^ range start: EMPTY/ range start: '$DYNSTART'/' $WW4CONF + test -n $DYNEND && sed -i 's/^ range end: EMPTY/ range end: '$DYNEND'/' $WW4CONF + cat << EOF +ipaddr: $IP4 +netmask: $IP4MASK +network: $IP4NET + range start: $DYNSTART + range end: $DYNEND +EOF +fi + +# configure the services of the host by building the host overlay +echo "-- Running wwctl --" +wwctl overlay build +wwctl configure tftp diff --git a/container-scripts/label-install b/container-scripts/label-install old mode 100644 new mode 100755 index 8f54ab42..063c00a0 --- a/container-scripts/label-install +++ b/container-scripts/label-install @@ -12,7 +12,8 @@ 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 +BASHCOMPLETION=/usr/share/bash_completion/completions/wwctl +CONFSCRIPT=/container/config-warewulf echo "LABEL INSTALL" # ensure all scripts will be present on the host @@ -23,6 +24,7 @@ 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} + chmod 755 /host/usr/local/bin/${SCRIPT} else echo "/host/usr/local/bin/${SCRIPT} already exist, will not update it" fi @@ -73,3 +75,6 @@ fi # containerdir mkdir -p /host/$CONTAINERDIR + +# now config the container +$CONFSCRIPT diff --git a/container-scripts/label-purge b/container-scripts/label-purge old mode 100644 new mode 100755 diff --git a/container-scripts/label-uninstall b/container-scripts/label-uninstall old mode 100644 new mode 100755 index 16d9b411..915e65f1 --- a/container-scripts/label-uninstall +++ b/container-scripts/label-uninstall @@ -17,4 +17,4 @@ 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 +rm -vf /host/usr/share/bash_completion/completions/wwctl diff --git a/container-scripts/warewulf-container-manage.sh b/container-scripts/warewulf-container-manage.sh new file mode 100755 index 00000000..abb94001 --- /dev/null +++ b/container-scripts/warewulf-container-manage.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# quick script to manage the container +CONTAINER_NAME=warewulf + +create_container() { +podman create \ + --name ${CONTAINER_NAME} \ + --tls-verify=false \ + --network host \ + ${IMAGE} +} + +run_container() { +podman run \ + --name ${CONTAINER_NAME} \ + --rm -ti \ + --network host \ + --entrypoint bash \ + ${IMAGE} +} + +if [ -z "$1" ]; then +echo " +First ARG is mandatory: +$0 [create|start|stop|rm|rmcache|run|bash|logs|install|uninstall] + +CONTAINER_NAME: '${CONTAINER_NAME}' + +DEPLOYMENT: +create + Pull the image and create the container automatically + +install + install needed files on the host to manage '${CONTAINER_NAME}' container + (in /usr/local/bin and /etc) + +start + Start the container '${CONTAINER_NAME}' + +REMOVAL: +uninstall + uninstall all needed files on the host to manage '${CONTAINER_NAME}' container + +stop + stop the container '${CONTAINER_NAME}' + +rm + delete the container '${CONTAINER_NAME}' + +rmcache + remove the container image in cache ${IMAGE} + +DEBUG: +run + podman run container '${CONTAINER_NAME}' + +bash + go with /bin/bash command inside '${CONTAINER_NAME}' + +logs + see log of container '${CONTAINER_NAME}' + + " + exit 1 +fi + +########### +# MAIN +########### +set -euxo pipefail + +case $1 in + start) + podman start ${CONTAINER_NAME} + podman ps | grep ${CONTAINER_NAME} + ;; + stop) + podman stop ${CONTAINER_NAME} + podman ps | grep ${CONTAINER_NAME} + ;; + rm) + set +e + podman stop ${CONTAINER_NAME} + podman rm ${CONTAINER_NAME} + ;; + create) + create_container + ;; + run) + run_container + ;; + rmcache) + podman rmi ${IMAGE} + ;; + logs) + podman logs ${CONTAINER_NAME} + ;; + bash) + set +e + podman exec -ti ${CONTAINER_NAME} $@ + ;; + install) + podman run --env IMAGE=${IMAGE} --rm --privileged -v /:/host ${IMAGE} /bin/bash /container/label-install + ;; + uninstall) + podman run --env IMAGE=${IMAGE} --rm --privileged -v /:/host ${IMAGE} /bin/bash /container/label-uninstall + ;; +esac diff --git a/container-scripts/wwctl b/container-scripts/wwctl old mode 100644 new mode 100755 index 42fbf644..1eab34b7 --- a/container-scripts/wwctl +++ b/container-scripts/wwctl @@ -1,7 +1,5 @@ #!/bin/bash -source /etc/warewulf-container.conf - set -euxo pipefail # Run the domain From 8514f5aa1b41041af612dfdff28b7cfebe42c142 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 29 Nov 2022 17:01:36 +0100 Subject: [PATCH 08/14] adding the ipxe stuff in the container --- Dockerfile | 3 ++- container-scripts/config-warewulf | 3 ++- container-scripts/label-install | 4 ---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index c50b9a2e..71a6cad3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,7 @@ LABEL maintainer="Christian Goll " COPY --from=builder /usr/bin/wwctl /usr/bin/wwctl COPY --from=builder /var/lib/warewulf /var/lib/warewulf +COPY --from=builder /usr/share/warewulf /usr/share/warewulf COPY --from=builder /etc/warewulf /etc/warewulf COPY --from=builder /warewulf-src/container-scripts /container-scripts @@ -67,7 +68,7 @@ RUN zypper -n install \ container-scripts/wwctl \ container-scripts/warewulf.service \ container-scripts/warewulf-container-manage.sh \ - container-scripts/config-warewul \ + container-scripts/config-warewulf \ /container &&\ mkdir -p /usr/share/bash_completion/completions/ &&\ cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\ diff --git a/container-scripts/config-warewulf b/container-scripts/config-warewulf index c7074527..cd4dfbd5 100755 --- a/container-scripts/config-warewulf +++ b/container-scripts/config-warewulf @@ -70,4 +70,5 @@ fi # configure the services of the host by building the host overlay echo "-- Running wwctl --" wwctl overlay build -wwctl configure tftp +# enable tftp if systemd is running +test -e /run/systemd/system && wwctl configure tftp diff --git a/container-scripts/label-install b/container-scripts/label-install index 063c00a0..35c99e33 100755 --- a/container-scripts/label-install +++ b/container-scripts/label-install @@ -13,7 +13,6 @@ CHROOTDIR=/var/lib/warewulf/chroots CONTAINERDIR=/var/lib/warewulf/container WAREWULFCONF=/etc/warewulf BASHCOMPLETION=/usr/share/bash_completion/completions/wwctl -CONFSCRIPT=/container/config-warewulf echo "LABEL INSTALL" # ensure all scripts will be present on the host @@ -75,6 +74,3 @@ fi # containerdir mkdir -p /host/$CONTAINERDIR - -# now config the container -$CONFSCRIPT From b59e1f1effc5baa72f6048dc4dd31bcb870af088 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 29 Nov 2022 17:07:44 +0100 Subject: [PATCH 09/14] add iproute2 for ip command --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 71a6cad3..1ae12012 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ RUN zypper -n install \ openssh-clients \ less \ dhcp-server \ + iproute2 \ tftp \ systemd \ && \ From 6225a3ff70c21dbb989f3aa34829c698182798d7 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 30 Nov 2022 10:50:37 +0100 Subject: [PATCH 10/14] need ipxe template in defaults --- internal/pkg/node/constructors.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index cb3ab52d..c17674ee 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -27,6 +27,7 @@ defaultnode: args: quiet crashkernel=no vga=791 net.naming-scheme=v238 init: /sbin/init root: initramfs + ipxe template: default profiles: - default network devices: From b73cf0875bd418ab4b71c58351d70dc662a0b9fd Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 30 Nov 2022 11:19:51 +0100 Subject: [PATCH 11/14] react on the error accordingly --- internal/pkg/api/container/container.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/pkg/api/container/container.go b/internal/pkg/api/container/container.go index d02cd950..757ea873 100644 --- a/internal/pkg/api/container/container.go +++ b/internal/pkg/api/container/container.go @@ -293,14 +293,19 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) { wwlog.Debug("Finding kernel version for: %s", source) kernelVersion := container.KernelVersion(source) - - creationTime, err := os.Stat(container.SourceDir(source)) + var creationTime uint64 + sourceStat, err := os.Stat(container.SourceDir(source)) if err != nil { wwlog.Error("%s\n", err) + } else { + creationTime = uint64(sourceStat.ModTime().Unix()) } - modTime, err := os.Stat(container.ImageFile(source)) + var modTime uint64 + imageStat, err := os.Stat(container.ImageFile(source)) if err != nil { wwlog.Error("%s\n", err) + } else { + modTime = uint64(imageStat.ModTime().Unix()) } size, err := util.DirSize(container.SourceDir(source)) if err != nil { @@ -309,20 +314,22 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) { imgSize, err := os.Stat(container.ImageFile(source)) if err != nil { wwlog.Error("%s\n", err) + } else { + size += imgSize.Size() } - size += imgSize.Size() imgSize, err = os.Stat(container.ImageFile(source) + ".gz") if err != nil { wwlog.Error("%s\n", err) + } else { + size += imgSize.Size() } - size += imgSize.Size() containerInfo = append(containerInfo, &wwapiv1.ContainerInfo{ Name: source, NodeCount: uint32(nodemap[source]), KernelVersion: kernelVersion, - CreateDate: uint64(creationTime.ModTime().Unix()), - ModDate: uint64(modTime.ModTime().Unix()), + CreateDate: creationTime, + ModDate: modTime, Size: uint64(size), }) From 9ec86a18b41919176f2ece96d3fb7bccb4da0196 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 30 Nov 2022 11:20:39 +0100 Subject: [PATCH 12/14] enable the warewulf service --- Dockerfile | 8 ++++++-- Makefile | 7 +++---- container-scripts/label-install | 2 +- internal/pkg/container/kernel.go | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ae12012..ceaa9bca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,7 @@ LABEL maintainer="Christian Goll " COPY --from=builder /usr/bin/wwctl /usr/bin/wwctl COPY --from=builder /var/lib/warewulf /var/lib/warewulf COPY --from=builder /usr/share/warewulf /usr/share/warewulf +COPY --from=builder /usr/lib/systemd/system/warewulfd.service /container-scripts/warewulfd.service COPY --from=builder /etc/warewulf /etc/warewulf COPY --from=builder /warewulf-src/container-scripts /container-scripts @@ -49,6 +50,7 @@ RUN zypper -n install \ less \ dhcp-server \ iproute2 \ + vim \ tftp \ systemd \ && \ @@ -74,11 +76,13 @@ RUN zypper -n install \ mkdir -p /usr/share/bash_completion/completions/ &&\ cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\ mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ - systemctl enable ww4-config + mv -v container-scripts/warewulfd.service /etc/systemd/system/ &&\ + systemctl enable ww4-config &&\ + systemctl enable warewulfd CMD [ "/usr/sbin/init" ] -EXPOSE 67/udp 68/udp 69/udp 9873 +EXPOSE 67/udp 68/udp 69/udp 80 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" diff --git a/Makefile b/Makefile index 993c032e..96405da0 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ $(GOLANGCI_LINT): setup: vendor $(TOOLS_DIR) setup_tools vendor: - ifndef OFFLINE_BUILD +ifndef OFFLINE_BUILD go mod tidy -v go mod vendor endif @@ -125,7 +125,7 @@ $(TOOLS_DIR): # Pre-build steps for source, such as "go generate" config: - # Store configuration for subsequent runs +# Store configuration for subsequent runs printf " $(foreach V,$(VARLIST),$V := $(strip $($V))\n)" > Defaults.mk # Global variable search and replace for all *.in files find . -type f -name "*.in" -not -path "./vendor/*" \ @@ -256,8 +256,7 @@ warewulfconf: config_defaults dist: vendor config rm -rf .dist/$(WAREWULF)-$(VERSION) $(WAREWULF)-$(VERSION).tar.gz mkdir -p .dist/$(WAREWULF)-$(VERSION) - cp -rap * .dist/$(WAREWULF)-$(VERSION)/ - find .dist/$(WAREWULF)-$(VERSION)/ -type f -name '*~' -delete + rsync -a --exclude=".*" --exclude "*~" * .dist/$(WAREWULF)-$(VERSION)/ cd .dist; tar -czf ../$(WAREWULF)-$(VERSION).tar.gz $(WAREWULF)-$(VERSION) rm -rf .dist diff --git a/container-scripts/label-install b/container-scripts/label-install index 35c99e33..e29365fb 100755 --- a/container-scripts/label-install +++ b/container-scripts/label-install @@ -43,7 +43,7 @@ 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") + test -e /host/${DIR} && (rsync -au --ignore-existing ${DIR} `dirname /host/${DIR}`; echo "updating $DIR") } # For podman, cp a systemd unit for starting on boot diff --git a/internal/pkg/container/kernel.go b/internal/pkg/container/kernel.go index c3f94db0..1e50df65 100644 --- a/internal/pkg/container/kernel.go +++ b/internal/pkg/container/kernel.go @@ -15,11 +15,11 @@ var ( `vmlinuz`, `vmlinux-*`, `vmlinuz-*`, - `vmlinuz.gz` } + `vmlinuz.gz`} kernelDirs = []string{ `/lib/modules/*/`, - `/boot/` } + `/boot/`} ) func KernelFind(container string) string { From 275a89a78b49c0fc654aca44da21821a2eba21df Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 30 Nov 2022 15:29:50 +0100 Subject: [PATCH 13/14] disable nfs and copy ssh public keys to container --- Dockerfile | 14 ++++++++------ container-scripts/config-warewulf | 3 ++- container-scripts/label-install | 10 ++++++++-- container-scripts/label-purge | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index ceaa9bca..048a51fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,7 @@ RUN zypper -n install \ dhcp-server \ iproute2 \ vim \ + yq \ tftp \ systemd \ && \ @@ -61,11 +62,12 @@ RUN zypper -n install \ 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 && \ + yq e '.ipaddr |= "EMPTY"' -i $WW4CONF && \ + yq e '.netmask |= "EMPTY"' -i $WW4CONF && \ + yq e '.network |= "EMPTY"' -i $WW4CONF && \ + yq e '.dhcp.["range start"] |= "EMPTY"' -i $WW4CONF && \ + yq e '.dhcp.["range end"] |= "EMPTY"' -i $WW4CONF && \ + yq e '.nfs.enabled |= false' -i $WW4CONF && \ mkdir -p /container && \ cp -vr container-scripts/label-* \ container-scripts/wwctl \ @@ -74,7 +76,7 @@ RUN zypper -n install \ container-scripts/config-warewulf \ /container &&\ mkdir -p /usr/share/bash_completion/completions/ &&\ - cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/wwctl &&\ + cp /etc/warewulf/bash_completion.d/warewulf /usr/share/bash_completion/completions/warewulf &&\ mv -v container-scripts/ww4-config.service /etc/systemd/system/ &&\ mv -v container-scripts/warewulfd.service /etc/systemd/system/ &&\ systemctl enable ww4-config &&\ diff --git a/container-scripts/config-warewulf b/container-scripts/config-warewulf index cd4dfbd5..fd6254b2 100755 --- a/container-scripts/config-warewulf +++ b/container-scripts/config-warewulf @@ -69,6 +69,7 @@ fi # configure the services of the host by building the host overlay echo "-- Running wwctl --" -wwctl overlay build # enable tftp if systemd is running test -e /run/systemd/system && wwctl configure tftp +test -e /run/systemd/system && wwctl configure ssh +wwctl overlay build diff --git a/container-scripts/label-install b/container-scripts/label-install index e29365fb..470ff0e0 100755 --- a/container-scripts/label-install +++ b/container-scripts/label-install @@ -12,7 +12,8 @@ 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 +BASHCOMPLETION=/usr/share/bash_completion/completions/w* +AUTHKEYDIR=/root/.ssh echo "LABEL INSTALL" # ensure all scripts will be present on the host @@ -67,10 +68,15 @@ sync_dir $CHROOTDIR sync_dir $WAREWULFCONF # bash completion -if [ ! -e /host/etc/bash_completion.d/wwctl ] ; then +if [ ! -e /host/etc/bash_completion.d/warewulf ] ; then mkdir -p /host/etc/bash_completion.d cp $BASHCOMPLETION /host/etc/bash_completion.d/ fi # containerdir mkdir -p /host/$CONTAINERDIR + +# authorized keys +mkdir -p /root/.ssh/ +echo "Copy authorized keys to container" +test -e /host/${AUTHKEYDIR}/*pub && cp -v /host/${AUTHKEYDIR}/*pub ${AUTHKEYDIR} || echo "no public keys found" diff --git a/container-scripts/label-purge b/container-scripts/label-purge index 95568309..f4dc9118 100755 --- a/container-scripts/label-purge +++ b/container-scripts/label-purge @@ -1,6 +1,7 @@ #!/bin/bash OVERLAYDIR=/var/lib/warewulf/overlays CHROOTDIR=/var/lib/warewulf/chroots +OCIDIR=/var/lib/warewulf/oci CONTAINERDIR=/var/lib/warewulf/container WAREWULFCONF=/etc/warewulf BASEDIR=/var/lib/warewulf @@ -28,6 +29,6 @@ while true ; do done echo "PURGING" /container/label-uninstall -rm -rv /host/$WAREWULFCONF /host/$OVERLAYDIR /host/$CHROOTDIR /host/$CONTAINERDIR +rm -rv /host/$WAREWULFCONF /host/$OVERLAYDIR /host/$CHROOTDIR /host/$CONTAINERDIR /host/$OCIDIR rmdir /host/$BASEDIR From ecf24be2f91b8468445a4989078a5bd9bfdd96e8 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 30 Nov 2022 16:15:59 +0100 Subject: [PATCH 14/14] need libgpgme --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 048a51fd..dfffc58e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM opensuse/tumbleweed:latest as builder -RUN zypper -n install --no-recommends git go1.18 &&\ +RUN zypper -n install --no-recommends git go1.18 libgpgme-devel &&\ zypper -n install -t pattern devel_basis # now build the warewulf