Skip to content

Commit

Permalink
Group deployment files in a single folder
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentAntoine committed Apr 11, 2024
1 parent cc0f6af commit 32f3462
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 26 deletions.
19 changes: 7 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ dev-run-data-warehouse:
git clone --depth=1 --branch=main https://github.com/MTES-MCT/monitorenv.git ./forklift/tests/test_data/external/monitorenv || echo "Monitorenv repository already present - skipping git clone" && \
export DATA_WAREHOUSE_PASSWORD=password && \
export DATA_WAREHOUSE_USER=clickhouse_user && \
docker compose -f ./infra/data_warehouse/docker-compose.yml -f ./infra/data_warehouse/docker-compose-test-data.yml up -d --remove-orphans
docker compose -f ./infra/deployment/docker-compose.yml -f ./infra/testing/docker-compose-test-data.yml up -d --remove-orphans

dev-run-metabase:
docker compose -f ./infra/data_warehouse/docker-compose-dev-metabase.yml up -d && \
docker compose -f ./infra/testing/docker-compose-dev-metabase.yml up -d && \
docker cp ./infra/metabase_plugins/clickhouse.metabase-driver.jar metabase:/plugins && \
docker restart metabase

dev-stop-data-warehouse:
docker compose -f ./infra/data_warehouse/docker-compose.yml -f ./infra/data_warehouse/docker-compose-test-data.yml down
export DATA_WAREHOUSE_PASSWORD=password && \
export DATA_WAREHOUSE_USER=clickhouse_user && \
docker compose -f ./infra/deployment/docker-compose.yml -f ./infra/testing/docker-compose-test-data.yml down

dev-stop-metabase:
docker compose -f ./infra/data_warehouse/docker-compose-dev-metabase.yml down
docker compose -f ./infra/testing/docker-compose-dev-metabase.yml down

dev-erase-data-warehouse-databases:
docker volume rm data_warehouse_data-warehouse-db data_warehouse_data-warehouse-logs data_warehouse_monitorfish-db-data data_warehouse_monitorenv-db-data || exit 0
Expand All @@ -31,17 +33,10 @@ docker-run-data-warehouse:
git clone --depth=1 --branch=main https://github.com/MTES-MCT/monitorenv.git ./forklift/tests/test_data/external/monitorenv || echo "Monitorenv repository already present - skipping git clone" && \
export DATA_WAREHOUSE_PASSWORD=password && \
export DATA_WAREHOUSE_USER=clickhouse_user && \
docker compose -f ./infra/data_warehouse/docker-compose.yml -f ./infra/data_warehouse/docker-compose-test-data.yml up -d --remove-orphans
docker compose -f ./infra/deployment/docker-compose.yml -f ./infra/testing/docker-compose-test-data.yml up -d --remove-orphans
docker-test-forklift: docker-run-data-warehouse
docker run --network host -v /var/run/docker.sock:/var/run/docker.sock -u forklift:$(DOCKER_GROUP) --env-file forklift/.env.test forklift:$(VERSION) coverage run -m pytest --pdb tests
docker-tag-forklift:
docker tag forklift:$(VERSION) ghcr.io/mtes-mct/fisheries-and-environment-data-warehouse/forklift:$(VERSION)
docker-push-forklift:
docker push ghcr.io/mtes-mct/fisheries-and-environment-data-warehouse/forklift:$(VERSION)

# RUN commands
run-datawarehouse:
docker compose -f ./infra/data_warehouse/docker-compose.yml up -d
register-forklift-flows:
docker pull ghcr.io/mtes-mct/fisheries-and-environment-data-warehouse/forklift:$(FORKLIFT_VERSION) && \
infra/forklift/register-flows.sh
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions infra/deployment/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run-datawarehouse:
docker compose -f ./docker-compose.yml up -d
register-forklift-flows:
docker pull ghcr.io/mtes-mct/fisheries-and-environment-data-warehouse/forklift:$(FORKLIFT_VERSION) && \
./register-flows.sh
46 changes: 46 additions & 0 deletions infra/deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Data Warehouse Deployment
### 1. Purpose and Architecture

