Skip to content

Commit

Permalink
Added Docker-based building and testing method (openstreetmap#363)
Browse files Browse the repository at this point in the history
* Build with Docker
* Use CUSTOM_DEFINES for Mapnik building
* Only run `install-package-and-test.yml` if etc, utils or YAML file have changed
  • Loading branch information
hummeltech authored Dec 31, 2023
1 parent 4e8334e commit 53b77bc
Show file tree
Hide file tree
Showing 25 changed files with 1,372 additions and 18 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*
!cmake
!CMakeLists.txt
!docs/man
!etc/apache2/renderd-example-map.conf
!etc/apache2/tile.load.in
!etc/renderd/renderd.conf.in
!includes
!src
!tests
!utils/example-map
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ runs:
- name: Build `Mapnik`
run: |
# Export variables
export CUSTOM_DEFINES="-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"
export GDAL_DATA=/usr/share/gdal
export JOBS=${JOBS:-$(nproc)}
export PROJ_LIB=/usr/share/proj
Expand All @@ -41,8 +42,12 @@ runs:
# Configure & build
./configure \
CC=${CC:-gcc} \
CXX=${CXX:-g++} \
CC="${CC:-gcc}" \
CUSTOM_CFLAGS="${CUSTOM_CFLAGS:-}" \
CUSTOM_CXXFLAGS="${CUSTOM_CXXFLAGS:-}" \
CUSTOM_DEFINES="${CUSTOM_DEFINES:-}" \
CUSTOM_LDFLAGS="${CUSTOM_LDFLAGS:-}" \
CXX="${CXX:-g++}" \
FAST=True \
OPTIMIZATION=0 \
PREFIX="/usr"
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/docker-image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: Docker Image Build

on:
pull_request:
push:
paths:
- "docker/**"
- ".github/workflows/docker-image-build.yml"

jobs:
docker-image-build:
name: Build & Test (${{ matrix.service-name }})
runs-on: ubuntu-latest
strategy:
matrix:
service-name:
- centos-7
- centos-stream-8
- centos-stream-9
- debian-11
- debian-12
- debian-testing
- fedora-38
- fedora-39
- fedora-rawhide
- opensuse-leap-15
- opensuse-tumbleweed
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-devel
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build & Start
run: docker compose up --build --detach ${{ matrix.service-name }}
working-directory: docker

- name: Test
run: |
until $(curl --fail --output tile.png --silent http://localhost:8081/tiles/renderd-example/9/297/191.png); do
echo 'Sleeping 5s';
sleep 5;
done
echo 'dbf26531286e844a3a9735cdd193598dca78d22f77cafe5824bcaf17f88cbb08 tile.png' | sha256sum --check
timeout-minutes: 1

- name: Show logs
if: failure()
run: docker compose logs
working-directory: docker

- name: Stop
if: success() || failure()
run: docker compose down --volumes
working-directory: docker
2 changes: 1 addition & 1 deletion .github/workflows/flawfinder-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: flawfinder
name: Flawfinder Analysis

on:
pull_request:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/install-package-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
name: Install Package & Test

on:
- push
pull_request:
push:
paths:
- "etc/**"
- "utils/**"
- ".github/workflows/install-package-and-test.yml"

jobs:
install-package-and-test:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ if(EXISTS "/etc/os-release")
elseif(DISTRO_ID MATCHES "freebsd")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/modules.d")
set(TILE_LOAD_FILENAME "080_tile.conf")
elseif(DISTRO_ID MATCHES "opensuse-leap")
elseif(DISTRO_ID MATCHES "opensuse-leap|opensuse-tumbleweed")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/conf.d")
set(TILE_LOAD_FILENAME "mod_tile.conf")
endif()
Expand Down
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=mod_tile
41 changes: 41 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Docker-based building & testing

For your convenience, we have provided a Docker-based building and testing method to help get started with development & testing.

### The following distributions are currently supported:

- centos-7 _(CentOS 7)_ [[Dockerfile](/docker/centos/7/Dockerfile)]
- centos-stream-8 _(CentOS Stream 8)_ [[Dockerfile](/docker/centos/stream/Dockerfile)]
- centos-stream-9 _(CentOS Stream 9)_ [[Dockerfile](/docker/centos/stream/Dockerfile)]
- debian-10 _(Debian 10)_ [[Dockerfile](/docker/debian/Dockerfile)]
- debian-11 _(Debian 11)_ [[Dockerfile](/docker/debian/Dockerfile)]
- debian-12 _(Debian 12)_ [[Dockerfile](/docker/debian/Dockerfile)]
- debian-testing _(Debian Testing)_ [[Dockerfile](/docker/debian/Dockerfile)]
- fedora-34 _(Fedora 34)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-35 _(Fedora 35)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-36 _(Fedora 36)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-37 _(Fedora 37)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-38 _(Fedora 38)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-39 _(Fedora 39)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- fedora-rawhide _(Fedora Rawhide)_ [[Dockerfile](/docker/fedora/Dockerfile)]
- opensuse-leap-15 _(openSUSE Leap 15)_ [[Dockerfile](/docker/opensuse/Dockerfile)]
- opensuse-tumbleweed _(openSUSE Tumbleweed)_ [[Dockerfile](/docker/opensuse/Dockerfile)]
- ubuntu-20.04 _(Ubuntu 20.04)_ [[Dockerfile](/docker/ubuntu/Dockerfile)]
- ubuntu-22.04 _(Ubuntu 22.04)_ [[Dockerfile](/docker/ubuntu/Dockerfile)]
- ubuntu-devel _(Ubuntu Devel)_ [[Dockerfile](/docker/ubuntu/Dockerfile)]

### Requirements:

- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://github.com/docker/compose)

### Usage:

```shell
$ # Use any "{distribution}" value from the list above
$ # I.E. docker-compose up --build ubuntu-devel
$ cd docker
$ docker-compose up --build {distribution}
```

Then you can visit: `http://localhost:8081/renderd-example-map`
173 changes: 173 additions & 0 deletions docker/centos/7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Arguments
ARG mapnik_version=3.1.0

# Mapnik Builder
FROM centos:centos7 as mapnik-builder

## Arguments
ARG mapnik_version

## Install mapnik-builder dependencies
RUN --mount=id=centos:centos7-/var/cache/yum,target=/var/cache/yum,type=cache,sharing=locked \
ulimit -n 40000; \
echo "install_weak_deps=0" >> /etc/yum.conf && \
sed --in-place 's/keepcache=0/keepcache=1/g' /etc/yum.conf && \
yum --assumeyes install epel-release centos-release-scl && \
yum --assumeyes upgrade && \
yum --assumeyes install \
boost169-devel \
bzip2 \
cairo-devel \
freetype-devel \
devtoolset-9-gcc \
devtoolset-9-gcc-c++ \
gdal-devel \
harfbuzz-devel \
libicu-devel \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libwebp-devel \
libxml2-devel \
make \
patch \
postgresql-devel \
proj-devel \
python3 \
sqlite-devel \
tar \
zlib-devel

## Download, Build & Install `Mapnik`
WORKDIR /tmp/mapnik_src
RUN --mount=id=centos:centos7-mapnik:${mapnik_version},target=/tmp/mapnik_src,type=cache \
export DESTDIR="/tmp/mapnik"; \
export GDAL_DATA="$(gdal-config --datadir)"; \
export JOBS="$(nproc)"; \
export PROJ_LIB="/usr/share/proj"; \
export PYTHON="python3"; \
mkdir --parents ${GDAL_DATA} ${PROJ_LIB}; \
if [ ! -f SConstruct ]; then \
curl --silent --location https://github.com/mapnik/mapnik/releases/download/v${mapnik_version}/mapnik-v${mapnik_version}.tar.bz2 \
| tar --extract --bzip2 --strip-components=1 --file=-; \
sed -i 's#BOOST_APPEND = match.groups()\[0\]#BOOST_APPEND = ""#g' SConstruct; \
fi; \
source /opt/rh/devtoolset-9/enable; \
export CUSTOM_DEFINES="-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"; \
export CUSTOM_LDFLAGS="-L/usr/lib64/boost169"; \
bash configure \
CPP_TESTS=False \
CUSTOM_CFLAGS="${CUSTOM_CFLAGS:-}" \
CUSTOM_CXXFLAGS="${CUSTOM_CXXFLAGS:-}" \
CUSTOM_DEFINES="${CUSTOM_DEFINES:-}" \
CUSTOM_LDFLAGS="${CUSTOM_LDFLAGS:-}" \
DEMO=False \
DESTDIR="${DESTDIR}" \
FAST=True \
INPUT_PLUGINS=all \
LIBDIR_SCHEMA=lib64 \
OPTIMIZATION=2 \
PREFIX=/usr \
SVG2PNG=True \
XMLPARSER=libxml2 && \
make PYTHON="${PYTHON}" && \
make install PYTHON="${PYTHON}"

# Builder
FROM centos:centos7 as builder

## Install builder dependencies
RUN --mount=id=centos:centos7-/var/cache/yum,target=/var/cache/yum,type=cache,sharing=locked \
ulimit -n 40000; \
echo "install_weak_deps=0" >> /etc/yum.conf && \
sed --in-place 's/keepcache=0/keepcache=1/g' /etc/yum.conf && \
yum --assumeyes install epel-release && \
yum --assumeyes upgrade && \
yum --assumeyes install \
boost169-devel \
cairo-devel \
cmake3 \
gcc \
gcc-c++ \
gdal \
glib2-devel \
harfbuzz-devel \
httpd-devel \
iniparser-devel \
libcurl-devel \
libicu-devel \
libjpeg \
libmemcached-devel \
librados2-devel \
libtiff \
libwebp \
make \
proj

## Copy files from builder(s)
### Mapnik
COPY --from=mapnik-builder /tmp/mapnik /

## Build, Test & Install `mod_tile`
COPY . /tmp/mod_tile_src
WORKDIR /tmp/mod_tile_build
RUN export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) && \
export CFLAGS="-I/usr/include/boost169" && \
export CXXFLAGS="-I/usr/include/boost169" && \
cmake3 -B . -S /tmp/mod_tile_src \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DENABLE_TESTS:BOOL=ON && \
cmake3 --build .
RUN export DESTDIR=/tmp/mod_tile && \
ctest3 --output-on-failure && \
(cmake3 --install . --prefix /usr --strip || make DESTDIR=${DESTDIR} install/strip) && \
mv /tmp/mod_tile/var/run /tmp/mod_tile/run

# Runner
FROM centos:centos7 as runner

## Install runner dependencies
RUN --mount=id=centos:centos7-/var/cache/yum,target=/var/cache/yum,type=cache,sharing=locked \
ulimit -n 40000; \
echo "install_weak_deps=0" >> /etc/yum.conf && \
sed --in-place 's/keepcache=0/keepcache=1/g' /etc/yum.conf && \
yum --assumeyes install epel-release && \
yum --assumeyes upgrade && \
yum --assumeyes install \
boost169-filesystem \
boost169-program-options \
boost169-regex \
cairo \
gdal \
harfbuzz \
httpd \
iniparser \
libicu \
libmemcached \
librados2 \
libtiff \
libwebp \
proj

## Copy files from builder(s)
### Mapnik
COPY --from=mapnik-builder /tmp/mapnik /
### mod_tile
COPY --from=builder /tmp/mod_tile /
COPY --chown=apache:apache --from=builder \
/tmp/mod_tile_src/utils/example-map \
/usr/share/renderd/example-map
COPY --from=builder \
/tmp/mod_tile_src/etc/apache2/renderd-example-map.conf \
/etc/httpd/conf.d/renderd-example-map.conf

## Add configuration
RUN printf '\n[example-map]\nURI=/tiles/renderd-example\nXML=/usr/share/renderd/example-map/mapnik.xml\n' >> /etc/renderd.conf
RUN printf '\n[example-map-jpg]\nTYPE=jpg image/jpeg jpeg\nURI=/tiles/renderd-example-jpg\nXML=/usr/share/renderd/example-map/mapnik.xml\n' >> /etc/renderd.conf
RUN printf '\n[example-map-png256]\nTYPE=png image/png png256\nURI=/tiles/renderd-example-png256\nXML=/usr/share/renderd/example-map/mapnik.xml\n' >> /etc/renderd.conf
RUN printf '\n[example-map-png32]\nTYPE=png image/png png32\nURI=/tiles/renderd-example-png32\nXML=/usr/share/renderd/example-map/mapnik.xml\n' >> /etc/renderd.conf
RUN printf '\n[example-map-webp]\nTYPE=webp image/webp webp\nURI=/tiles/renderd-example-webp\nXML=/usr/share/renderd/example-map/mapnik.xml\n' >> /etc/renderd.conf

## Start services
CMD httpd -e debug -k start; \
G_MESSAGES_DEBUG=${G_MESSAGES_DEBUG:-info} renderd --foreground
Loading

0 comments on commit 53b77bc

Please sign in to comment.