Skip to content

Commit

Permalink
Working in container with data in volume: /data
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan committed Jul 12, 2020
1 parent c0fa228 commit cd3c58e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 98 deletions.
Empty file modified cobbler-wrapper.sh
100755 → 100644
Empty file.
114 changes: 78 additions & 36 deletions cobbler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,87 @@
FROM ubuntu:bionic

ARG COBBLER_GIT_URL="https://github.com/cobbler/cobbler.git"
ARG COBBLER_GIT_TAG="v3.0.0"
ARG COBBLER_SECRET_KEY="!jd!o9tq7k+@-f-4+r#uqa9b9y(yo%2^ch2iq!pdgmo^$i360j"
ARG COBBLER_GIT_TAG="v3.1.2"

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
apt-get install -y fence-agents ipxe ipmitool \
python3-pip \
apache2 \
apache2-dev \
libsasl2-dev \
libapache2-mod-wsgi-py3 \
make \
isc-dhcp-server \
atftpd \
git \
lsb-release \
net-tools \
curl \
supervisor \
vim \
rsyslog \
grub-efi-amd64-signed \
rsync && \
ln -sf /proc/self/fd/1 /var/log/apache2/access.log && \
ln -sf /proc/self/fd/1 /var/log/apache2/error.log && \
pip3 install j2cli
apt-get install -qqy gnupg curl && \
/bin/sh -c "echo 'deb http://download.opensuse.org/repositories/Debian:/debbuild/Debian_10/ /' > /etc/apt/sources.list.d/debbuild.list" && \
curl -sL http://download.opensuse.org/repositories/Debian:/debbuild/Debian_10/Release.key | apt-key add - && \
apt-get update -qq && \
apt-get install -qqy \
debbuild \
debbuild-macros \
wget \
pycodestyle \
pyflakes3 \
python-django-common \
python3-coverage \
python3-distro \
python3-distutils \
python3-django \
python3-dnspython \
python3-dns \
python3-dnsq \
python3-future \
python3-ldap3 \
python3-netaddr \
python3-pip \
python3-pycodestyle \
python3-pytest \
python3-setuptools \
python3-simplejson \
python3-sphinx \
python3-tornado \
python3-tz \
python3-yaml \
python3-pip \
liblocale-gettext-perl \
lsb-release \
xz-utils \
bzip2 \
dpkg-dev \
tftpd-hpa \
#createrepo \
rsync \
xorriso\
fakeroot \
patch \
pax \
git \
hardlink \
apache2 \
libapache2-mod-wsgi-py3 \
apache2-dev \
libsasl2-dev \
make \
isc-dhcp-server \
net-tools \
supervisor \
vim \
rsyslog \
grub-efi-amd64-signed \
fence-agents \
ipxe \
ipmitool \
lsof \
wget \
systemd && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
ln -sf /proc/self/fd/1 /var/log/apache2/access.log && \
ln -sf /proc/self/fd/1 /var/log/apache2/error.log


RUN git clone --branch $COBBLER_GIT_TAG $COBBLER_GIT_URL && cd cobbler && \
pip3 install -r requirements.txt &&\
RUN git clone --branch $COBBLER_GIT_TAG $COBBLER_GIT_URL --depth 1 && cd cobbler && \
# Ubuntu 18.04's apt package python3-cheetah fails to install:
pip3 install cheetah3 j2cli && \
mkdir -p /etc/cobbler/power/ && \
make && \
make install && \
ln -s /srv/tftpboot /var/lib/tftpboot && \
echo "SECRET_KEY='$COBBLER_SECRET_KEY'" >> /usr/local/lib/python3.6/dist-packages/cobbler/web/settings.py && \
ln -s /srv/tftp /var/lib/tftpboot && \
ln -s /usr/local/share/cobbler /usr/share/ && \
export COBBLER_SECRET_KEY=$(head /dev/urandom | tr -dc 'A-Za-z0-9!"#$%()*+,-./:;<=>?@[\]^_`{|}~' | head -c 57 ; echo '') && \
echo "SECRET_KEY='$COBBLER_SECRET_KEY'" >> /usr/local/share/cobbler/web/settings.py && \
sed -i "s|^INTERFACESv4=.*|INTERFACESv4='eth0'|g" /etc/default/isc-dhcp-server && \
echo "lanplus=1" >> /etc/cobbler/power/fence_ipmilan.template && \
touch /var/lib/dhcp/dhcpd.leases && \
Expand All @@ -45,17 +91,13 @@ RUN git clone --branch $COBBLER_GIT_TAG $COBBLER_GIT_URL && cd cobbler && \
COPY tree/ /