This Data Warehouse is meant to collect data from Monitorfish, Monitorenv and Rapportnav V2 applications and provide
a centralized database for statistical analysis through data querying and visualization tools such as Metabase.

It is composed of 2 dockerized services :
- a Clickhouse database
- a set of python data flows orchestrated by Prefect, named `Forklift`

### 2. Deployment
#### 2.1. Prerequisites

- Install docker : https://docs.docker.com/engine/install/debian/#install-using-the-repository
- Install GNU make if not already installed :
`sudo apt-get update`
`sudo apt-get install make`
- Install pyenv : https://github.com/pyenv/pyenv-installer
- Install python : `pyenv install 3.12.3`
- Copy the contents of the `infra/deployment` folder onto the host machine, in the `~` folder.
- Create a virtual environment in the `~/prefect-agent` folder and install `prefect` in this virtual environment :
- `cd prefect-agent`
- `pyenv local 3.12.3`
- `python -m venv .venv`
- `source .venv/bin/activate`
- `pip install prefect=1.3.0`
- Run `prefect backend server` to switch Prefect into server mode (as opposed to cloud mode, the default). A file `backend.toml` should appear at `~/.prefect/backend.toml` containing `backend = "server"`.
- Define and start a Prefect agent service:
- Fill in the placeholders in `.prefect-agent` and `prefectdockeragent.service`.
- Move `prefectdockeragent.service` into `/etc/systemd/system`.
- Run `sudo systemctl enable prefectdockeragent.service` to enable the service.
- Run `sudo systemctl start prefectdockeragent.service` to start the service.
- Run `systemctl status prefectdockeragent.service` to check the service is running.
- Rename `.env.template` as `.env` and fill in the environement variables : these are the environment variables that will be used by the flow runners, inside the forklift runner containers.

#### 2.2. Running the Data Warehouse

- Update the `DATA_WAREHOUSE_USER` and `DATA_WAREHOUSE_PASSWORD` environment variables in the `.data-warehouse` file.
- Run `source .data-warehouse`.
- Run `make run-datawarehouse`.

#### 2.3. Running or updating `Forklift`

- Update the `FORKLIFT_VERSION` variable in the `.data-warehouse` file.
- Run `source .data-warehouse`.
- Run `make register-forklift-flows`.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
db:
image: clickhouse/clickhouse-server:23.11.4.24
Expand Down
1 change: 1 addition & 0 deletions infra/deployment/prefect-agent/.prefect-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PREFECT_SERVER_URL=
1 change: 1 addition & 0 deletions infra/deployment/prefect-agent/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.3
13 changes: 13 additions & 0 deletions infra/deployment/prefect-agent/prefectdockeragent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Prefect Docker Agent

[Service]
Type=simple

User=<USER-TO-CHANGE>
ExecStart=<SCRIPT-LOCATION-TO-CHANGE>/prefectdockeragent.sh
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions infra/deployment/prefect-agent/prefectdockeragent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
source ~/prefect-agent/.venv/bin/activate && \
source ~/prefect-agent/.prefect-agent && \
prefect agent docker start --api "${PREFECT_SERVER_URL}" --label forklift;
11 changes: 11 additions & 0 deletions infra/deployment/register-flows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

docker run -t --rm --network=host --name forklift-register-flows \
-v /opt2/sacrois-data:/opt2/sacrois-data \
-v "$(pwd)"/.env:/home/forklift/data_warehouse/.env \
-v "$(pwd)"/backend.toml:/home/forklift/.prefect/backend.toml \
--env-file .env \
-e FORKLIFT_VERSION \
-e SACROIS_FILES_GID \
ghcr.io/mtes-mct/fisheries-and-environment-data-warehouse/forklift:$FORKLIFT_VERSION \
python forklift/main.py
11 changes: 0 additions & 11 deletions infra/forklift/register-flows.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:

metabase-db:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:

monitorfish-db:
Expand Down

0 comments on commit 32f3462

Please sign in to comment.