From 644b94021e825126c59a59f611cd8a5e85a75386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 26 Nov 2024 08:58:51 +0100 Subject: [PATCH] Add support of lighttpd --- Dockerfile | 22 ++++++++++----- acceptance_tests/conftest.py | 10 +++++++ acceptance_tests/docker-compose.yaml | 34 ++++++++++++++++++++--- acceptance_tests/test_map.py | 9 +++++++ runtime/etc/lighttpd/lighttpd.conf | 18 +++++++++++++ runtime/usr/local/bin/start-server | 40 ++++++++++++++++++---------- 6 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 runtime/etc/lighttpd/lighttpd.conf diff --git a/Dockerfile b/Dockerfile index 6220e035..1ab49931 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM ghcr.io/osgeo/gdal:ubuntu-small-3.8.5 as gdal +FROM ghcr.io/osgeo/gdal:ubuntu-small-3.8.5 AS gdal -FROM gdal as builder -LABEL maintainer Camptocamp "info@camptocamp.com" +FROM gdal AS builder +LABEL maintainer="Camptocamp " SHELL ["/bin/bash", "-o", "pipefail", "-cux"] RUN --mount=type=cache,target=/var/cache,sharing=locked \ @@ -67,8 +67,8 @@ RUN if test "${WITH_ORACLE}" = "ON"; then \ RUN ninja install \ && if test "${WITH_ORACLE}" = "ON"; then rm -rf /usr/local/lib/sdk; fi -FROM gdal as runner -LABEL maintainer Camptocamp "info@camptocamp.com" +FROM gdal AS runner +LABEL maintainer="Camptocamp " SHELL ["/bin/bash", "-o", "pipefail", "-cux"] # Let's copy a few of the settings from /etc/init.d/apache2 @@ -89,7 +89,8 @@ RUN --mount=type=cache,target=/var/cache,sharing=locked \ && apt-get upgrade --assume-yes \ && apt-get install --assume-yes --no-install-recommends ca-certificates apache2 libapache2-mod-fcgid \ libfribidi0 librsvg2-2 libpng16-16 libgif7 libfcgi0ldbl \ - libxslt1.1 libprotobuf-c1 libaio1 libpcre2-posix3 glibc-tools + libxslt1.1 libprotobuf-c1 libaio1 libpcre2-posix3 glibc-tools \ + spawn-fcgi lighttpd RUN a2enmod fcgid headers status \ && a2dismod -f auth_basic authn_file authn_core authz_user autoindex dir \ @@ -122,6 +123,7 @@ ENV MS_DEBUGLEVEL=0 \ MS_ERRORFILE=stderr \ MAPSERVER_CONFIG_FILE=/etc/mapserver.conf \ MAPSERVER_BASE_PATH= \ + OGCAPI_HTML_TEMPLATE_DIRECTORY=/usr/local/share/mapserver/ogcapi/templates/html-bootstrap4/ \ MAX_REQUESTS_PER_PROCESS=1000 \ MIN_PROCESSES=1 \ MAX_PROCESSES=5 \ @@ -129,7 +131,13 @@ ENV MS_DEBUGLEVEL=0 \ IDLE_TIMEOUT=300 \ IO_TIMEOUT=40 \ APACHE_LIMIT_REQUEST_LINE=8190 \ - GET_ENV=env + GET_ENV=env \ + SERVER=apache \ + LIGHTTPD_CONF=/etc/lighttpd/lighttpd.conf \ + LIGHTTPD_PORT=8080 \ + LIGHTTPD_FASTCGI_HOST=spawn-fcgi \ + LIGHTTPD_FASTCGI_PORT=3000 \ + LIGHTTPD_ACCESSLOG_FORMAT="%h %V %u %t \"%r\" %>s %b" CMD ["/usr/local/bin/start-server"] diff --git a/acceptance_tests/conftest.py b/acceptance_tests/conftest.py index 6a796e96..f412eaac 100644 --- a/acceptance_tests/conftest.py +++ b/acceptance_tests/conftest.py @@ -10,6 +10,7 @@ BASE_URL_MAP = "http://mapserver-map:8080" BASE_URL_OGCAPI = "http://mapserver-ogcapi:8080/mymap/ogcapi" BASE_URL_BASE_PATH = "http://mapserver-path:8080/this/is/a/test" +BASE_URL_LIGHTTPD = "http://mapserver-lighttpd:8080" @pytest.fixture @@ -40,3 +41,12 @@ def connection_ogcapi(): """ utils.wait_url(BASE_URL_OGCAPI + "/collections/polygons?f=html") return Connection(BASE_URL_OGCAPI, "http://localhost") + + +@pytest.fixture +def connection_lighttpd(): + """ + Fixture that returns a connection to a running batch container. + """ + utils.wait_url(BASE_URL_LIGHTTPD) + return Connection(BASE_URL_LIGHTTPD, "http://localhost") diff --git a/acceptance_tests/docker-compose.yaml b/acceptance_tests/docker-compose.yaml index 5404a7e7..4c047948 100644 --- a/acceptance_tests/docker-compose.yaml +++ b/acceptance_tests/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '2' - volumes: tmp: logs: @@ -60,7 +58,6 @@ services: MS_DEBUGLEVEL: '5' MAPSERVER_CATCH_SEGV: '1' MAPSERVER_CONFIG_FILE: /etc/mapserver/landingpage.conf - OGCAPI_HTML_TEMPLATE_DIRECTORY: /usr/local/share/mapserver/ogcapi/templates/html-bootstrap4/ links: - db # ports: @@ -69,6 +66,37 @@ services: - ./config/mapserver/:/etc/mapserver user: www-data + mapserver-spawn-fcgi: + image: camptocamp/mapserver:${DOCKER_TAG} + environment: + MS_DEBUGLEVEL: '5' + MS_MAPFILE: /etc/mapserver/mapserver.map + SERVER: spawn-fcgi + read_only: true + links: + - db + volumes: + - ./config/mapserver/:/etc/mapserver + - tmp:/tmp + - logs:/var/log/ + user: 12311:12311 + + mapserver-lighttpd: + image: camptocamp/mapserver:${DOCKER_TAG} + environment: + SERVER: lighttpd + LIGHTTPD_FASTCGI_HOST: mapserver-spawn-fcgi + read_only: true + links: + - db + # ports: + # - 8380:8080 + volumes: + - ./config/mapserver/:/etc/mapserver + - tmp:/tmp + - logs:/var/log/ + user: 12311:12311 + db: image: camptocamp/postgres:17-postgis-3 environment: diff --git a/acceptance_tests/test_map.py b/acceptance_tests/test_map.py index faaea4dc..d59feacf 100644 --- a/acceptance_tests/test_map.py +++ b/acceptance_tests/test_map.py @@ -23,3 +23,12 @@ def test_get_folder_map(connection_map): ) assert [e.text for e in answer.findall(f"{ns}Service/{ns}Title")] == ["test"] assert [e.text for e in answer.findall(f".//{ns}Layer/{ns}Name")] == ["test", "polygons"] + + +def test_lighttpd(connection_lighttpd): + ns = "{http://www.opengis.net/wms}" + answer = connection_lighttpd.get_xml( + "?MAP=/etc/mapserver/mapserver.map&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0" + ) + assert [e.text for e in answer.findall(f"{ns}Service/{ns}Title")] == ["test"] + assert [e.text for e in answer.findall(f".//{ns}Layer/{ns}Name")] == ["test", "polygons"] diff --git a/runtime/etc/lighttpd/lighttpd.conf b/runtime/etc/lighttpd/lighttpd.conf new file mode 100644 index 00000000..0c81199d --- /dev/null +++ b/runtime/etc/lighttpd/lighttpd.conf @@ -0,0 +1,18 @@ +server.modules = ( "mod_accesslog", "mod_auth", "mod_fastcgi" ) + +server.document-root = "/none" +server.port = env.LIGHTTPD_PORT +server.errorlog = "/dev/fd/2" + +accesslog.format = env.LIGHTTPD_ACCESSLOG_FORMAT +accesslog.filename = "/dev/fd/2" + +fastcgi.server = ( "" => + ( + ( + "host" => env.LIGHTTPD_FASTCGI_HOST, + "port" => env.LIGHTTPD_FASTCGI_PORT, + "check-local" => "disable", + ), + ) +) diff --git a/runtime/usr/local/bin/start-server b/runtime/usr/local/bin/start-server index 8a0b9ab5..d559f8d8 100755 --- a/runtime/usr/local/bin/start-server +++ b/runtime/usr/local/bin/start-server @@ -1,21 +1,33 @@ #!/bin/bash -e -# save the environment to be able to restore it in the FCGI daemon (used -# in /usr/local/bin/qgis_mapsev_wrapper) for the startup code. -${GET_ENV} | sed -e 's/^\([^=]*\)=.*/PassEnv \1/' > /tmp/pass-env +if [ "${SERVER}" == spawn-fcgi ]; then + echo "Starting with spawn-fcgi" + exec /usr/bin/spawn-fcgi -p "${LIGHTTPD_FASTCGI_PORT}" -n -- /usr/local/bin/mapserv +else + if [ "${SERVER}" == lighttpd ]; then + echo "Starting lighttpd" + exec lighttpd -D -f "${LIGHTTPD_CONF}" + else + echo "Starting with apache2" -# Save the environment to be able to restore it in the FCGI daemon (used in /usr/local/bin/mapserv_wrapper) -${GET_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init_env + # save the environment to be able to restore it in the FCGI daemon (used + # in /usr/local/bin/qgis_mapsev_wrapper) for the startup code. + ${GET_ENV} | sed -e 's/^\([^=]*\)=.*/PassEnv \1/' > /tmp/pass-env -if [ "${UID}" == 0 ]; then - echo "Switching listen port to 80" - cd /tmp - sed -i -e 's///' /etc/apache2/sites-available/000-default.conf - sed -i -e 's/Listen 8080$/Listen 80/' /etc/apache2/ports.conf -fi + # Save the environment to be able to restore it in the FCGI daemon (used in /usr/local/bin/mapserv_wrapper) + ${GET_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init_env + + if [ "${UID}" == 0 ]; then + echo "Switching listen port to 80" + cd /tmp + sed -i -e 's///' /etc/apache2/sites-available/000-default.conf + sed -i -e 's/Listen 8080$/Listen 80/' /etc/apache2/ports.conf + fi -trap '' WINCH + trap '' WINCH -rm -f "${APACHE_PID_FILE}" + rm -f "${APACHE_PID_FILE}" -exec apache2 -DFOREGROUND + exec apache2 -DFOREGROUND + fi +fi