Skip to content

Commit

Permalink
fixing dev environment with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
romainm13 committed Feb 22, 2024
1 parent d3f3e01 commit d04e67e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions Trawlwatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<style>{f.read()}</style>", unsafe_allow_html=True)
return


local_css(Path("styles.css"))

st.write("![](https://upload.wikimedia.org/wikipedia/fr/e/e8/Logo_BLOOM.jpg)")
Expand Down
8 changes: 7 additions & 1 deletion alembic/init_script/load_amp_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path

import geopandas as gpd
import pandas as pd
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion alembic/init_script/load_positions_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=","
)

Expand Down
10 changes: 6 additions & 4 deletions bloom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://"
Expand All @@ -25,5 +28,4 @@ class Settings(BaseSettings):

srid: int = 4326


settings = Settings()

0 comments on commit d04e67e

Please sign in to comment.