start at geo-db
This commit is contained in:
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y libpq-dev gcc \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY app/requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY app/ .
|
||||||
|
|
||||||
|
CMD ["python", "main.py"]
|
||||||
38
app/main.py
Normal file
38
app/main.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
import psycopg2
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
DB_USER = os.getenv("POSTGRES_USER");
|
||||||
|
DB_PASSWWORD = os.getenv("POSTGRES_PASSWORD");
|
||||||
|
DB_NAME = os.getenv("POSTGRES_DB");
|
||||||
|
DB_HOST = os.getenv("POSTGRES_HOST");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def connect_db():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
conn = psycopg2.connect(
|
||||||
|
host=DB_HOST,
|
||||||
|
database=DB_NAME,
|
||||||
|
user=DB_USER,
|
||||||
|
password=DB_PASSWWORD
|
||||||
|
)
|
||||||
|
print("Connected to the database successfully!")
|
||||||
|
return conn
|
||||||
|
except psycopg2.OperationalError as e:
|
||||||
|
print(f"Database connection failed: {e}")
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("starting app.")
|
||||||
|
# conn = connect_db();
|
||||||
|
# cursor = conn.cursor()
|
||||||
|
# cursor.execute("SELECT postgis_full_version();")
|
||||||
|
|
||||||
|
# print("obst", cursor.fetchone());
|
||||||
|
|
||||||
|
|
||||||
2
app/requirements.txt
Normal file
2
app/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
psycopg2-binary==2.9.3
|
||||||
|
SQLAlchemy==1.4.36
|
||||||
0
copernicus.py
Normal file
0
copernicus.py
Normal file
42
docker-compose.yml
Normal file
42
docker-compose.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
services:
|
||||||
|
geo-db-postgis:
|
||||||
|
image: postgis/postgis:15-3.3
|
||||||
|
container_name: geo-db-postgis
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${GEODB_USER}
|
||||||
|
POSTGRES_PASSWORD: ${GEODB_PW}
|
||||||
|
POSTGRES_DB: ${GEODB_NAME}
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:5432:5432"
|
||||||
|
volumes:
|
||||||
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
container_name: geo-app
|
||||||
|
environment:
|
||||||
|
PYTHONUNBUFFERED: 1
|
||||||
|
POSTGRES_USER: ${GEODB_USER}
|
||||||
|
POSTGRES_PASSWORD: ${GEODB_PW}
|
||||||
|
POSTGRES_DB: ${GEODB_NAME}
|
||||||
|
POSTGRES_HOST: geo-db-postgis
|
||||||
|
depends_on:
|
||||||
|
- geo-db-postgis
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
driver: bridge
|
||||||
|
external: true
|
||||||
38
sentinel.py
Normal file
38
sentinel.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Sentinel:
|
||||||
|
def __init__ (self, user, pw,
|
||||||
|
id="cdse-public",
|
||||||
|
type="password",
|
||||||
|
auth_url="https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token"
|
||||||
|
):
|
||||||
|
|
||||||
|
self.user = user;
|
||||||
|
self.password = pw;
|
||||||
|
self.auth_url = auth_url;
|
||||||
|
|
||||||
|
|
||||||
|
self.login_data = {
|
||||||
|
"client_id": id,
|
||||||
|
"username": self.user,
|
||||||
|
"password": self.password,
|
||||||
|
"grant_type": type,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
response = requests.post(self.auth_url, data=self.login_data);
|
||||||
|
self.access_token = response.json()["access_token"];
|
||||||
|
print(f"Login with user {self.user} successful.");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sat = Sentinel("test", "endex");
|
||||||
|
sat.login();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user