diff --git a/Dockerfile b/Dockerfile index 4d55339b..fa11dd55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,17 @@ FROM ubuntu:24.04 LABEL maintainer="datapunt@amsterdam.nl" ARG DEBIAN_FRONTEND=noninteractive +# build-time inputs +ARG EXTRA_ARG1 +ARG EXTRA_ARG2 + +ENV MAP_URL="${EXTRA_ARG1:-http://localhost:8383}" \ + LEGEND_URL="${EXTRA_ARG2:-http://localhost:8383}" + +# echo domain variables used +RUN echo "Using ARGS=$EXTRA_ARG1 LEGEND_URL=$EXTRA_ARG2" +RUN echo "Using MAP_URL=$MAP_URL LEGEND_URL=$LEGEND_URL" + RUN apt-get update -y \ && apt-get install -y --no-install-recommends \ apache2 \ @@ -16,15 +27,22 @@ RUN apt-get update -y \ # Enable these Apache modules RUN a2enmod actions cgid headers rewrite +# rm default access log +RUN a2disconf other-vhosts-access-log # Configure localhost in Apache RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf +RUN sed -i '/^Listen 80$/d' /etc/apache2/ports.conf #config file COPY mapserver.conf /usr/local/etc/ RUN echo "SetEnv MAPSERVER_CONFIG_FILE \"/usr/local/etc/mapserver.conf\"" >> /etc/apache2/apache2.conf +# apache config RUN rm /etc/apache2/mods-enabled/alias.conf +COPY docker/conf/custom.conf /etc/apache2/conf-enabled/ +COPY docker/conf/ports.conf /etc/apache2/ports.conf + COPY docker/000-default.conf /etc/apache2/sites-available/ COPY docker/docker-entrypoint.sh /bin COPY epsg /usr/share/proj @@ -35,8 +53,14 @@ RUN groupmod -o -g 999 www-data RUN mkdir /var/lock/apache2 && mkdir /var/run/apache2 RUN chown -R 999:999 /var/lock/apache2 && chown -R 999:999 /var/run/apache2 && chown -R 999:999 /var/log/apache2/ RUN chown -R 999:999 /srv/ && chown -R 999:999 /etc/apache2/ +# maps COPY --chown=999:999 . /srv/mapserver/ +RUN for i in /srv/mapserver/*.map; do echo $i; done +RUN : "${MAP_URL:?MAP_URL not set}" \ + && : "${LEGEND_URL:?LEGEND_URL not set}" \ + && for i in /srv/mapserver/*.map; do sed -i 's#MAP_URL_REPLACE#'"$MAP_URL"'#g' $i ; sed -i 's#LEGEND_URL_REPLACE#'"$LEGEND_URL"'#g' $i; done RUN rm -rf /srv/mapserver/private +RUN python3 /srv/mapserver/tools/make_indexjson.py /srv/mapserver/*.map > /srv/mapserver/index.json EXPOSE 8080 diff --git a/docker/000-default.conf b/docker/000-default.conf index 993755d8..99547aa6 100644 --- a/docker/000-default.conf +++ b/docker/000-default.conf @@ -1,6 +1,6 @@ # Never run the server with LOCAL set in production - + ServerAdmin datapunt@amsterdam.nl DocumentRoot /srv/mapserver diff --git a/docker/conf/custom.conf b/docker/conf/custom.conf new file mode 100644 index 00000000..05123972 --- /dev/null +++ b/docker/conf/custom.conf @@ -0,0 +1,3 @@ +Timeout 600 +ErrorLog /dev/stderr +CustomLog /dev/stdout combined diff --git a/docker/conf/ports.conf b/docker/conf/ports.conf new file mode 100644 index 00000000..3cc6764e --- /dev/null +++ b/docker/conf/ports.conf @@ -0,0 +1 @@ +Listen 8080 diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index e9c0a4c0..9aab10a5 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -39,31 +39,11 @@ CONNECTION "host=${DATASERVICES_DB_HOST} dbname=${DATASERVICES_DB_NAME} user=${D PROCESSING "CLOSE_CONNECTION=DEFER" EOF -# Configure apache to redirect errors to stderr. -# The mapserver will redirect errors to apache errorstream (see header.inc and private/header.inc) -# and apache will then redirect this to stderr, which will then be redirected to syslog/kibana. -# ref: http://mapserver.org/optimization/debugging.html#steps-to-enable-mapserver-debugging -# https://serverfault.com/questions/711168/writing-apache2-logs-to-stdout-stderr -sed -i 's/ErrorLog .*/ErrorLog \/dev\/stderr/' /etc/apache2/apache2.conf -sed -i 's/Timeout 300/Timeout 600/' /etc/apache2/apache2.conf -# set listen port to non-privileged port -sed -i '0,/Listen [0-9]*/s//Listen 8080/' /etc/apache2/ports.conf -sed -i s/\/ /etc/apache2/sites-enabled/000-default.conf - # Replace actual location of the mapserver depending on the environment shopt -s globstar nullglob -for i in **/*.map; do - sed -i 's#MAP_URL_REPLACE#'"$MAP_URL"'#g' $i - sed -i 's#LEGEND_URL_REPLACE#'"$LEGEND_URL"'#g' $i -done - -mkdir -p /srv/mapserver/config # python3 /srv/mapserver/tools/make_mapfile_config.py > /srv/mapserver/sld/config.json -echo Make JSON index of maps -python3 /srv/mapserver/tools/make_indexjson.py /srv/mapserver/*.map > /srv/mapserver/index.json - echo Starting server # Apache gets grumpy about PID files pre-existing rm -f /var/run/apache2/apache2.pid