Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pymviewer"]
path = pymviewer
url = https://github.com/jdev-org/pymviewer.git
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "/home/user/git/mviewerstudio/src/app.py",
"FLASK_APP": "/home/gaetan/projects/mviewer/mviewerstudio/src/app.py",
"FLASK_DEBUG": "1",
"CONF_PATH_FROM_MVIEWER":"apps/store",
"EXPORT_CONF_FOLDER":"/home/gaetan/projects/mviewer/mviewer/apps/store/",
"MVIEWERSTUDIO_PUBLISH_PATH":"/home/gaetan/projects/mviewer/mviewer/apps/public",
"CONF_PUBLISH_PATH_FROM_MVIEWER":"apps/public",
"DEFAULT_ORG":"geobretagne",
"QGS_FOLDER":"/home/gaetan/projects/qgis/compo-jm/volumes/qgis-srv",
"QGIS_SERVER_INTERNAL_URL": "http://localhost:90/ogc"

},
"args": [
Expand Down
19 changes: 18 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ services:
build:
context: .
dockerfile: docker/Dockerfile
network: host
args:
UID: "${UID:-1000}"
GID: "${GID:-1000}"
pull_policy: build
image: mviewer/mviewerstudio:latest
image: mviewer/mviewerstudio:qgis
user: "${UID:-1000}:${GID:-1000}"
# ports:
# - "8000:8000"
environment:
Expand All @@ -16,9 +21,21 @@ services:
- EXPORT_CONF_FOLDER=/home/mvuser/apps/store
- MVIEWERSTUDIO_PUBLISH_PATH=/home/mvuser/apps/public
- MVIEWERSTUDIO_URL_PATH_PREFIX=mviewerstudio
- QGS_FOLDER=/home/mvuser/qgis
- QGIS_SERVER_INTERNAL_URL=http://qgis-server/ogc/
volumes:
- "./apps:/home/mvuser/apps"
- "./qgis:/home/mvuser/qgis"
- "./src/static/config.json:/home/mvuser/src/static/config.json"
# QGIS Server exposed on localhost:90 to match src/static/config.json
qgis-server:
profiles:
- qgis
image: qgis/qgis-server:latest
ports:
- "90:80"
volumes:
- "./qgis:/io/data"
# Served under /mviewer/ see docker/nginx/default.conf.template
mviewer:
depends_on:
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ENV EXPORT_CONF_FOLDER=/home/mvuser/apps/store \
MVIEWERSTUDIO_PUBLISH_PATH=/home/mvuser/apps/public \
CONF_PUBLISH_PATH_FROM_MVIEWER=apps/public \
DEFAULT_ORG=public \
MVIEWERSTUDIO_URL_PATH_PREFIX=mviewerstudio
MVIEWERSTUDIO_URL_PATH_PREFIX=mviewerstudio \
QGS_FOLDER=/home/mvuser/qgis

CMD ["gunicorn", "-w 1", "-b 0.0.0.0:8000", "src.app:app"]
195 changes: 176 additions & 19 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,188 @@
# mviewerstudio Dockerfile
# Docker

## Image
Only python Dockerfile will be maintained (PHP backend is fully deprecated).
## Objectif

## Environment variables
Cette composition Docker lance :

- EXPORT_CONF_FOLDER is the "staging" folder where studio will store draft configs and work in progress
- CONF_PATH_FROM_MVIEWER is the url path given to mviewer to access the same map files
- MVIEWERSTUDIO_PUBLISH_PATH is the "production" folder where studio will copy the map files when you ask to *Publish*
- CONF_PUBLISH_PATH_FROM_MVIEWER is the url path given to mviewer to access the same map files
- MVIEWERSTUDIO_URL_PATH_PREFIX allows to serve studio on a non-root path, see [#271](https://github.com/mviewer/mviewerstudio/pull/271)
- `mviewerstudio` : backend Flask/Gunicorn ;
- `mviewer` : frontend mviewer ;
- `www` : reverse-proxy Nginx exposé sur `http://localhost/` ;
- `qgis-server` : service optionnel, activé via le profil Compose `qgis`.

## Default configuration
Par défaut :

The default configuration (env vars defined in the dockerfile and json config file present in `src/static/config.json`) assume that:
- the mviewer _apps_ folder is mounted at EXPORT_CONF_FOLDER=/home/apprunner/apps
- /home/apprunner/apps/store and /home/apprunner/apps/prod are existing folders (you might need to create them manually beforehand)
- it is using `src/static/config.json`, which you will probably want to adapt to your own environment.
- Studio est accessible sur `http://localhost/mviewerstudio/`
- mviewer est accessible sur `http://localhost/mviewer/`
- QGIS Server est proxifié sur `http://localhost/ogc/`
- le conteneur QGIS Server direct est aussi exposé sur `http://localhost:90/`

## Pré-requis

It is also configured to serve the frontend (static files) with gunicorn, which is usually not recommended. Later versions might use an nginx container to serve the frontend.
- Docker et Docker Compose installés ;
- les dossiers `./apps` et `./qgis` présents dans le dépôt ;
- le dossier `./qgis` doit être accessible en lecture/écriture pour l'utilisateur qui lance Docker Compose.

**Starting with version 4.3, the docker image assumes that the `EXPORT_CONF_FOLDER` directory is writeable for user 1000:1000.**
La composition monte :

## Build mviewerstudio image
- `./apps` dans Studio et mviewer ;
- `./qgis` dans Studio et QGIS Server ;
- `./src/static/config.json` dans le conteneur Studio.

Use docker compose to build image :
## Démarrage complet avec QGIS Server

`docker compose build mviewerstudio`
Commande recommandée pour une première exécution ou après modification du code :

```bash
docker compose --profile qgis up -d --build
```

Cette commande :

- construit l'image locale `mviewerstudio` ;
- démarre `mviewerstudio`, `mviewer`, `www` et `qgis-server` ;
- active les fonctions Studio qui dépendent de QGIS Server.

À utiliser quand :

- vous démarrez la stack pour la première fois ;
- vous avez modifié le backend Python, Nginx ou le `Dockerfile` ;
- vous avez besoin de l'import QGIS, du `GetCapabilities` ou des projets `.qgs`.

## Remise à zéro

Pour arrêter la stack et supprimer aussi les volumes anonymes associés :

```bash
docker compose down -v
```

Cette commande :

- arrête tous les conteneurs de la composition ;
- supprime le réseau Docker créé par Compose ;
- supprime les volumes anonymes créés par les services.

Elle ne supprime pas vos fichiers du dépôt comme `./apps` ou `./qgis`, car ce sont des bind mounts locaux.

## Démarrage simple sans QGIS Server

Pour relancer uniquement Studio, mviewer et Nginx, sans le service QGIS :

```bash
docker compose up -d
```

Cette commande :

- démarre `mviewerstudio`, `mviewer` et `www` ;
- ne démarre pas `qgis-server`, car il est derrière le profil `qgis`.

À utiliser quand :

- vous n’avez pas besoin des fonctions QGIS ;
- vous voulez seulement consulter Studio ou mviewer ;
- vous redémarrez rapidement la stack après un `down`.

## Quand utiliser quelle commande

`docker compose --profile qgis up -d --build`

- pour un démarrage complet ;
- pour reconstruire l'image `mviewerstudio` ;
- pour activer QGIS Server.

`docker compose down -v`

- pour repartir d'un état Docker propre ;
- pour forcer un redémarrage complet de la composition.

`docker compose up -d`

- pour un redémarrage rapide sans QGIS Server ;
- pour relancer les services web principaux après un arrêt.

## Build local ou image déjà publiée

Le service `mviewerstudio` peut fonctionner de deux façons dans `docker-compose.yml`.

### 1. Build local de l'image

C'est le mode actuellement configuré dans ce dépôt.

Extrait actuel :

```yaml
mviewerstudio:
build:
context: .
dockerfile: docker/Dockerfile
network: host
args:
UID: "${UID:-1000}"
GID: "${GID:-1000}"
pull_policy: build
image: mviewer/mviewerstudio:qgis
```

Dans ce mode :

- Docker construit l'image à partir du code local ;
- `image:` sert surtout de tag pour l'image construite ;
- les changements dans le dépôt sont pris en compte après `docker compose up -d --build`.

À utiliser quand :

- vous développez localement ;
- vous modifiez Python, Nginx, le `Dockerfile` ou les dépendances ;
- vous voulez tester l'état exact du dépôt courant.

### 2. Utiliser une image officielle déjà construite

Si vous voulez démarrer depuis une image publiée, il faut retirer la section `build:` et conserver seulement `image:`.

Exemple :

```yaml
mviewerstudio:
image: mviewer/mviewerstudio:latest
user: "${UID:-1000}:${GID:-1000}"
```

Dans ce mode :

- Docker ne reconstruit pas l'image locale ;
- Compose télécharge ou réutilise l'image distante `mviewer/mviewerstudio:latest` ;
- les modifications locales du code Python ne sont pas embarquées dans le conteneur.

À utiliser quand :

- vous voulez tester une image publiée ;
- vous ne souhaitez pas reconstruire l'image localement ;
- vous cherchez un démarrage plus simple sur une version déjà packagée.

### Comment basculer d'un mode à l'autre

Pour passer en mode image officielle dans `docker-compose.yml` :

- supprimer le bloc `build:` du service `mviewerstudio` ;
- supprimer `pull_policy: build` ;
- remplacer la valeur de `image:` par le tag publié que vous voulez utiliser, par exemple `mviewer/mviewerstudio:latest`.

Pour revenir au mode build local :

- remettre le bloc `build:` ;
- remettre `pull_policy: build` ;
- conserver ou ajuster le tag `image:` utilisé pour nommer l'image locale construite.

## URLs utiles

- Studio : `http://localhost/mviewerstudio/`
- mviewer : `http://localhost/mviewer/`
- QGIS Server via Nginx : `http://localhost/ogc/`
- QGIS Server direct : `http://localhost:90/`

## Notes

- Le service `qgis-server` est optionnel. Sans le profil `qgis`, les routes Studio qui dépendent de QGIS Server ne fonctionneront pas.
- La configuration front par défaut est portée par `src/static/config.json`.
- Le reverse-proxy Nginx est défini dans `docker/nginx/default.conf.template`.
11 changes: 10 additions & 1 deletion docker/nginx/default.conf.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
server {
listen 80;
server_name ${NGINX_HOST};
resolver 127.0.0.11 ipv6=off;

location = /mviewer {
return 302 /mviewer/$is_args$args;
}

location /mviewer/ {
proxy_pass http://mviewer/;
proxy_pass http://mviewer:8080/;
}

location /apps/ {
Expand All @@ -26,6 +27,14 @@ server {
#proxy_set_header sec-org "geobretagne";
}

location /ogc/ {
set $qgis_upstream qgis-server:80;
proxy_pass http://$qgis_upstream$request_uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}

location / {
server_name_in_redirect off;
return 302 /${MVIEWERSTUDIO_URL_PATH_PREFIX}/;
Expand Down
2 changes: 1 addition & 1 deletion install/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ lxml>=4.9.2
GitPython>=3
requests
Unidecode
git+https://github.com/jdev-org/pymviewer.git#egg=pymviewer
pymviewer
1 change: 1 addition & 0 deletions pymviewer
Submodule pymviewer added at b3c043
Loading
Loading