From 6540ef1c1634c53afbf0192e77b962b930e6df0e Mon Sep 17 00:00:00 2001 From: Localhorst04 Date: Fri, 5 Dec 2025 11:39:58 +0100 Subject: [PATCH] init FastAPI Backend incl. postgresDb --- Dockerfile | 10 ++++++++++ docker-compose.yaml | 24 ++++++++++++++++++++++++ requirements.txt | 5 +++++ 3 files changed, 39 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..13f11ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.12-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y build-essential + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..8369adc --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +services: + api: + build: . + container_name: url_api + ports: + - "8000:8000" + environment: + DATABASE_URL: "postgresql://user:password@db:5432/urlshort" + depends_on: + - db + + db: + image: postgres:16 + container_name: url_db + restart: always + environment: + POSTGRES_USER: user + POSTGRES_PASSWORD: password + POSTGRES_DB: urlshort + volumes: + - db_data:/var/lib/postgresql/data + +volumes: + db_data: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c1d075d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +fastapi +uvicorn[standard] +SQLAlchemy +psycopg2-binary +python-dotenv