Skip to content

Commit ed13694

Browse files
committed
Add Dockerfile and build steps for custom image
1 parent 04583e5 commit ed13694

File tree

6 files changed

+237
-0
lines changed

6 files changed

+237
-0
lines changed

docker/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!runtime
3+
!instantclient
4+
!templates

docker/Dockerfile

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.11.0 AS gdal
2+
# see https://github.com/OSGeo/gdal/tree/master/docker#ubuntu-based
3+
4+
FROM gdal AS builder
5+
LABEL maintainer="[email protected]"
6+
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
7+
8+
RUN --mount=type=cache,target=/var/cache,sharing=locked \
9+
--mount=type=cache,target=/root/.cache \
10+
apt-get update \
11+
&& apt-get upgrade --assume-yes \
12+
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends bison \
13+
flex python3-lxml libfribidi-dev swig \
14+
cmake librsvg2-dev colordiff libpq-dev libpng-dev libjpeg-dev libgif-dev libgeos-dev libgd-dev \
15+
libfreetype6-dev libfcgi-dev libcurl4-gnutls-dev libcairo2-dev libxml2-dev \
16+
libxslt1-dev python3-dev python3-pip python3-setuptools python3-venv php-dev libexempi-dev lcov lftp ninja-build git curl \
17+
clang libprotobuf-c-dev protobuf-c-compiler libharfbuzz-dev libcairo2-dev librsvg2-dev \
18+
unixodbc-dev \
19+
&& ln -s /usr/lib/*-linux-gnu/libproj.so.*[0] $(echo /usr/lib/*-linux-gnu)/libproj.so
20+
21+
ARG MAPSERVER_BRANCH
22+
ARG MAPSERVER_REPO
23+
24+
RUN git clone ${MAPSERVER_REPO} --branch=${MAPSERVER_BRANCH} --depth=100 /src \
25+
&& cd /src
26+
27+
RUN --mount=type=cache,target=/var/cache,sharing=locked \
28+
--mount=type=cache,target=/root/.cache
29+
30+
WORKDIR /src/build
31+
RUN cmake .. \
32+
-GNinja \
33+
-DCMAKE_C_FLAGS="-O2 -DPROJ_RENAME_SYMBOLS" \
34+
-DCMAKE_CXX_FLAGS="-O2 -DPROJ_RENAME_SYMBOLS" \
35+
-DCMAKE_BUILD_TYPE=Release \
36+
-DCMAKE_INSTALL_PREFIX=/usr/local \
37+
-DWITH_CLIENT_WMS=1 \
38+
-DWITH_CLIENT_WFS=1 \
39+
-DWITH_OGCAPI=1 \
40+
-DWITH_KML=0 \
41+
-DWITH_SOS=0 \
42+
-DWITH_XMLMAPFILE=0 \
43+
-DWITH_CAIRO=1 \
44+
-DWITH_RSVG=1 \
45+
-DUSE_PROJ=1 \
46+
-DUSE_WFS_SVR=1 \
47+
-DUSE_OGCAPI_SVR=1 \
48+
-DWITH_ORACLESPATIAL=0 \
49+
-DWITH_PYTHON=1 \
50+
-DWITH_MSSQL2008=0
51+
52+
RUN ninja install
53+
54+
# Run the make command for pythonmapscript-wheel
55+
# RUN cmake --build . --target pythonmapscript-wheel
56+
57+
FROM gdal AS runner
58+
LABEL maintainer="[email protected]"
59+
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
60+
61+
# Let's copy a few of the settings from /etc/init.d/apache2
62+
ENV APACHE_CONFDIR=/etc/apache2 \
63+
APACHE_ENVVARS=/etc/apache2/envvars \
64+
# And then a few more from $APACHE_CONFDIR/envvars itself
65+
APACHE_RUN_USER=www-data \
66+
APACHE_RUN_GROUP=www-data \
67+
APACHE_RUN_DIR=/tmp/apache2 \
68+
APACHE_PID_FILE=/tmp/apache2/apache2.pid \
69+
APACHE_LOCK_DIR=/var/lock/apache2 \
70+
APACHE_LOG_DIR=/var/log/apache2
71+
# MS_MAP_PATTERN=^\\/etc\\/mapserver\\/([^\\.][-_A-Za-z0-9\\.]+\\/{1})*([-_A-Za-z0-9\\.]+\\.map)$
72+
73+
RUN --mount=type=cache,target=/var/cache,sharing=locked \
74+
--mount=type=cache,target=/root/.cache \
75+
apt-get update \
76+
&& apt-get upgrade --assume-yes \
77+
&& apt-get install --assume-yes --no-install-recommends ca-certificates apache2 libapache2-mod-fcgid \
78+
libfribidi0 librsvg2-2 libpng16-16 libgif7 libfcgi0ldbl \
79+
libxslt1.1 libprotobuf-c1 libaio1t64 libpcre2-posix3 glibc-tools
80+
81+
RUN a2enmod fcgid headers status \
82+
&& a2dismod -f auth_basic authn_file authn_core authz_user autoindex dir \
83+
&& rm /etc/apache2/mods-enabled/alias.conf \
84+
&& mkdir --mode=go+w --parent ${APACHE_RUN_DIR} ${APACHE_LOCK_DIR} \
85+
&& mkdir --parent /etc/mapserver \
86+
&& chmod o+w /var/lib/apache2/fcgid /var/lib/apache2/fcgid/sock \
87+
&& find "$APACHE_CONFDIR" -type f -exec sed -ri ' \
88+
s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
89+
s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
90+
' '{}' ';' \
91+
&& sed -ri 's!LogFormat "(.*)" combined!LogFormat "%{us}T %{X-Request-Id}i \1" combined!g' /etc/apache2/apache2.conf \
92+
&& echo 'ErrorLogFormat "%{X-Request-Id}i [%l] [pid %P] %M"' >> /etc/apache2/apache2.conf \
93+
&& sed -i -e 's/<VirtualHost \*:80>/<VirtualHost *:8080>/' /etc/apache2/sites-available/000-default.conf \
94+
&& sed -i -e 's/Listen 80$/Listen 8080/' /etc/apache2/ports.conf \
95+
&& rm -rf /etc/apache2/conf-enabled/other-vhosts-access-log.conf
96+
97+
# Create a writable directory for MapServer temporary data
98+
RUN mkdir -p /tmp/mapserver-data && \
99+
chown www-data:www-data /tmp/mapserver-data && \
100+
chmod 755 /tmp/mapserver-data
101+
102+
EXPOSE 8080
103+
104+
COPY --from=builder /usr/local/bin /usr/local/bin/
105+
COPY --from=builder /usr/local/lib /usr/local/lib/
106+
COPY --from=builder /usr/local/share/mapserver /usr/local/share/mapserver/
107+
COPY --from=builder /src/share/ogcapi/templates/html-bootstrap4 /usr/local/share/mapserver/ogcapi/templates/html-bootstrap4/
108+
109+
COPY runtime /
110+
111+
RUN ldconfig
112+
113+
ENV MS_DEBUGLEVEL=0 \
114+
MS_ERRORFILE=stderr \
115+
MAPSERVER_CONFIG_FILE=/usr/local/share/mapserver/config/index.conf \
116+
MAPSERVER_BASE_PATH= \
117+
MAX_REQUESTS_PER_PROCESS=1000 \
118+
MIN_PROCESSES=1 \
119+
MAX_PROCESSES=5 \
120+
BUSY_TIMEOUT=300 \
121+
IDLE_TIMEOUT=300 \
122+
IO_TIMEOUT=40 \
123+
APACHE_LIMIT_REQUEST_LINE=8190 \
124+
GET_ENV=env \
125+
SERVER=apache
126+
127+
CMD ["/usr/local/bin/start-server"]
128+
129+
VOLUME /tmp
130+
131+
WORKDIR /etc/mapserver

docker/ReadMe.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Creating the Docker Image
2+
3+
```
4+
start "C:\Program Files\Docker\Docker\Docker Desktop.exe"
5+
cd C:\GitHub\getting-started-with-mapserver\docker
6+
7+
docker build `
8+
--tag "mapserver-workshop" `
9+
--target=runner `
10+
--build-arg=MAPSERVER_BRANCH=main `
11+
--build-arg=MAPSERVER_REPO=https://github.com/mapserver/mapserver `
12+
.
13+
14+
docker run -it --name mapserver-workshop -p 8080:8080 mapserver-workshop
15+
16+
docker tag mapserver-workshop geographika/mapserver-workshop
17+
18+
docker login
19+
# geographika
20+
# docker images
21+
docker push geographika/mapserver-workshop
22+
```
23+
24+
## Testing
25+
26+
```
27+
docker start mapserver-workshop
28+
docker exec -it mapserver-workshop bash
29+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Mapserver has memory leaks, this limit should improve long term memory usage
2+
FcgidMaxRequestsPerProcess ${MAX_REQUESTS_PER_PROCESS}
3+
FcgidMinProcessesPerClass ${MIN_PROCESSES}
4+
FcgidMaxProcessesPerClass ${MAX_PROCESSES}
5+
FcgidBusyTimeout ${BUSY_TIMEOUT}
6+
FcgidIdleTimeout ${IDLE_TIMEOUT}
7+
FcgidIOTimeout ${IO_TIMEOUT}
8+
LimitRequestLine ${APACHE_LIMIT_REQUEST_LINE}
9+
FcgidProcessTableFile /tmp/fcgid_shm
10+
FcgidIPCDir /tmp/mod_fcgid
11+
12+
ScriptAliasMatch "^${MAPSERVER_BASE_PATH}/(.*)" /usr/local/bin/mapserv_wrapper/$1
13+
ScriptAliasMatch "^${MAPSERVER_BASE_PATH}" /usr/local/bin/mapserv_wrapper
14+
<LocationMatch "^/.*">
15+
# Enable CORS (required for WFS requests)
16+
Header set Access-Control-Allow-Origin "*"
17+
Header set Cache-Control "max-age=0, must-revalidate, no-cache, no-store"
18+
19+
SetHandler fcgid-script
20+
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
21+
Require all granted
22+
Include /tmp/pass-env
23+
# Digital Ocean does not seem to pass this header back
24+
# even though HTTP_X_FORWARDED_HOST is
25+
# SetEnv HTTP_X_FORWARDED_PORT 443
26+
RequestHeader set X-Forwarded-Port "443"
27+
</LocationMatch>
28+
29+
ExtendedStatus On
30+
31+
# Remove below for production
32+
<Location "/server-status-remote">
33+
SetHandler server-status
34+
</Location>
35+
36+
ServerName localhost
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash -a
2+
3+
# Add the environment variables that were set when apache was started
4+
# shellcheck source=/dev/null
5+
source /tmp/init_env
6+
7+
# GDAL uses CWD to write temporary files. So we better be in a location writable by www-data.
8+
cd /tmp || exit 1
9+
10+
if [[ "${MAPSERVER_CATCH_SEGV}" == 1 ]]; then
11+
exec catchsegv /usr/local/bin/mapserv "$@"
12+
else
13+
exec /usr/local/bin/mapserv "$@"
14+
fi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash -e
2+
3+
echo "Starting with apache2"
4+
5+
# save the environment to be able to restore it in the FCGI daemon (used
6+
# in /usr/local/bin/qgis_mapsev_wrapper) for the startup code.
7+
${GET_ENV} | sed -e 's/^\([^=]*\)=.*/PassEnv \1/' > /tmp/pass-env
8+
9+
# Save the environment to be able to restore it in the FCGI daemon (used in /usr/local/bin/mapserv_wrapper)
10+
${GET_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init_env
11+
12+
#if [[ "${UID}" == 0 ]]; then
13+
# echo "Switching listen port to 80"
14+
# cd /tmp
15+
# sed -i -e 's/<VirtualHost \*:8080>/<VirtualHost *:80>/' /etc/apache2/sites-available/000-default.conf
16+
# sed -i -e 's/Listen 8080$/Listen 80/' /etc/apache2/ports.conf
17+
#fi
18+
19+
trap '' WINCH
20+
21+
rm -f "${APACHE_PID_FILE}"
22+
23+
exec apache2 -DFOREGROUND

0 commit comments

Comments
 (0)