Skip to content

Commit

Permalink
Add support of lighttpd
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 26, 2024
1 parent 31d1b1e commit 644b940
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 24 deletions.
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
FROM gdal AS builder
LABEL maintainer="Camptocamp <[email protected]>"
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]

RUN --mount=type=cache,target=/var/cache,sharing=locked \
Expand Down Expand Up @@ -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 "[email protected]"
FROM gdal AS runner
LABEL maintainer="Camptocamp <[email protected]>"
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]

# Let's copy a few of the settings from /etc/init.d/apache2
Expand All @@ -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 \
Expand Down Expand Up @@ -122,14 +123,21 @@ 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 \
BUSY_TIMEOUT=300 \
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"]

Expand Down
10 changes: 10 additions & 0 deletions acceptance_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
34 changes: 31 additions & 3 deletions acceptance_tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '2'

volumes:
tmp:
logs:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions acceptance_tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
18 changes: 18 additions & 0 deletions runtime/etc/lighttpd/lighttpd.conf
Original file line number Diff line number Diff line change
@@ -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",
),
)
)
40 changes: 26 additions & 14 deletions runtime/usr/local/bin/start-server
Original file line number Diff line number Diff line change
@@ -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/<VirtualHost \*:8080>/<VirtualHost *:80>/' /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/<VirtualHost \*:8080>/<VirtualHost *:80>/' /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

0 comments on commit 644b940

Please sign in to comment.