RUN service apache2 start && \
mkdir /srv/tftpboot && \
mkdir -p /srv/tftpboot && \
touch /etc/genders && \
/usr/local/bin/cobblerd && \
cobbler signature update && \
cobbler get-loaders && \
cobbler sync && \
ln -s /usr/local/share/cobbler /usr/share/ && \
cp /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed /srv/tftpboot/grubx64.efi && \
cp /usr/lib/ipxe/undionly.kpxe /srv/tftpboot/undionly.kpxe && \
mv /var/lib/cobbler/snippets /var/lib/cobbler/autoinstall_snippets && \
mv /var/lib/cobbler/scripts /var/lib/cobbler/autoinstall_scripts
chown -R 33:0 /var/lib/cobbler/webui_sessions && \
ln -s /var/www/cobbler_webui_content /var/www/html/

ENV COBBLER_SERVER_HOST=127.0.0.1 \
COBBLER_NEXT_SERVER_HOST=192.168.10.91 \
Expand All @@ -73,4 +115,4 @@ EXPOSE 67/udp
EXPOSE 69/udp

ENTRYPOINT ["/usr/bin/supervisord"]
CMD ["-c", "/etc/supervisor/supervisord.conf"]
CMD ["-c", "/etc/supervisor/supervisord.conf"]
26 changes: 0 additions & 26 deletions cobbler/tree/etc/apache2/conf-available/cobbler_web.conf

This file was deleted.

2 changes: 1 addition & 1 deletion cobbler/tree/etc/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ stdout_logfile_maxbytes=0
autorestart=true

[program:atftpd]
command=/usr/sbin/atftpd --daemon --tftpd-timeout 300 --retry-timeout 5 --no-multicast --no-fork --verbose=5 /srv/tftpboot/ --no-source-port-checking --logfile -
command=/usr/sbin/in.tftpd --listen --user tftp --address 0.0.0.0:69 --secure /srv/tftpboot/
priority=7
redirect_stderr=true
stdout_logfile=/dev/fd/1
Expand Down
43 changes: 42 additions & 1 deletion cobbler/tree/usr/local/bin/update-config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
#!/bin/bash
echo "Updating configuration files from environment variables"
mkdir -p /data/var/lib
mkdir -p /data/etc/cobbler
mkdir -p /data/srv
mkdir -p /data/iso
j2 --undefined /etc/cobbler/settings.j2 -o /etc/cobbler/settings
j2 --undefined /etc/cobbler/dhcp.template.j2 -o /etc/cobbler/dhcp.template
j2 --undefined /etc/apache2/conf-available/cobbler_web.conf.j2 -o /etc/apache2/conf-available/cobbler_web.conf
j2 --undefined /var/lib/cobbler/snippets/preseed_bionic_post_deploy.j2 -o /var/lib/cobbler/snippets/preseed_bionic_post_deploy
j2 --undefined /var/lib/cobbler/snippets/preseed_xenial_post_deploy.j2 -o /var/lib/cobbler/snippets/preseed_xenial_post_deploy
if [[ -L /var/www ]]; then
echo "is a symlink"; else
cp --recursive --no-clobber -d /var/www /data/srv/
rm -rf --verbose /var/www
ln --symbolic --verbose /data/srv/www /var/www
fi
if [[ -L /etc/cobbler ]]; then
echo "is a symlink"; else
cp --recursive --no-clobber -d /etc/cobbler /data/etc/
rm -rf --verbose /etc/cobbler
ln --symbolic --verbose /data/etc/cobbler /etc/cobbler
fi
if [[ -L /var/lib/cobbler ]]; then
echo "is a symlink"; else
cp --recursive --no-clobber -d /var/lib/cobbler /data/var/lib/
rm -rf --verbose /var/lib/cobbler/
ln --symbolic --verbose /data/var/lib/cobbler /var/lib/cobbler
fi
if [[ -L /var/lib/dhcp ]]; then
echo "is a symlink"; else
cp --recursive --no-clobber -d /var/lib/dhcp /data/var/lib/
rm -rf --verbose /var/lib/dhcp
ln --symbolic --verbose /data/var/lib/dhcp /var/lib/dhcp
fi
chown -R 33:0 /data/var/lib/cobbler/webui_sessions
chown -R 33:0 /data/var/lib/cobbler/web.ss
if [[ -L /srv ]]; then
echo "is a symlink"; else
cp --recursive --no-clobber -d /srv /data/
rm -rf --verbose /srv
ln --symbolic --verbose /data/srv /srv
fi
unlink /var/lib/tftpboot/tftp
ln --symbolic --verbose /srv/tftpboot /var/lib/tftpboot/tftp
mkdir -p /data/srv/www/cobbler/links
sleep 30
pkill -f tftpd
supervisorctl start atftpd
Empty file modified cobbler/tree/var/lib/cobbler/triggers/sync/post/restart-dhcp.sh
100755 → 100644
Empty file.
21 changes: 8 additions & 13 deletions download-iso-and-mount.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#!/bin/bash
URL_BIONIC="http://cdimage.ubuntu.com/releases/18.04/release/ubuntu-18.04.3-server-amd64.iso"
FILENAME_BIONIC=$(basename $URL_BIONIC)
echo "Downloading $FILENAME_BIONIC"
test -f ~/$FILENAME_BIONIC || curl $URL_BIONIC -o ~/$FILENAME_BIONIC
test -d /mnt/bionic || sudo mkdir /mnt/bionic
sudo mount -o loop ~/$FILENAME_BIONIC /mnt/bionic

