Skip to content

Mapserver Installation

Grace Amondi edited this page May 10, 2021 · 3 revisions

Mukau Mapserver Repository builds an image of PostgreSQL/PostGIS and Mapserver. The Mukau system uses Mapserver as the main GIS engine for connecting to the database and rendering the layers for consumption by the frontend webmap in WMS standards. The OSGEO Mapserver instance connects to database and process the layers for visualization by use of mapfiles.

This componets brings in the ability to separate Mapserver to its own docker container, since it can live independently from the Mukau wagtail CMS. The MapViewer will need to be configured to point to the new dockerized Mapserver instance.

This section describes the installation steps for the Mukau Mapserver component as a standalone. It also describes the steps inorder to push any changes made to the Mukau entrypoint.

Required Software

In order to install Mukau Mapserver, the following softwares need to be installed first:

Mukau requires docker in order to function. Follow these instructions to install docker on Windows, and these instructions to install docker on Mac OS. If you are running Linux, follow the instructions on this page that are appropriate for the Linux distribution you are using.

Mukau Mapserver

Table of Contents

Introduction

Mukau Mapserver Repository builds an image of PostgreSQL/PostGIS and Mapserver. The Mukau system uses Mapserver as the main GIS engine for connecting to the database and rendering the layers for consumption by the frontend webmap in WMS standards. The OSGEO Mapserver instance connects to database and process the layers for visualization by use of mapfiles.

This componets brings in the ability to separate Mapserver to its own docker container, since it can live independently from the Mukau wagtail CMS. The MapViewer will need to be configured to point to the new dockerized Mapserver instance.

Installation

1. Clone the Repository

git clone https://github.com/icpac-igad/mukau-mapserver.git

2. Create .env file

To create a .env file at the root of the project execute:

cp .env.sample .env

The .env file expects the following Environment Variables:

Variable Description
POSTGRES_DB_MS The mukau database name
POSTGRES_USER_MS
POSTGRES_PASSWORD_MS password for the postgres user
POSTGRES_PORT_MS
GIS_USER gis
GIS_USER_PASS password for the gis user
MAP_USER mapuser
MAP_USER_PASS password for the map user
MAPSERVER_PORT port mukua mapserver will be running on
MAPSERVER_IMAGE_URI The mapserver production image to use. This should be the URI to the image on a local or remote private registry, with the version tag e.g localhost:5000/mukau-mapserver:1.0

You can view the available tags for mukau-mapserver image at https://eahazardswatch.icpac.net/v2/mukau-mapserver/tags/list. This requires authentication.

3. Database container Setup - mukau_mapserver_db

This is the container that runs the mukau postgresql database. This container does not need a Dockerfile since it uses the official postgis/postgis:12-master image that already has Postgresql + Postgis installed. All the files required by this container will be inside the /database directory.

A sql folder needs to be created inside the /database/initdb/ folder. This directory will contain a list of scripts and sql files to initialize the mukau database with users and data.

These files must be downloaded (https://edo.jrc.ec.europa.eu/documents/mukau/pgsql_data.tar) and copied into this sql/ folder like so:

  • gis_tables
  • map_tables

Inside the folder /database/initdb/ there are two scripts as described below:

  • 01.init.sh - Which will create the necessary database users and privileges
  • 02.database_data_population.sh - Which will populate the database using the sql files in the /database/initdb/sql folder

4. Executable file

To make the database init file execute as a program, run:

chmod +x /database/initdb/01.init.sh

5. Build Docker Image

To build the docker image, run:

sudo docker-compose build

6. Start Docker Compose (in the background)

sudo docker-compose up -d

The application should now be available at http:127.0.0.1:<MAPSERVER_PORT> . The <MAPSERVER_PORT> config is specified in the .env file.


Deploy Latest Development (Local) updates to Staging/Production

1. Update .env (MUKAU-MAPSERVER)

Change the MAPSERVER_IMAGE_URI tag version in the .env file to a higher version. The convension used is that version numbers ending in an odd number (for example 1.1) are development versions, while versions ending in an even number (for example (1.2) are release versions.

For example, set this variable in the production .env:

MAPSERVER_IMAGE_URI=localhost:5000/mukau-mapserver:1.0

2. Build Docker Image

To build the docker image, run:

sudo docker-compose build

3. Push New Image to private registry

Mirror local tag (MUKAU-GEOCMS) with the remote tag(MUKAU-DOCKER).

sudo docker tag <local_tag> <remote_tag>

For example:

sudo docker tag localhost:5000/mukau-mapserver:1.0 eahazardswatch.icpac.net/mukau-mapserver:1.0 

Next, login to the eahazardswatch.icpac.net registry, execute the command below and provide appropriate credentials.

sudo docker login eahazardswatch.icpac.net

Push the new image to the private registry, run:

sudo docker push <remote_tag>

For example,

sudo docker push eahazardswatch.icpac.net/mukau-mapserver:1.0 

Other commands

Monitor logs

To view the status of the database, run:

sudo docker logs mukau_mapserver_db -f

To view the status of the mapserver app, run:

sudo docker logs mapserver -f

Making Updates

To update the application, for example after changing the MAPSERVER_IMAGE_URI variable in .env file just run again:

sudo docker-compose stop

then

sudo docker-compose up

Stop and Clean Docker

To stop and remove everything including volumes run (reset). NOTE: This will result in lose of any data save to the database

sudo docker-compose down --volumes

Access database on cmd

docker exec -it <DB_CONTAINER> psql -U <DB_USER> <DB_NAME> 

Backup postgres table

sudo docker exec -it <DB_CONTAINER> pg_dump -U <DB_USER> -t <DB_TABLE> <DB_NAME> > 'path_to_ouput.sql'

Backup postgres database

docker exec -t <DB_CONTAINER> pg_dumpall -c -U <DB_USER> | gzip > ./tmp/dump_$(date +"%Y-%m-%d_%H_%M_%S").gz

Restore database backups

gunzip < your_dump.sql.gz | docker exec -i <DB_CONTAINER> psql -U <DB_USER> -d <DB_NAME>

Access Docker Containers

Access to the running container (mukau-mapserver or any container name, the one defined in docker-compose.yml)

docker exec -it <CONTAINER> bash

Clone this wiki locally