-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added db seed service to import data inside db with docker-compose lo…
…cal deployment
- Loading branch information
1 parent
43abf67
commit 38ca0ee
Showing
10 changed files
with
98 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
# Plateforme Base Adresse Nationale | ||
# Plateforme de la Base Adresse Nationale | ||
|
||
Ce dépôt regroupe l'essentiel des briques faisant partie de la plateforme Base Adresse Nationale, à savoir : | ||
## Architecture | ||
|
||
- les routines d'import ; | ||
- les routines de consolidation ; | ||
- les routines de production des fichiers ; | ||
- un service "worker" réagissant en temps réel à toute modification. | ||
La BAN Plateforme contient : | ||
- Une API synchrone et asynchrone : serveur Express (point d'entrée : server.js). | ||
L'API asynchrone envoit des tâches dans la queue du redis, pris en charge par le worker. | ||
- Un worker (point d'entrée : worker.js) qui récupère les tâches du redis. | ||
- Des scripts (imports, consolidation, exports). | ||
|
||
## Installer un environnement de développement | ||
La BAN Plateforme import et export des données d'une base MongoDB. | ||
|
||
### Pré-requis | ||
|
||
- Node.js 16 ou supérieur | ||
- MongoDB 4 ou supérieur | ||
- Redis | ||
- yarn ou npm | ||
## Installation | ||
|
||
### Configuration | ||
Pour mettre en place un environnement fonctionnel, vous pouvez partir du fichier .env.sample et le copier en le renommant .env. | ||
|
||
Pour mettre en place un environnement fonctionnel, vous pouvez partir du fichier `.env.sample` et le copier en le renommant `.env`. | ||
### Deploiement local avec Docker | ||
|
||
Compte-tenu de la puissance de calcul nécessaire pour effectuer les traitements sur France entière il est conseillé de restreindre à un seul département pour les développements. Par exemple `DEPARTEMENTS=57`. | ||
#### Pré-requis | ||
- Docker | ||
- Docker-compose | ||
|
||
### Installation des dépendances | ||
#### Commandes | ||
Pour déployer l'environnement, lancer la commande suivante : | ||
|
||
```bash | ||
yarn | ||
```sh | ||
docker-compose up --build -d | ||
``` | ||
|
||
### Préparation des contours administratifs | ||
|
||
```bash | ||
yarn prepare-contours | ||
``` | ||
Prepare les contours France entière sans prendre en compte le .env. | ||
--build : permet de builder les images locales. | ||
-d : permet de lancer les conteneurs en arrière plan. | ||
|
||
### Téléchargement des données nécessaires | ||
La commande précédente va déployer une architecture locale, interconnectée, avec : | ||
- un conteneur "db" (image mongo:4.2.23) | ||
- un conteneur "redis" (image redis:4.0.9) | ||
- un conteneur "api" (à partir de l'image définie dans le fichier docker-resources/api/Dockerfile.dev) | ||
- un conteneur "db_seed" (à partir de l'image définie dans le fichier docker-resources/db_seed/Dockerfile.dev) | ||
|
||
```bash | ||
yarn download-datasets | ||
``` | ||
Télécharge fantoir.sqlite, gazetteer.sqlite, communes-locaux-adresses.json. | ||
#### Initialisation de données dans la BDD | ||
|
||
### Import des différentes sources | ||
Pour initialiser des données dans la base MongoDB: | ||
- remplir le dossier docker-resources/db_seed/data-to-init avec des fichiers .json (le nom des fichiers correspondront au nom des collections qui seront importées) | ||
- activer la fonctionnalité d'import en passant la variable d'environnement ACTIVATE_DB_SEED à : | ||
|
||
```bash | ||
yarn import:ign-api-gestion | ||
yarn import:cadastre | ||
yarn import:ftth | ||
```sh | ||
ACTIVATE_DB_SEED = true | ||
``` | ||
Prend en compte le .env pour ne télécharger les données que sur le département concerné. | ||
- les données seront soit ajoutées soit "overridé" selon la valeur de la variable d'environnement | ||
|
||
### Consolidation des adresses | ||
|
||
```bash | ||
yarn compose | ||
```sh | ||
OVERRIDE_DATA_ON_IMPORT = true ##true: données overridées, false: donnée ajoutées | ||
``` | ||
|
||
### Production des fichiers | ||
|
||
```bash | ||
yarn dist | ||
``` | ||
### Deploiement local sans Docker | ||
|
||
## Opérations d’exploitation | ||
#### Pré-requis | ||
- Node.js 16 ou supérieur | ||
- MongoDB 4 ou supérieur | ||
- Redis | ||
- yarn ou npm | ||
|
||
### Appliquer la mise à jour de la liste des communes certifiées d'office | ||
#### Commandes | ||
Pour déployer l'api et le worker, lancer les deux commandes suivantes en parrallèle : | ||
|
||
```bash | ||
yarn apply-batch-certification | ||
```sh | ||
yarn dev | ||
``` | ||
|
||
```sh | ||
yarn worker:dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM mongo:4.2.23 | ||
|
||
COPY docker-resources/db_seed/data-to-init/ ./data-to-init | ||
COPY docker-resources/db_seed/start.dev.sh ./start.dev.sh | ||
CMD ["bash", "start.dev.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[{ | ||
"codeCommune":"12345" | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## This script is used to import data into the database | ||
## It looks into the data-to-init folder and import all the json files | ||
## The name of the collection imported will be the name of the file without the extension | ||
|
||
echo "ACTIVATE_DB_SEED : $ACTIVATE_DB_SEED" | ||
echo "OVERRIDE_DATA_ON_IMPORT : $OVERRIDE_DATA_ON_IMPORT" | ||
|
||
if [[ "$ACTIVATE_DB_SEED" = "true" ]]; then | ||
for file in `ls data-to-init`; do | ||
filename="${file%.*}" | ||
echo "Importing $file data into $filename collection..." | ||
if [[ "$OVERRIDE_DATA_ON_IMPORT" = "true" ]]; then | ||
mongoimport --host db --db $MONGODB_DBNAME --collection $filename --type json --file /data-to-init/$file --jsonArray --drop | ||
else | ||
mongoimport --host db --db $MONGODB_DBNAME --collection $filename --type json --file /data-to-init/$file --jsonArray | ||
fi | ||
|
||
done | ||
fi |