From 4ea88d080b6a3e1f4a9f7e2fe9a8f2e42270435e Mon Sep 17 00:00:00 2001 From: Kyle Rawlins Date: Thu, 21 Mar 2024 11:31:02 -0400 Subject: [PATCH] fix: version update for container testing, other fixes 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 --- utils/build-testing-container.sh | 7 ++-- utils/provision-chroot.sh | 43 ++++++++++++++------ utils/testing-container/Dockerfile | 18 ++++---- utils/testing-container/docker-entrypoint.sh | 2 +- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/utils/build-testing-container.sh b/utils/build-testing-container.sh index 436c5682..1519ca8f 100755 --- a/utils/build-testing-container.sh +++ b/utils/build-testing-container.sh @@ -7,8 +7,9 @@ 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 @@ -16,9 +17,9 @@ else 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'." diff --git a/utils/provision-chroot.sh b/utils/provision-chroot.sh index 3536d54c..adc680d0 100755 --- a/utils/provision-chroot.sh +++ b/utils/provision-chroot.sh @@ -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. diff --git a/utils/testing-container/Dockerfile b/utils/testing-container/Dockerfile index 47d841d4..868010fe 100644 --- a/utils/testing-container/Dockerfile +++ b/utils/testing-container/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:22.04 # See README.md for what this does and why @@ -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 \ @@ -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. diff --git a/utils/testing-container/docker-entrypoint.sh b/utils/testing-container/docker-entrypoint.sh index a1f11256..3eef7b42 100755 --- a/utils/testing-container/docker-entrypoint.sh +++ b/utils/testing-container/docker-entrypoint.sh @@ -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