Skip to content
Snippets Groups Projects
Commit 488f7b43 authored by Benoît Courty's avatar Benoît Courty
Browse files

Merge branch 'deploy-prod' into 'main'

Ajoute le job de CI deploy-prod

See merge request !19
parents a13c33a3 fbb431da
No related branches found
No related tags found
1 merge request!19Ajoute le job de CI deploy-prod
Pipeline #21512 passed
......@@ -4,7 +4,7 @@
# possible values: https://docs.python.org/3/library/logging.html#logging-levels
LOGGING_LEVEL=INFO
ORIGINS=[https://leximpact.an.fr, http://localhost:5173, http://localhost:8000, http://localhost]
ORIGINS=[http://localhost:5173, http://127.0.0.1:5173, http://dotations.leximpact.an.fr]
DATA_DIRECTORY="./data"
......
......@@ -22,6 +22,8 @@ cache:
# run script before each job's script
before_script:
# Initialise le .env
- cp .env.example .env
# install poetry (and collapse section)
- echo -e "\e[0Ksection_start:`date +%s`:poetry_install_section[collapsed=true]\r\e[0KInstalling poetry..."
- pip download --dest=${PIP_DOWNLOAD_DIR} poetry # STEP 1
......@@ -147,3 +149,37 @@ deploy-integ:
# defined in: https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/environments
name: integration
when: manual
deploy-prod:
# SSH_PRIVATE_KEY and PRODUCTION_IP defined in:
# https://git.leximpact.dev/groups/leximpact/simulateur-dotations-communes/-/settings/ci_cd
# PRODUCTION_HOST_DOMAIN_NAME defined in:
# https://git.leximpact.dev/groups/leximpact/-/settings/ci_cd
stage: deploy
before_script:
# install git to have ssh-agent and ssh-add
- apt update && apt install -y git curl
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# check that we are in a container (inside Proxmox LXC container) before bypassing StrictHostKeyChecking
- '[[ -f /.dockerenv ]] && mkdir -p ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\tLogLevel quiet\n" > ~/.ssh/config'
script:
# remove previous wheel on integration server and execute the new wheel
- ssh -J gitlabci@$PRODUCTION_HOST_DOMAIN_NAME leximpact@$PRODUCTION_IP "cd $CI_PROJECT_NAME && rm -v dist/* && exit"
- scp -o "ProxyCommand ssh gitlabci@$PRODUCTION_HOST_DOMAIN_NAME nc -w 1 %h 22" -r dist/ leximpact@$PRODUCTION_IP:$CI_PROJECT_NAME/
# add the current .env configuration to the container (overwrite it if it already exists)
- scp -o "ProxyCommand ssh gitlabci@$PRODUCTION_HOST_DOMAIN_NAME nc -w 1 %h 22" .env leximpact@$PRODUCTION_IP:$CI_PROJECT_NAME/.env
# add the current CSV data files to the container (overwrite them if they already exist)
- scp -o "ProxyCommand ssh gitlabci@$PRODUCTION_HOST_DOMAIN_NAME nc -w 1 %h 22" data/*csv leximpact@$PRODUCTION_IP:$CI_PROJECT_NAME/data/
# get launch_api.py and deploy.sh on container (on SSH port 22)
- ssh -J gitlabci@$PRODUCTION_HOST_DOMAIN_NAME leximpact@$PRODUCTION_IP "mkdir -p $CI_PROJECT_NAME/.gitlab/ci/ && exit"
- scp -o "ProxyCommand ssh gitlabci@$PRODUCTION_HOST_DOMAIN_NAME nc -w 1 %h 22" .gitlab/ci/launch_api.py leximpact@$PRODUCTION_IP:$CI_PROJECT_NAME/.gitlab/ci/launch_api.py
- scp -o "ProxyCommand ssh gitlabci@$PRODUCTION_HOST_DOMAIN_NAME nc -w 1 %h 22" .gitlab/ci/deploy.sh leximpact@$PRODUCTION_IP:$CI_PROJECT_NAME/.gitlab/ci/deploy.sh
# use a ssh relay to connect to the host containing the runner allowed to access the artifacts (wheel)
- ssh -J gitlabci@$PRODUCTION_HOST_DOMAIN_NAME leximpact@$PRODUCTION_IP "cd $CI_PROJECT_NAME && bash .gitlab/ci/deploy.sh && exit"
environment:
# defined in: https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/environments
name: production
when: manual
only:
- main
# CHANGELOG
### 4.2.2 [!19](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/19)
* Met en place un `.env.example` pour la configuration de l'environnement par défaut. Cela permet de ne pas avoir de fichier `.env` sur le dépôt.
### 4.2.1 [!20](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/20)
* Correction d'un crash. Optimisation.
......
......@@ -19,13 +19,23 @@ poetry env use python3.11
## Installer `leximpact-dotations-back`
Initialiser la configuration en copiant le modèle de fichier `.env` :
```shell
# dans le répertoire racine du dépôt
# (celui où se trouve ce fichier README.md)
cp .env.example .env
```
Vérifier que la version de Python associée à Poetry est bien la version attendue :
```shell
poetry run python --version
# résultat attendu : Python 3.11.x
```
Pour installer les dépendances de ce dépôt, exécuter la commande suivante dans un terminal Shell :
```shell
poetry install
```
......
[tool.poetry]
name = "leximpact-dotations-back"
version = "4.2.1"
version = "4.2.2"
description = "Simulating annual State grants to the French administrative divisions"
authors = ["LexImpact <leximpact@assemblee-nationale.fr>"]
license = "AGPL-3.0-or-later"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment