From d04e67e195eb6d1ddd60d48a59197b38f16ca189 Mon Sep 17 00:00:00 2001 From: romainm13 Date: Thu, 22 Feb 2024 23:15:18 +0100 Subject: [PATCH] fixing dev environment with docker --- .env.template | 4 +++- Makefile | 2 +- Trawlwatcher.py | 8 +++++--- alembic/init_script/load_amp_data.py | 8 +++++++- alembic/init_script/load_positions_data.py | 4 +++- bloom/config.py | 10 ++++++---- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.env.template b/.env.template index 7a12de36..594989c5 100644 --- a/.env.template +++ b/.env.template @@ -1,8 +1,10 @@ # these values are used in the local docker env. You can use "localhost" hostname if you run the application without docker +POSTGRES_HOSTNAME=postgres_bloom +POSTGRES_HOSTNAME_OUTSIDE_WHEN_DOCKER=localhost # when using docker, the hostname is mapped to the outside world POSTGRES_USER=bloom_user POSTGRES_PASSWORD=bloom -POSTGRES_HOSTNAME=postgres POSTGRES_DB=bloom_db POSTGRES_PORT=5432 +POSTGRES_PORT_OUTSIDE_WHEN_DOCKER=5480 # when using docker, the port is mapped to the outside world != 5432 SPIRE_TOKEN= SLACK_URL= diff --git a/Makefile b/Makefile index 696176fb..3fb92bbe 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ build: launch-dev-db: @docker compose -f docker-env/docker-compose-db.yaml up -d - @sleep 10 + @sleep 20 $(BLOOM_DEV_DOCKER) --rm d4g/bloom:${VERSION} alembic upgrade head $(BLOOM_DEV_DOCKER) --rm d4g/bloom:${VERSION} /venv/bin/python3 alembic/init_script/load_vessels_data.py diff --git a/Trawlwatcher.py b/Trawlwatcher.py index 4bc7ea19..49976328 100644 --- a/Trawlwatcher.py +++ b/Trawlwatcher.py @@ -9,15 +9,17 @@ layout="wide", ) -load_dotenv() - +# FILL IN YOUR CREDENTIALS .env file HERE !! +env_path = Path('.') / '.env.template' +if not env_path.is_file(): + raise FileNotFoundError(f"Couldn't find .env file at {env_path.absolute()}") +load_dotenv(env_path) def local_css(file_name: str) -> None: with Path.open(file_name) as f: st.markdown(f"", unsafe_allow_html=True) return - local_css(Path("styles.css")) st.write("![](https://upload.wikimedia.org/wikipedia/fr/e/e8/Logo_BLOOM.jpg)") diff --git a/alembic/init_script/load_amp_data.py b/alembic/init_script/load_amp_data.py index 532fcd64..4512b43f 100644 --- a/alembic/init_script/load_amp_data.py +++ b/alembic/init_script/load_amp_data.py @@ -1,5 +1,6 @@ import logging import os +from pathlib import Path import geopandas as gpd import pandas as pd @@ -29,9 +30,14 @@ + "/" + postgres_db ) + engine = create_engine(db_url, echo=False) -df = pd.read_csv("zones_subset_02022024.csv") +df = pd.read_csv( + Path.joinpath(Path.cwd(), "data/zones_subset_02022024.csv"), + sep=",", +) + df = df.rename(columns={"Geometry": "geometry", "Index": "index", "Wdpaid": "WDPAID", "Name": "name", diff --git a/alembic/init_script/load_positions_data.py b/alembic/init_script/load_positions_data.py index 9a1e2a9f..35d371a8 100644 --- a/alembic/init_script/load_positions_data.py +++ b/alembic/init_script/load_positions_data.py @@ -27,9 +27,11 @@ + "/" + postgres_db ) + engine = create_engine(db_url) + df = pd.read_csv( - Path.joinpath(Path.cwd(), "spire_positions_subset_02022024.csv"), + Path.joinpath(Path.cwd(), "data/spire_positions_subset_02022024.csv"), sep="," ) diff --git a/bloom/config.py b/bloom/config.py index aabd8e1a..3b98fcfe 100644 --- a/bloom/config.py +++ b/bloom/config.py @@ -2,13 +2,16 @@ from pydantic import BaseSettings - class Settings(BaseSettings): postgres_user = os.environ.get("POSTGRES_USER") postgres_password = os.environ.get("POSTGRES_PASSWORD") - postgres_hostname = os.environ.get("POSTGRES_HOSTNAME") + # postgres_hostname = os.environ.get("POSTGRES_HOSTNAME") + postgres_hostname = os.environ.get("POSTGRES_HOSTNAME_OUTSIDE_WHEN_DOCKER") # when using docker + # postgres_port = os.environ.get("POSTGRES_PORT") + postgres_port = os.environ.get("POSTGRES_PORT_OUTSIDE_WHEN_DOCKER") # when using docker postgres_db = os.environ.get("POSTGRES_DB") - postgres_port = os.environ.get("POSTGRES_PORT") + + print("db_url: ", "postgresql://"+postgres_user+":"+postgres_password+"@"+postgres_hostname+":"+postgres_port+"/"+postgres_db) db_url = ( "postgresql://" @@ -25,5 +28,4 @@ class Settings(BaseSettings): srid: int = 4326 - settings = Settings()