Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Feb 25, 2025
2 parents 4baaf7e + f47a0c3 commit 7eb5fc9
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 29 deletions.
20 changes: 17 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,35 @@ POSTGRES_USER="geonatadmin"
POSTGRES_PASSWORD="geonatpasswd"
POSTGRES_HOST="postgres"
POSTGRES_DB="geonature2db"
POSTGRES_PORT=5432
POSTGRES_PORT_ON_HOST=5432

USERSHUB_IMAGE="ghcr.io/pnx-si/usershub:latest"

USERSHUB_IMAGE="ghcr.io/pnx-si/usershub:2.4.4"
USERSHUB_PROTOCOL="${BASE_PROTOCOL}"
USERSHUB_HOST="${HOST}"
USERSHUB_HOSTPORT="${HOSTPORT}"
USERSHUB_PREFIX="/usershub"

GEONATURE_BACKEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-backend-extra:latest"
GEONATURE_BACKEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-backend-extra:2.15.4"
GEONATURE_BACKEND_PROTOCOL="${BASE_PROTOCOL}"
GEONATURE_BACKEND_HOST="${HOST}"
GEONATURE_BACKEND_HOSTPORT="${HOSTPORT}"
GEONATURE_BACKEND_PREFIX="/geonature/api"

GEONATURE_FRONTEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-frontend-extra:latest"
GEONATURE_FRONTEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-frontend-extra:2.15.4"
GEONATURE_FRONTEND_PROTOCOL="${BASE_PROTOCOL}"
GEONATURE_FRONTEND_HOST="${HOST}"
GEONATURE_FRONTEND_HOSTPORT="${HOSTPORT}"
GEONATURE_FRONTEND_PREFIX="/geonature"

### DEV CONFIGS Uncomment if you want to use in dev mode
# USERSHUB_IMAGE="ghcr.io/pnx-si/usershub-local:latest"
# GEONATURE_BACKEND_IMAGE="ghcr.io/pnx-si/geonature-backend-local:latest"
# GEONATURE_BACKEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-backend-extra-local:latest"
# GEONATURE_FRONTEND_IMAGE="ghcr.io/pnx-si/geonature-frontend-local:latest"
# GEONATURE_FRONTEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-frontend-extra-local:latest"
# COMPOSE_FILE=docker-compose.yml:docker-compose-dev.yml

# Should be set to false for first launch but can be set to true afterward to gain time.
# SKIP_POPULATE_DB=false
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: GEONATURE_BACKEND_IMAGE=ghcr.io/pnx-si/geonature-backend:2.15.3
build-args: GEONATURE_BACKEND_IMAGE=ghcr.io/pnx-si/geonature-backend:2.15.4

frontend:
name: Build geonature frontend docker image
Expand Down Expand Up @@ -94,4 +94,4 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: GEONATURE_FRONTEND_IMAGE=ghcr.io/pnx-si/geonature-frontend:2.15.3
build-args: GEONATURE_FRONTEND_IMAGE=ghcr.io/pnx-si/geonature-frontend:2.15.4
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SHELL := /bin/bash

launch:
docker compose up -d

dev_init:
jq '.projects.geonature.architect.build.configurations.development += {"baseHref": "/geonature/"}' sources/GeoNature/frontend/angular.json > angular.json.tmp && mv angular.json.tmp sources/GeoNature/frontend/angular.json # Pas une super pratique mais pas d'autre solution pour le moment
source .env; echo "{\"API_ENDPOINT\":\"//localhost$${GEONATURE_BACKEND_PREFIX}\"}" > sources/GeoNature/frontend/src/assets/config.json

submodule_init:
git submodule update --init --recursive

build:
build/build.sh

dev: dev_init
COMPOSE_FILE=docker-compose.yml:docker-compose-dev.yml docker compose up -d --force-recreate
source .env; echo "Services de developpement lancés, vous pouvez y acceder sur : https://$${HOST}$${GEONATURE_FRONTEND_PREFIX}"

