Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feat/add dev compose #48

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0b6e40d
Merge pull request #15 from PnX-SI/develop
camillemonchicourt Sep 19, 2023
6d82f28
Merge pull request #19 from PnX-SI/develop
camillemonchicourt Sep 28, 2023
a268d1e
Merge pull request #21 from PnX-SI/develop
camillemonchicourt Oct 18, 2023
a24a896
Merge pull request #22 from PnX-SI/develop
camillemonchicourt Oct 18, 2023
23f0461
Merge pull request #24 from PnX-SI/develop
camillemonchicourt Dec 15, 2023
55cc8e9
Merge branch 'develop'
jacquesfize Feb 29, 2024
adf988a
Merge remote-tracking branch 'origin/develop'
jacquesfize May 3, 2024
3149c0d
Merge remote-tracking branch 'origin/develop'
jacquesfize Jun 3, 2024
91caef0
Merge remote-tracking branch 'origin/develop'
jacquesfize Dec 16, 2024
d8d8738
Merge remote-tracking branch 'origin/develop'
jacquesfize Dec 16, 2024
89d58ef
[WIP] Working on integrating a developpement mode to the project. For…
Christophe-Ramet Jan 10, 2025
78cef23
Précisions changelog 2.15
camillemonchicourt Dec 20, 2024
3543de7
Giving a default argument silence a warning
Christophe-Ramet Jan 10, 2025
dc395e9
Changed handling of env var to be able to launch dev with docker comp…
Christophe-Ramet Jan 13, 2025
c0ca1b5
[WIP] Build.sh is no longer needed. All builds directive were added t…
Christophe-Ramet Jan 14, 2025
8f47ff4
[WIP] Deleted duplicate docker file. Create a dev target in dockerfile
Christophe-Ramet Jan 14, 2025
a676d88
Simplification du Makefile et update du Readme
Christophe-Ramet Jan 14, 2025
fcf3fce
[WIP] Added module to debug mode (export, dashboard and monitoring)
Christophe-Ramet Jan 15, 2025
44acddd
Added traefik to dev services
Christophe-Ramet Jan 17, 2025
80a0e90
Ajout du frontend au docker compose. Pour l'instant, le mode de fonct…
Christophe-Ramet Jan 24, 2025
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
9 changes: 9 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ 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
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SHELL := /bin/bash

launch: submodule_init
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

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

prod:
COMPOSE_FILE=docker-compose.yml docker compose up -d
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ 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`. Selon vos préférences, si la commande
a déjà été lancé une fois, vous pouvez ensuite simplement lancer un `docker compose up`. Le premier lancement peut mettre quelques
dizaines de minutes.

Vous pouvez visiter votre géonature à l'adresse https://localhost/geonature et le proxy traefik http://localhost:8080/.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


(Pour l'instant, pour que le frontend fonctionne, il faut aussi modifier le fichier
`sources/GeoNature/frontend/angular.json`. C'est fait de manière transparente dans le make dev.)

### 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-local:latest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nécessaire ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne pas remplir cette ligne créait des warnings au moment du build chez moi (quelque chose du genre Attention si cette variable n'est pas remplie l'image est invalide).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On peut utiliser un ARG ?


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
9 changes: 9 additions & 0 deletions build/Dockerfile-geonature-frontend
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ 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
RUN npm install
EXPOSE 4443
CMD ["npm", "run", "start", "--", "--host", "0.0.0.0", "--port", "4443"]
ENTRYPOINT []


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
19 changes: 19 additions & 0 deletions build/dev/Dockerfile-geonature-backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG GEONATURE_BACKEND_IMAGE="ghcr.io/pnx-si/geonature-backend-local:latest"
Christophe-Ramet marked this conversation as resolved.
Show resolved Hide resolved


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

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]
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
98 changes: 98 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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

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


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
command: npm run start -- --host 0.0.0.0 --port 4443
build:
context: .
dockerfile: build/Dockerfile-geonature-frontend
target: dev-extra
args:
GEONATURE_FRONTEND_IMAGE: ${GEONATURE_FRONTEND_IMAGE}
volumes:
- ./sources/GeoNature/frontend:/build

# TODO rendre optionel la partie peuplement de la BDD
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- Avant d'effectuer la mise à jour de GeoNature, installer l'extension `ltree` dans le container `postgres` :
`docker compose exec postgres psql -U [user_postgres] -d [nom_db_geonature] -f /docker-entrypoint-initdb.d/add-extensions.sql`
- Avec cette nouvelle version, les médias de TaxHub se trouvent dans le dossier `media` de GeoNature. Si vous mettez à jour votre GeoNature, déplacer les médias de TaxHub de l'ancien dossier (`GeoNature-Docker-services/data/taxhub/medias`) vers le nouveau (`GeoNature-Docker-services/data/geonature/media/taxhub`) :
`cp -r data/taxhub/medias/* data/geonature/media/taxhub`
- La suppression du container TaxHub implique une modification du docker-compose, n'oubliez pas de récupérer les modifications de ce dernier ([Voir documentation](https://github.com/PnX-SI/GeoNature-Docker-services?tab=readme-ov-file#mettre-%C3%A0-jour-geonature-et-ses-modules))

## 2.14.2 (2024-06-03)
Expand Down
10 changes: 1 addition & 9 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,7 @@ docker image inspect ghcr.io/pnx-si/geonature-backend-extra --format '{{json .Co

- Initialiser et cloner les sous-modules git :
```bash
git submodule init
git submodule update
```
- Faire de même pour les sous-modules de GeoNature et UsersHub, exemple pour GeoNature :
```bash
cd sources/GeoNature
git submodule init
git submodule update
cd ../..
make submodule_init
```
- Apporter vos éventuelles modifications au code source.
- Il est conseillé de renommer les images dans le fichier `.env` afin de ne pas rentrer en conflit avec les images officielles, par exemple en leur rajoutant un suffix `-local` :
Expand Down