URL_XENIAL="http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-amd64.iso"
FILENAME_XENIAL=$(basename $URL_XENIAL)
echo "Downloading $FILENAME_XENIAL"
test -f ~/$FILENAME_XENIAL || curl $URL_XENIAL -o ~/$FILENAME_XENIAL
test -d /mnt/xenial ||sudo mkdir /mnt/xenial
sudo mount -o loop ~/$FILENAME_XENIAL /mnt/xenial
URL="http://cdimage.ubuntu.com/releases/18.04/release/ubuntu-18.04.4-server-amd64.iso"
COBBLER_SHARE_PATH="/mnt2/pool/cobbler"
DISTRO_NAME="ubuntu-18.04.4-server"
FILENAME=$(basename $URL)
echo "Downloading $FILENAME"
test -f ~/$FILENAME || curl $URL -o ~/$FILENAME
test -d ${COBBLER_SHARE_PATH}/iso/${DIR} || mkdir ${COBBLER_SHARE_PATH}/iso/${DISTRO_NAME}
mount -o loop ~/$FILENAME ${COBBLER_SHARE_PATH}/iso/${DIR}
29 changes: 8 additions & 21 deletions import-iso.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,15 @@ if [ ! -f "/usr/local/bin/cobbler" ]; then
echo "\$ docker exec -it cobbler /bin/bash -c \"\$(<import-iso.sh)\""
exit 1
fi
PROFILE_NAME="ubuntu-18.04.2-server"
echo "Importing ${PROFILE_NAME}"
cobbler import --name="$PROFILE_NAME" --path /mnt/bionic --arch=x86_64 --breed ubuntu --autoinstall ubuntu-server-bionic-unattended-cobbler-rpc.seed
DISTRO_NAME="ubuntu-18.04.4-server"
TEMPLATE="ubuntu-server-bionic-unattended-cobbler-rpc.seed"
echo "Importing ${DISTRO_NAME}"
cobbler import --name="$DISTRO_NAME" --path /data/iso/${DISTRO_NAME} --arch=x86_64 --breed ubuntu --autoinstall ${TEMPLATE}
if [[ $? -eq 0 ]]; then
for PROFILE in $(cobbler profile list | grep ${PROFILE_NAME});do
echo "Updating profile $PROFILE"
cobbler profile edit \
--name ${PROFILE} \
for distro in $(cobbler distro list | grep ${DISTRO_NAME});do
echo "Updating distro $distro"
cobbler distro edit \
--name ${distro} \
--kernel-options="ksdevice=bootif lang priority=critical locale=en_US text netcfg/dhcp_timeout=60 netcfg/choose_interface=auto console=tty0"
done
fi

PROFILE_NAME="ubuntu-16.04.6-server"
echo "Importing ${PROFILE_NAME}"
cobbler import --name="$PROFILE_NAME" --path /mnt/xenial --arch=x86_64 --breed ubuntu --autoinstall ubuntu-server-xenial-unattended-cobbler-rpc.seed
if [[ $? -eq 0 ]]; then
for PROFILE in $(cobbler profile list | grep ${PROFILE_NAME});do
echo "Updating profile $PROFILE"
cobbler profile edit \
--name ${PROFILE} \
--kernel-options="ksdevice=bootif lang priority=critical locale=en_US text netcfg/dhcp_timeout=60 netcfg/choose_interface=auto console=tty0"
done
fi
echo "Running cobbler sync"
cobbler sync
Empty file modified inventory/cobbler.py
100755 → 100644
Empty file.

0 comments on commit cd3c58e

Please sign in to comment.