diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..533919e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM neale/eris + +RUN apk --no-cache add lua5.2 +RUN apk --no-cache add lua5.3 + +# Install MOTH. This could be less obtuse. +COPY www /moth/www +COPY bin /moth/bin +RUN mkdir -p /moth/state/teams /moth/state/points.new /moth/state/points.tmp +RUN chown www:www /moth/state/teams /moth/state/points.new /moth/state/points.tmp +RUN mkdir -p /moth/packages +RUN touch /moth/state/points.log +RUN ln -s ../state/puzzles.json /moth/www/puzzles.json +RUN ln -s ../state/points.json /moth/www/points.json + +COPY src/moth-init /usr/sbin/moth-init + +WORKDIR / +CMD ["/usr/sbin/moth-init"] + diff --git a/bin/once b/bin/once index 9439510..af4d152 100755 --- a/bin/once +++ b/bin/once @@ -7,20 +7,36 @@ else fi basedir=$(pwd) -[ -n "$DEBUG" ] && printf "Updating moth instance in %s\n" $(pwd) +log () { + echo "moth: $@" 1>&2 +} # Do nothing if `disabled` is present if [ -f disabled ]; then + log "Instance disabled: doing nothing" exit fi # Reset to initial state if `reset` is present if [ -f reset ]; then + log "Resetting state" rm -f state/teams/* state/points.new/* state/points.tmp/* : > state/points.log rm -f reset fi +# Create some team names if needed +if [ ! -f state/assigned.txt ]; then + log "Generating team names" + hd state/assigned.txt +fi + +# Helpful error message +if [ $(ls packages | wc -l) -eq 0 ]; then + log "error: No packages installed" + exit +fi + # Create a list of currently-active categories : > state/categories.txt.new for dn in packages/*; do diff --git a/src/moth-init b/src/moth-init new file mode 100755 index 0000000..e0cd4d1 --- /dev/null +++ b/src/moth-init @@ -0,0 +1,9 @@ +#! /bin/sh + +while true; do + /moth/bin/once + sleep 20 +done & + +cd /moth/www +s6-tcpserver -u $(id -u www) -g $(id -g www) 0.0.0.0 80 /usr/bin/eris -c -d -.