Skip to content

Commit

Permalink
fix: version update for container testing, other fixes
Browse files Browse the repository at this point in the history
This commit updates the ubuntu version to 22.04 (from 18.04). As part of
these changes, I also made some fixes:

* correctly set an error code if chroot provisioning fails
* resequence some of the package install order, trying to handle locale
  issues more robustly
* improved error messaging
  • Loading branch information
rawlins committed Mar 21, 2024
1 parent 962ca5a commit 4ea88d0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
7 changes: 4 additions & 3 deletions utils/build-testing-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ CONTAINER_TAG=dgl-test

cd `dirname "$0"`/..
docker build --tag $CONTAINER_TAG -f utils/testing-container/Dockerfile .
if [ $? -ne 0 ]; then echo "Aborting after docker build!" && exit 1; fi
if [ $? -ne 0 ]; then echo "docker build failed, aborting!" && exit 1; fi

echo "Provisioning chroot..."
if [ "$1" = '--no-tty' ]; then
docker run --privileged $CONTAINER_TAG --provision-chroot
else
docker run -it --privileged $CONTAINER_TAG --provision-chroot
fi

if [ $? -ne 0 ]; then
echo "Aborting after chroot script!" && exit 1;
echo "chroot provisioning failed, aborting!" && exit 1;
fi

CID=$(docker ps -lq)
docker commit $CID $CONTAINER_TAG
echo "Container commited as '$CONTAINER_TAG'!"
echo "Build succeeded! Final container commited as '$CONTAINER_TAG'."
43 changes: 31 additions & 12 deletions utils/provision-chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,54 @@ CDEV_USER=$(id -u crawl-dev)
if [ $? -ne 0 ]; then echo "No 'crawl-dev' user!"; exit 1; fi
CDEV_GROUP=$(id -g crawl-dev)

# must match the outer distribution.
debootstrap bionic $DGL_CHROOT
# version here must match the outer distribution. `jammy` = ubuntu 22.04
# note, this command is not really rerunnable without resetting the chroot
# directory...
debootstrap jammy $DGL_CHROOT
if [ $? -ne 0 ]; then
echo "Provisioning failed in debootstrap."
exit 1
fi
cp /etc/resolv.conf $DGL_CHROOT/etc/resolv.conf
cp /etc/apt/sources.list $DGL_CHROOT/etc/apt/

# these bind mounts would need to be manually added to the fstab in some setups
mount --bind /proc/ $DGL_CHROOT/proc/
mount --bind /dev/pts/ $DGL_CHROOT/dev/pts/
if [ ! -e $DGL_CHROOT/proc/ ]; then
mount --bind /proc/ $DGL_CHROOT/proc
fi
if [ ! -e $DGL_CHROOT/dev/pts ]; then
mount --bind /dev/pts/ $DGL_CHROOT/dev/pts/
fi

cat << EOF | chroot $DGL_CHROOT/
# minimal package list for running crawl and doing some basic maintenance; you
# may want to curate this further.
apt-get update && apt-get -y install bzip2 python3-minimal ncurses-term locales locales-all sqlite3 libpcre3 liblua5.1-0 autoconf build-essential lsof bison libncursesw5-dev libsqlite3-dev flex sudo libbot-basicbot-perl vim
sed -i -e "s/# $LANG.*/$LANG.UTF-8 UTF-8/" /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
update-locale LANG=$LANG
apt-get update && \
apt-get -y install locales locales-all && \
sed -i -e "s/# $LANG.*/$LANG.UTF-8 UTF-8/" /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=$LANG && \
apt-get -y install bzip2 python3-minimal ncurses-term sqlite3 libpcre3 liblua5.1-0 autoconf build-essential lsof bison libncursesw5-dev libsqlite3-dev flex sudo libbot-basicbot-perl vim && \
# match the uids to the containing system
groupadd crawl -g $CRAWL_GROUP
groupadd crawl-dev -g $CDEV_GROUP
useradd crawl -u $CRAWL_USER -g $CRAWL_GROUP
groupadd crawl -g $CRAWL_GROUP && \
groupadd crawl-dev -g $CDEV_GROUP && \
useradd crawl -u $CRAWL_USER -g $CRAWL_GROUP && \
useradd crawl-dev -u $CDEV_USER -g $CDEV_GROUP
EOF

if [ $? -ne 0 ]; then
echo "Provisioning failed while installing packages."
exit 1
fi

# In order for the webtiles server to work when chrooted, it needs access to
# any packages that are dynamically imported. In general this is very few, but
# Tornado versions >3 rely heavily on dynamic imports. So we copy it into the
# chroot from outside.
# An alternative would be to install a full python setup into the chroot,
# including this package, but this is extremely heavy.
# including this package, but this is extremely heavy. Another alternative might
# be to simply copy the outer python library in (though note the python-minimal
# install above). However, we do want tornado to exactly match...
#
# I'm not sure if this is a reliable recipe for finding package locations in
# general, but it seems to work for tornado.
Expand Down
18 changes: 11 additions & 7 deletions utils/testing-container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:18.04
FROM ubuntu:22.04

# See README.md for what this does and why

Expand All @@ -12,9 +12,17 @@ ARG DEBIAN_FRONTEND=noninteractive
ARG TERM=dumb

# basic prerequisites
RUN apt-get update
RUN apt-get install -y locales locales-all
ENV LANG=en_US.UTF-8
RUN sed -i -e "s/# $LANG.*/$LANG.UTF-8 UTF-8/" /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales \
&& update-locale LANG=$LANG

# TODO: actually set up ccache, this just installs it
RUN apt-get update && apt-get install -y sudo git build-essential autoconf automake bison libncursesw5-dev flex liblua5.1-0-dev libsqlite3-dev libz-dev locales vim locales-all pkg-config python3 python3-pip python3-yaml ccache libpng-dev sqlite3 libpcre3 libpcre3-dev apache2 advancecomp pngcrush debootstrap openssh-server curl \
&& pip3 install tornado \
RUN apt-get install -y sudo git build-essential autoconf automake bison libncursesw5-dev flex liblua5.1-0-dev libsqlite3-dev libz-dev vim pkg-config python3 python3-pip python3-yaml ccache libpng-dev sqlite3 libpcre3 libpcre3-dev apache2 advancecomp pngcrush debootstrap openssh-server curl

RUN pip3 install tornado \
&& ln -s /usr/bin/python3 /usr/bin/python \
&& useradd -m crawl \
&& useradd -m crawl-dev \
Expand All @@ -27,10 +35,6 @@ RUN apt-get update && apt-get install -y sudo git build-essential autoconf autom
&& usermod -G crawl-dev -a root \
&& usermod -G crawl-dev -a www-data

ENV LANG=en_US.UTF-8
RUN sed -i -e "s/# $LANG.*/$LANG.UTF-8 UTF-8/" /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales \
&& update-locale LANG=$LANG

# allow crawl-dev to run various things with sudo without a password. These
# permissions may be too open for a production server.
Expand Down
2 changes: 1 addition & 1 deletion utils/testing-container/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
if [ "$1" = '--provision-chroot' ]; then
/home/crawl-dev/dgamelaunch-config/utils/provision-chroot.sh
exit 0
exit $?
fi

if [ -d "/home/crawl/DGL/proc/" ]; then
Expand Down

0 comments on commit 4ea88d0

Please sign in to comment.