Skip to content

Commit

Permalink
[tests] docker stack to test modules
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentj committed Nov 10, 2022
1 parent a2597e7 commit 969a82b
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ Il est possible que l'intégration ne soit pas optimale, mais cela devrait tout

## Cas de l'utilisation à partir d'une base de données

Pour utiliser ce module en vous connectant à votre base de données, vous devrez disposer d'une base avec une table raster de type MNT. Vous devrez également ajouter au fichier `profiles.ini.php` (situé dans `lizmap/var/config`) le bloc ci-dessous :
Pour utiliser ce module en vous connectant à votre base de données, vous devrez disposer d'une base avec une table raster de type MNT.
Vous devrez également ajouter au fichier `profiles.ini.php` (situé dans `lizmap/var/config`) le bloc ci-dessous :

```ini
[jdb:altiProfil]
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{
"name": "Michaël DOUCHIN",
"email": "[email protected]"
},
{
"name": "Laurent Jouanneau",
"email": "[email protected]"
}
],
"require": {
Expand Down
4 changes: 4 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
lizmap/www/
lizmap/var/
lizmap/qgis-server-plugins
93 changes: 93 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
SHELL = bash
.ONESHELL:
.PHONY: env
#

LIZMAP_DIR=$(shell pwd)/lizmap

LIZMAP_USER_ID:=$(shell id -u)
LIZMAP_USER_GID:=$(shell id -g)

LIZMAP_VERSION_TAG:=3.5
QGIS_VERSION_TAG:=3.22
POSTGIS_VERSION_TAG:=13-3

QGIS_MAP_WORKERS:=1

LIZMAP_PORT:=127.0.0.1:9012
OWS_PORT:=127.0.0.1:9013
LZMPGPORT:=127.0.0.1:9014

BASEDIR:=$(shell realpath ..)

PGMETADATA_MODULE_SRC:=$(shell realpath ..)

main:
@cat <<- EOF
Commandes:
run: initialise environnement and run stack
stop: stop docker and remove containers
clean: reset containers and remove lizmap configuration

Note: Un fichier d'environment pour docker compose
est crée à chaque invocation de 'run'.
Cela permet d'utiliser les commandes 'docker compose'
sans passer par le Makefile
EOF

dirs:
@mkdir -p $(LIZMAP_DIR)/var/log/nginx \
$(LIZMAP_DIR)/var/nginx-cache \
$(LIZMAP_DIR)/qgis-server-plugins \
$*

env: dirs
@cat <<- EOF > .env
COMPOSE_PROJECT_NAME=altiprofil
LIZMAP_DIR=$(LIZMAP_DIR)
LIZMAP_USER_ID=$(LIZMAP_USER_ID)
LIZMAP_USER_GID=$(LIZMAP_USER_GID)
QGIS_MAP_WORKERS=$(QGIS_MAP_WORKERS)
LIZMAP_PORT=$(LIZMAP_PORT)
OWS_PORT=$(OWS_PORT)
LZMPGPORT=$(LZMPGPORT)
PGMETADATA_MODULE_SRC=$(PGMETADATA_MODULE_SRC)
LIZMAP_VERSION_TAG=$(LIZMAP_VERSION_TAG)
QGIS_VERSION_TAG=$(QGIS_VERSION_TAG)
POSTGIS_VERSION_TAG=$(POSTGIS_VERSION_TAG)
EOF

run: stop env install-plugins
docker compose up

stop:
docker compose down || true

clean: stop
docker compose down -v
rm -rf $(LIZMAP_DIR)/www/*
rm -rf $(LIZMAP_DIR)/var/*

# Pull images from github 3liz
pull:
docker pull 3liz/lizmap-web-client:${LIZMAP_VERSION_TAG}
docker pull 3liz/qgis-map-server:${QGIS_VERSION_TAG}
docker pull 3liz/postgis:${POSTGIS_VERSION_TAG}

shell:
docker compose exec -u ${LIZMAP_USER_ID} lizmap /bin/sh -l

install-module:
docker compose exec -u ${LIZMAP_USER_ID} lizmap php /www/lizmap/install/configurator.php altiProfil
docker compose exec -u ${LIZMAP_USER_ID} lizmap php /www/lizmap/install/configurator.php altiProfilAdmin
docker compose exec -u ${LIZMAP_USER_ID} lizmap php /www/lizmap/install/installer.php -v

install-plugins:
docker run \
-u $(LIZMAP_USER_ID):$(LIZMAP_USER_GID) \
--rm -it \
-e QGSRV_SERVER_PLUGINPATH=/srv/plugins \
-v $(LIZMAP_DIR)/qgis-server-plugins:/srv/plugins \
-v $(shell pwd)/:/src \
--entrypoint /src/add-server-plugins.sh \
3liz/qgis-map-server:${QGIS_VERSION_TAG}
49 changes: 49 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Run Lizmap stack with docker compose

Steps:

- Launch Lizmap with docker compose
```
# Clean previous versions (optional)
make clean
# Run the different services
make run
```
- If you run Lizmap 3.6+, install the altiProfil modules with
```
make install-module
```
- Open your browser at `http://localhost:9012`
For more information, refer to the [docker compose documentation](https://docs.docker.com/compose/)
## Access to the dockerized PostgreSQL instance
You can access the docker PostgreSQL test database `lizmap` from your host by configuring a
[service file](https://docs.qgis.org/latest/en/docs/user_manual/managing_data_source/opening_data.html#postgresql-service-connection-file).
The service file can be stored in your user home `~/.pg_service.conf` and should contain this section
```ini
[lizmap-altiprofil]
dbname=lizmap
host=localhost
port=9097
user=lizmap
password=lizmap1234!
```

Then you can use any PostgreSQL client (psql, QGIS, PgAdmin, DBeaver) and use the `service`
instead of the other credentials (host, port, database name, user and password).

```bash
psql service=lizmap-altiprofil
```

## Access to the lizmap container

If you want to enter into the lizmap container to execute some commands,
execute `make shell`.
5 changes: 5 additions & 0 deletions tests/add-server-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

qgis-plugin-manager init
qgis-plugin-manager update
qgis-plugin-manager install "Lizmap server"
74 changes: 74 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3'
services:
pgsql:
image: 3liz/postgis:${POSTGIS_VERSION_TAG}
environment:
POSTGRES_PASSWORD: lizmap1234!
volumes:
- postgis-volume:/var/lib/postgresql/data
- ${LIZMAP_DIR}/initdb.d:/docker-entrypoint-initdb.d
ports:
- ${LZMPGPORT}:5432
lizmap:
image: 3liz/lizmap-web-client:${LIZMAP_VERSION_TAG}
environment:
LIZMAP_CACHEREDISDB: '1'
LIZMAP_CACHEREDISHOST: redis
LIZMAP_CACHESTORAGETYPE: redis
LIZMAP_HOME: /srv/lizmap
LIZMAP_USER: ${LIZMAP_USER_ID}
LIZMAP_WMSSERVERURL: http://map:8080/ows/
LIZMAP_CONFIG_INCLUDE: /srv/etc/conf
PGSERVICEFILE: /srv/etc/pg_service.conf
PGPASSFILE: /srv/etc/pgpass.conf
volumes:
- ${LIZMAP_DIR}/instances:/srv/projects
- ${LIZMAP_DIR}/var/lizmap-theme-config:/www/lizmap/var/lizmap-theme-config
- ${LIZMAP_DIR}/var/lizmap-config:/www/lizmap/var/config
- ${LIZMAP_DIR}/var/lizmap-db:/www/lizmap/var/db
- ${LIZMAP_DIR}/www:/www/lizmap/www
- ${LIZMAP_DIR}/var/lizmap-log:/www/lizmap/var/log
- ${LIZMAP_DIR}/var/lizmap-temp:/www/temp/lizmap/
- ${LIZMAP_DIR}/etc:/srv/etc:ro
- ${PGMETADATA_MODULE_SRC}/altiProfil:/www/lizmap/lizmap-modules/altiProfil
- ${PGMETADATA_MODULE_SRC}/altiProfilAdmin:/www/lizmap/lizmap-modules/altiProfilAdmin
command:
- php-fpm
depends_on:
- pgsql
map:
image: 3liz/qgis-map-server:${QGIS_VERSION_TAG}
command: qgisserver -c /srv/etc/py-qgis-server.conf
environment:
QGSRV_CACHE_ROOTDIR: /srv/projects
QGSRV_CACHE_SIZE: '20'
QGSRV_LOGGING_LEVEL: DEBUG
QGSRV_USER: ${LIZMAP_USER_ID}:${LIZMAP_USER_GID}
QGSRV_SERVER_WORKERS: ${QGIS_MAP_WORKERS}
QGSRV_SERVER_PLUGINPATH: /srv/plugins
PGSERVICEFILE: /srv/etc/pg_service.conf
PGSPASSFILE: /srv/etc/pgpass.conf
QGIS_SERVER_LIZMAP_REVEAL_SETTINGS: 'yes'
volumes:
- ${LIZMAP_DIR}/instances:/srv/projects
- ${LIZMAP_DIR}/etc:/srv/etc:ro
- ${LIZMAP_DIR}/qgis-server-plugins:/srv/plugins
ports:
- ${OWS_PORT}:8080
restart: unless-stopped
redis:
image: redis:5-alpine
web:
image: nginx:1
user: ${LIZMAP_USER_ID}:${LIZMAP_USER_ID}
volumes:
- ${LIZMAP_DIR}/etc/nginx.conf:/etc/nginx/nginx.conf
- ${LIZMAP_DIR}/var/log/nginx:/var/log/nginx
- ${LIZMAP_DIR}/var/nginx-cache:/var/cache/nginx
- ${LIZMAP_DIR}:/srv/lizmap
ports:
- ${LIZMAP_PORT}:8080
depends_on:
- lizmap
volumes:
postgis-volume:
7 changes: 7 additions & 0 deletions tests/lizmap/etc/conf/lizmapconfig.d/lizmapConfig.ini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[services]
lizmapPluginAPIURL="http://map:8080/lizmap/"

[repository:altiprofil]
label=altiprofil
path="/srv/projects/altiprofil/"
allowUserDefinedThemes=1
16 changes: 16 additions & 0 deletions tests/lizmap/etc/conf/localconfig.d/localconfig.ini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[modules]
altiProfil.access=2
altiProfilAdmin.access=2

[jResponseHtml]
plugins = debugbar


[simple_urlengine_entrypoints]
admin="jacl2db~*@classic,jacl2db_admin~*@classic,jauthdb_admin~*@classic,master_admin~*@classic,admin~*@classic,jcommunity~*@classic,altiProfilAdmin~*@classic"

[mailer]
webmasterEmail="[email protected]"
webmasterName="Lizmap Docker"
mailerType=file

13 changes: 13 additions & 0 deletions tests/lizmap/etc/conf/profiles.d/profile.ini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;[jdb]
;default=jauth
;jacl2_profile=jauth
;lizlog=jauth

;[jdb:jauth]
;driver=pgsql
;host=pgsql
;port=5432
;database=lizmap
;user=lizmap
;password="lizmap1234!"
;search_path=public
61 changes: 61 additions & 0 deletions tests/lizmap/etc/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#user www-data;
worker_processes 4;

error_log /var/log/nginx/error.log warn;
pid /var/log/nginx/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;

keepalive_timeout 65;

gzip on;

server {
listen 8080;

server_name lizmap;

root /srv/lizmap/www;
index index.html index.php;

access_log /var/log/nginx/lizmap_access.log;
error_log /var/log/nginx/lizmap_error.log;

# URI resolved to web sub directory
# and found a index.php file here
location ~* /(\w+/)?\w+\.php {

fastcgi_split_path_info ^(.+\.php)(/.+)$;
set $path_info $fastcgi_path_info; # because of bug http://trac.nginx.org/nginx/ticket/321

try_files $fastcgi_script_name =404;
include fastcgi_params;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_param PATH_INFO $path_info;
fastcgi_param PATH_TRANSLATED $document_root$path_info;
fastcgi_pass lizmap:9000;
}
}
}
19 changes: 19 additions & 0 deletions tests/lizmap/etc/pg_service.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Connection configuration file
#
# A service is a set of named connection parameters. You may specify
# multiple services in this file. Each starts with a service name in
# brackets. Subsequent lines have connection configuration parameters of
# the pattern "param=value" or LDAP URLs starting with "ldap://"
# to look up such parameters. A sample configuration for postgres is
# included in this file. Lines beginning with '#' are comments.
#
# Copy this to /etc/postgresql-common/ (or select its location with the
# PGSYSCONFDIR environment variable) and rename it pg_service.conf.
#

[lizmap-altiprofil]
dbname=lizmap
host=pgsql
user=lizmap
password=lizmap1234!
5 changes: 5 additions & 0 deletions tests/lizmap/etc/py-qgis-server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[api.endpoints]
lizmap_api=/lizmap

[api.enabled]
lizmap_api=yes
10 changes: 10 additions & 0 deletions tests/lizmap/initdb.d/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

psql --username postgres --no-password <<-EOSQL
CREATE ROLE lizmap WITH LOGIN CREATEDB PASSWORD 'lizmap1234!';
CREATE DATABASE lizmap WITH OWNER lizmap;
EOSQL

psql --username postgres --no-password -d lizmap <<-EOSQL
CREATE EXTENSION IF NOT EXISTS postgis SCHEMA public;
EOSQL
Empty file.

0 comments on commit 969a82b

Please sign in to comment.