prod:
./init-config.sh
COMPOSE_FILE=docker-compose.yml docker compose up -d
source .env; echo "Services de production lancés, vous pouvez y acceder sur : https://$${HOST}$${GEONATURE_FRONTEND_PREFIX}"
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ Ces variables d’environnement doivent être renseignées directement dans le f
- Vérifiez si la [dernière version disponible](https://github.com/PnX-SI/GeoNature-Docker-services/releases) correspond aux versions des applications que vous souhaitez mettre à jour
- Placez vous dans le dossier `GeoNature-Docker-services` de votre serveur
- Mettez à jour le contenu du dossier dans sa dernière version : `git pull`
- Changez la version de GeoNature dans les variables `GEONATURE_BACKEND_EXTRA_IMAGE`, `GEONATURE_FRONTEND_EXTRA_IMAGE`, et de UsersHub dans `USERSHUB_IMAGE` dans votre fichier `.env`. Par exemple, pour passer de la version 2.15.2 à 2.15.3, effectuez les modifications suivantes :

```env
USERSHUB_IMAGE="ghcr.io/pnx-si/usershub:2.4.4"
[...]
GEONATURE_BACKEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-backend-extra:2.15.3"
[...]
GEONATURE_FRONTEND_EXTRA_IMAGE="ghcr.io/pnx-si/geonature-frontend-extra:2.15.3"
```

Pour connaître la version de UsersHub, consultez la note de version.

- Lancez la commande qui va télécharger les dernières versions des différentes applications et les relancer : `docker compose pull && docker compose up -d --remove-orphans`

## FAQ
Expand All @@ -99,6 +112,20 @@ Ces images sont le pendant de [celles publiées sur le dépôt de GeoNature](htt

## Liens utiles

## Lancer une instance de développement

Commencez par vous assurer d'avoir installé make et jq `sudo apt install make jq`.

Il faut ensuite, dans votre fichier .env décommenter les lignes de l'environnement de dev.
Une fois le fichier .env rempli correctement, il faut créer les fichiers de configuration avec `./init-config.sh`.

Une fois cela fait, il ne vous reste plus qu'à lancer `make submodule_init` suivit de `make dev`.
Il est déconseillé de lancer avec la commande `docker compose up -d` car si vous mettez à jour le projet GeoNature,
cela ne fonctionnera pas sans relancer `make dev_init`.
Le premier lancement peut mettre quelques dizaines de minutes.

Vous pouvez visiter votre GeoNature à l'adresse https://localhost/geonature et le proxy traefik http://localhost:8080/.

### GeoNature

- [Dépôt](https://github.com/PnX-SI/GeoNature)
Expand Down
8 changes: 5 additions & 3 deletions build/Dockerfile-geonature-backend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GEONATURE_BACKEND_IMAGE
ARG GEONATURE_BACKEND_IMAGE="ghcr.io/pnx-si/geonature-backend:latest"

FROM python:3.11-bookworm AS build

Expand All @@ -22,15 +22,17 @@ WORKDIR /build/
COPY ./sources/gn_module_monitoring .
RUN python setup.py bdist_wheel

FROM ${GEONATURE_BACKEND_IMAGE}-wheels AS prod-extra

FROM ${GEONATURE_BACKEND_IMAGE}-wheels AS base_env
WORKDIR /dist/geonature
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt-get update && apt-get install -y libproj-dev proj-bin
COPY --from=build-export /build/dist/*.whl .
COPY --from=build-dashboard /build/dist/*.whl .
COPY --from=build-monitoring /build/dist/*.whl .


FROM base_env AS prod-extra
RUN --mount=type=cache,target=/root/.cache \
pip install *.whl sentry_sdk[flask]
RUN rm -f *.whl
8 changes: 8 additions & 0 deletions build/Dockerfile-geonature-frontend
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ COPY ./sources/gn_module_monitoring/frontend/ .
RUN --mount=type=cache,target=/root/.npm \
npm ci --omit=dev --omit=peer

FROM source-extra as dev-extra
WORKDIR /build
RUN npm link @angular/cli
COPY ./build/dev/frontend_entrypoint.sh /entrypoint.sh
ENTRYPOINT /entrypoint.sh
RUN npm install
EXPOSE 4443

FROM source-extra AS build-extra

WORKDIR /build/
Expand Down
14 changes: 7 additions & 7 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash

set -x
set -x
set -o nounset

# todo delete this file ? Unless we want people to be able to build without launching compose
# Buildkit by default since 2023, we don't need to specify it no more ? Same thing with compose that use it by default
# now
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1

source .env

# GN BACKEND WHEELS
docker build -f sources/GeoNature/backend/Dockerfile -t ${GEONATURE_BACKEND_IMAGE}-wheels --target=wheels sources/GeoNature/

# GN BACKEND EXTRA
docker build \
--build-arg GEONATURE_BACKEND_IMAGE=${GEONATURE_BACKEND_IMAGE} \
-f ./build/Dockerfile-geonature-backend \
-t ${GEONATURE_BACKEND_EXTRA_IMAGE} .
--build-arg GEONATURE_BACKEND_IMAGE=${GEONATURE_BACKEND_IMAGE} \
-f ./build/Dockerfile-geonature-backend \
-t ${GEONATURE_BACKEND_EXTRA_IMAGE} .

# GN FRONTEND SOURCE
docker build -f sources/GeoNature/frontend/Dockerfile -t ${GEONATURE_FRONTEND_IMAGE}-source --target=source sources/GeoNature/
Expand Down
20 changes: 20 additions & 0 deletions build/dev/Dockerfile-geonature-backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG GEONATURE_BACKEND_IMAGE="ghcr.io/pnx-si/geonature-backend-local:latest"


FROM ${GEONATURE_BACKEND_IMAGE}-wheels AS base_env
WORKDIR /dist/geonature

RUN rm -f geonature-*
COPY --chown=${UID}:${GUID} /sources/GeoNature /sources/GeoNature
COPY --chown=${UID}:${GUID} /sources/gn_module_export /sources/gn_module_export
COPY --chown=${UID}:${GUID} /sources/gn_module_dashboard /sources/gn_module_dashboard
COPY --chown=${UID}:${GUID} /sources/gn_module_monitoring /sources/gn_module_monitoring
RUN --mount=type=cache,target=/root/.cache \
pip install *.whl sentry_sdk[flask] \
# Delete when those dependency will be added to requirements-dev
RUN pip install watchdog pytest pytest-flask pytest-benchmark pip-tools
RUN cd /sources/GeoNature/backend
RUN pip install -r requirements-dev.txt
RUN --mount=type=cache,target=/root/.cache \
pip install -e /sources/GeoNature -e /sources/gn_module_export -e /sources/gn_module_dashboard -e /sources/gn_module_monitoring \
RUN rm -f *.whl
13 changes: 13 additions & 0 deletions build/dev/frontend_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
npm install

# We need to install external modules dependencies
if [ -d "external_modules" ]; then
for dir in external_modules/*; do
if [ -d "$dir" ]; then
echo "Installation of dependencies $dir"
(cd "$dir" && npm install)
fi
done
fi
npm run start -- --host 0.0.0.0 --port 4443
108 changes: 108 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
services:

#------------------------------------Builds section start-----------------------------------#
base-backend:
image: ${GEONATURE_BACKEND_IMAGE}-wheels
build:
context: sources/GeoNature
dockerfile: backend/Dockerfile
target: wheels
entrypoint: /bin/bash -c exit

base-frontend-source:
image: ${GEONATURE_FRONTEND_IMAGE}-source
build:
context: sources/GeoNature
dockerfile: frontend/Dockerfile
target: source
entrypoint: /bin/bash -c exit

base-frontend-nginx:
image: ${GEONATURE_FRONTEND_IMAGE}-nginx
build:
context: sources/GeoNature
dockerfile: frontend/Dockerfile
target: prod-base
entrypoint: /bin/sh -c exit

userhub-build:
image: ${USERSHUB_IMAGE}
build:
target: prod
context: sources/UsersHub
volumes:
- ./config/usershub:/dist/config/
entrypoint: /bin/sh -c exit
#------------------------------------Builds section end------------------------------------#
geonature-install-db:
depends_on:
base-backend:
condition: service_completed_successfully
build:
dockerfile: build/dev/Dockerfile-geonature-backend
volumes:
- ./sources/GeoNature:/sources/GeoNature

geonature-backend:
depends_on:
base-backend:
condition: service_completed_successfully
volumes:
- ./sources/GeoNature:/sources/GeoNature
- ./sources/gn_module_export:/sources/gn_module_export
- ./sources/gn_module_dashboard:/sources/gn_module_dashboard
- ./sources/gn_module_monitoring:/sources/gn_module_monitoring
build:
dockerfile: build/dev/Dockerfile-geonature-backend

geonature-worker:
depends_on:
base-backend:
condition: service_completed_successfully
volumes:
- ./sources/GeoNature:/sources/GeoNature
- ./sources/gn_module_export:/sources/gn_module_export
- ./sources/gn_module_dashboard:/sources/gn_module_dashboard
- ./sources/gn_module_monitoring:/sources/gn_module_monitoring
build:
dockerfile: build/dev/Dockerfile-geonature-backend
command: watchmedo auto-restart --directory=/sources/GeoNature --pattern=*.py --recursive -- celery -A geonature.celery_app:app worker --beat --schedule-filename=/dist/media/celerybeat-schedule.db

postgres:
ports:
- "${POSTGRES_PORT_ON_HOST:-5432}:${POSTGRES_PORT:-5432}"

traefik:
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entryPoints.web.address=:80"
- "--entryPoints.web.http.redirections.entrypoint.to=:${HTTPS_PORT}"
- "--entryPoints.web.http.redirections.entrypoint.scheme=https"
- "--entryPoints.websecure.address=:443"
- "--certificatesResolvers.acme-resolver.acme.email=${ACME_EMAIL}"
- "--certificatesResolvers.acme-resolver.acme.storage=/etc/traefik/certs/acme.json"
- "--certificatesResolvers.acme-resolver.acme.tlsChallenge=true"
ports:
- "8080:8080"

geonature-frontend:
depends_on:
base-frontend-source:
condition: service_completed_successfully
build:
context: .
dockerfile: build/Dockerfile-geonature-frontend
target: dev-extra
args:
GEONATURE_FRONTEND_IMAGE: ${GEONATURE_FRONTEND_IMAGE}
volumes:
- ./sources/GeoNature/frontend:/build
- ./sources/gn_module_dashboard/frontend:/build/external_modules/dashboard
- ./sources/gn_module_export/frontend:/build/external_modules/export
- ./sources/gn_module_monitoring/frontend:/build/external_modules/monitorings
- ./sources/GeoNature/contrib/gn_module_occhab/frontend:/build/external_modules/occhab
- ./sources/GeoNature/contrib/occtax/frontend:/build/external_modules/occtax
- ./sources/GeoNature/contrib/gn_module_validation/frontend:/build/external_modules/validation
- ./build/dev/frontend_entrypoint.sh:/entrypoint.sh
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.9"

x-restart-policy: &restart-policy
restart: ${RESTART_POLICY:-unless-stopped}

Expand Down Expand Up @@ -52,7 +50,7 @@ services:
- "--certificatesResolvers.acme-resolver.acme.storage=/etc/traefik/certs/acme.json"
- "--certificatesResolvers.acme-resolver.acme.tlsChallenge=true"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/run/docker.sock:/var/run/docker.sock
- ./config/traefik:/etc/traefik/dynamic
- ./data/traefik/certs:/etc/traefik/certs
ports:
Expand All @@ -77,7 +75,7 @@ services:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
PGPORT: ${POSTGRES_PORT:-5432}
volumes:
- ./assets/postgres/initdb:/docker-entrypoint-initdb.d/
- postgres:/var/lib/postgresql/data
Expand Down Expand Up @@ -136,6 +134,7 @@ services:
install_ref_sensitivity: ${GEONATURE_DB_INSTALL_REF_SENSITIVITY:-true}
usershub: ${GEONATURE_DB_INSTALL_USERSHUB:-true}
usershub_samples: ${GEONATURE_DB_INSTALL_USERSHUB_SAMPLES:-true}
GEONATURE_SKIP_POPULATE_DB: ${SKIP_POPULATE_DB:-false}

geonature-worker:
<<: [*restart-policy, *geonature-backend-defaults]
Expand Down
Loading

0 comments on commit 7eb5fc9

Please sign in to comment.