From db550aca52cda3346b06943ef2b2bf3650066e44 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 30 Jul 2024 11:43:40 +1000 Subject: [PATCH 1/2] Added QGIS server container. --- compose/docker-compose.yml | 25 ++++++++++++ images/qgis-server/Dockerfile | 54 +++++++++++++++++++++++++ images/qgis-server/cmd.sh | 5 +++ images/qgis-server/data/pg_service.conf | 6 +++ 4 files changed, 90 insertions(+) create mode 100644 images/qgis-server/Dockerfile create mode 100644 images/qgis-server/cmd.sh create mode 100644 images/qgis-server/data/pg_service.conf diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 41cdaad..3487b53 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -36,6 +36,31 @@ services: interval: 30s start_period: 30s + qgis-server: + # Should use version with utf-8 locale support: + image: qgis-server:latest + logging: + driver: local + options: + max-file: "3" + restart: unless-stopped + ports: + - "5555:5555" + volumes: + - /home/dtaylor/broker/images/qgis-server/data:/data:ro + - /home/dtaylor/broker/images/qgis-server/data/STE_2021_AUST_SHP_GDA94:/Downloads/STE_2021_AUST_SHP_GDA94 + environment: + - LANG=en_EN.UTF-8 + - QGIS_PROJECT_FILE=/data/SP-devices.qgz + - QGIS_SERVER_LOG_LEVEL=0 # INFO (log all requests) +# - QGIS_SERVER_CACHE_DIRECTORY=/tmp +# - QGIS_SERVER_DISABLE_GETPRINT=true +# - QGIS_SERVER_IGNORE_BAD_LAYERS=true + - QGIS_SERVER_LOG_STDERR=true +# - QGIS_SERVER_PARALLEL_RENDERING=true + - QGIS_SERVER_PROJECT_CACHE_STRATEGY=filesystem + - DEBUG=1 # display env before spawning QGIS Server + restapi: image: broker/python-base logging: diff --git a/images/qgis-server/Dockerfile b/images/qgis-server/Dockerfile new file mode 100644 index 0000000..32b5674 --- /dev/null +++ b/images/qgis-server/Dockerfile @@ -0,0 +1,54 @@ +FROM debian:bookworm-slim + +ENV LANG=en_EN.UTF-8 + + +RUN apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests --allow-unauthenticated -y \ + gnupg \ + ca-certificates \ + wget \ + locales \ + && localedef -i en_US -f UTF-8 en_US.UTF-8 \ + # Add the current key for package downloading + # Please refer to QGIS install documentation (https://www.qgis.org/fr/site/forusers/alldownloads.html#debian-ubuntu) + && mkdir -m755 -p /etc/apt/keyrings \ + && wget -O /etc/apt/keyrings/qgis-archive-keyring.gpg https://download.qgis.org/downloads/qgis-archive-keyring.gpg \ + # Add repository for latest version of qgis-server + # Please refer to QGIS repositories documentation if you want other version (https://qgis.org/en/site/forusers/alldownloads.html#repositories) + && echo "deb [signed-by=/etc/apt/keyrings/qgis-archive-keyring.gpg] https://qgis.org/debian bookworm main" | tee /etc/apt/sources.list.d/qgis.list \ + && apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests --allow-unauthenticated -y \ + qgis-server \ + spawn-fcgi \ + xauth \ + xvfb \ + && apt-get remove --purge -y \ + gnupg \ + wget \ + && rm -rf /var/lib/apt/lists/* + +RUN useradd -m qgis + +ENV TINI_VERSION v0.19.0 +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +RUN chmod +x /tini + +ENV QGIS_PREFIX_PATH /usr +ENV QGIS_SERVER_LOG_STDERR 1 +ENV QGIS_SERVER_LOG_LEVEL 2 + +COPY cmd.sh /home/qgis/cmd.sh +RUN chmod -R 777 /home/qgis/cmd.sh +RUN chown qgis:qgis /home/qgis/cmd.sh + +COPY data/pg_service.conf /home/qgis/.pg_service.conf +RUN chmod -R 444 /home/qgis/.pg_service.conf +RUN chown qgis:qgis /home/qgis/.pg_service.conf + +USER qgis +WORKDIR /home/qgis + +ENTRYPOINT ["/tini", "--"] + +CMD ["/home/qgis/cmd.sh"] diff --git a/images/qgis-server/cmd.sh b/images/qgis-server/cmd.sh new file mode 100644 index 0000000..7ceee99 --- /dev/null +++ b/images/qgis-server/cmd.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +[[ $DEBUG == "1" ]] && env + +exec /usr/bin/xvfb-run --auto-servernum --server-num=1 /usr/bin/spawn-fcgi -p 5555 -n -d /home/qgis -- /usr/lib/cgi-bin/qgis_mapserv.fcgi diff --git a/images/qgis-server/data/pg_service.conf b/images/qgis-server/data/pg_service.conf new file mode 100644 index 0000000..7fcf8ef --- /dev/null +++ b/images/qgis-server/data/pg_service.conf @@ -0,0 +1,6 @@ +[scmn] +host=db +port=5432 +dbname=broker +user=postgres +password=CHANGEME From 31c281c2c9bdaf5195302ea15102c8c1a8d73666 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 9 Aug 2024 10:41:23 +1000 Subject: [PATCH 2/2] Now creating a versioned image. --- compose/docker-compose.yml | 16 ++++++---------- images/qgis-server/Dockerfile | 11 ++++++++--- run.sh | 8 +++++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 3487b53..5e3d754 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -37,8 +37,7 @@ services: start_period: 30s qgis-server: - # Should use version with utf-8 locale support: - image: qgis-server:latest + image: qgis-server:3.38.1 logging: driver: local options: @@ -47,17 +46,14 @@ services: ports: - "5555:5555" volumes: - - /home/dtaylor/broker/images/qgis-server/data:/data:ro - - /home/dtaylor/broker/images/qgis-server/data/STE_2021_AUST_SHP_GDA94:/Downloads/STE_2021_AUST_SHP_GDA94 + - ../images/qgis-server/data:/data:ro + - ../images/qgis-server/data/STE_2021_AUST_SHP_GDA94:/Downloads/STE_2021_AUST_SHP_GDA94:ro environment: - LANG=en_EN.UTF-8 - - QGIS_PROJECT_FILE=/data/SP-devices.qgz - - QGIS_SERVER_LOG_LEVEL=0 # INFO (log all requests) -# - QGIS_SERVER_CACHE_DIRECTORY=/tmp -# - QGIS_SERVER_DISABLE_GETPRINT=true -# - QGIS_SERVER_IGNORE_BAD_LAYERS=true + - QGIS_PROJECT_FILE=/data/LogicalDevs.qgs + - QGIS_SERVER_LOG_LEVEL=1 # Warnings - QGIS_SERVER_LOG_STDERR=true -# - QGIS_SERVER_PARALLEL_RENDERING=true + - QGIS_SERVER_PARALLEL_RENDERING=true - QGIS_SERVER_PROJECT_CACHE_STRATEGY=filesystem - DEBUG=1 # display env before spawning QGIS Server diff --git a/images/qgis-server/Dockerfile b/images/qgis-server/Dockerfile index 32b5674..011bbea 100644 --- a/images/qgis-server/Dockerfile +++ b/images/qgis-server/Dockerfile @@ -19,13 +19,16 @@ RUN apt-get update \ && echo "deb [signed-by=/etc/apt/keyrings/qgis-archive-keyring.gpg] https://qgis.org/debian bookworm main" | tee /etc/apt/sources.list.d/qgis.list \ && apt-get update \ && apt-get install --no-install-recommends --no-install-suggests --allow-unauthenticated -y \ - qgis-server \ + qgis-server=1:3.38.1+17bookworm \ spawn-fcgi \ xauth \ xvfb \ + vim \ + postgresql-client \ && apt-get remove --purge -y \ gnupg \ wget \ + && apt -y autoremove \ && rm -rf /var/lib/apt/lists/* RUN useradd -m qgis @@ -36,14 +39,16 @@ RUN chmod +x /tini ENV QGIS_PREFIX_PATH /usr ENV QGIS_SERVER_LOG_STDERR 1 -ENV QGIS_SERVER_LOG_LEVEL 2 +ENV QGIS_SERVER_LOG_LEVEL 1 COPY cmd.sh /home/qgis/cmd.sh RUN chmod -R 777 /home/qgis/cmd.sh RUN chown qgis:qgis /home/qgis/cmd.sh +# QGIS server seems to ignore the PGSERVICEFILE env var so the servivces file +# must be in the default location. COPY data/pg_service.conf /home/qgis/.pg_service.conf -RUN chmod -R 444 /home/qgis/.pg_service.conf +RUN chmod -R 644 /home/qgis/.pg_service.conf RUN chown qgis:qgis /home/qgis/.pg_service.conf USER qgis diff --git a/run.sh b/run.sh index 9df61f3..7b56073 100755 --- a/run.sh +++ b/run.sh @@ -13,9 +13,15 @@ cd $BROKER_ROOT cd compose/$MODE ./dc.sh down cd $BROKER_ROOT +echo Building REST API image docker build -q -t broker/python-base -f images/restapi/Dockerfile . +echo Building TTN decoder image docker build -q -t broker/ttn_decoder -f images/ttn_decoder/Dockerfile . +echo Building web app image docker build -q -t broker/mgmt-app -f src/www/Dockerfile . -cd compose/$MODE +echo Building QGIS server image +cd images/qgis-server +docker build -q -f Dockerfile -t qgis-server:3.38.1 ./ +cd ../../compose/$MODE ./dc.sh up -d ./dc.sh logs -f