Skip to content

Commit

Permalink
Added compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kamps committed Oct 29, 2024
1 parent 0b62562 commit 8541203
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["fastapi", "run", "app/main.py"]

# we use 'dev' here so we can sync code changes into the container and
# have the application pick these up without restarting for easy development
CMD ["fastapi", "dev", "app/main.py"]
8 changes: 3 additions & 5 deletions app/dependencies/database.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from sqlmodel import Session, SQLModel, create_engine
from fastapi import Depends
from typing import Annotated
from os import getenv
from app.models import *

# @todo replace with postgresDB
__sqlite_file_name = "../database.db"
__sqlite_url = f"sqlite:///{__sqlite_file_name}"
__connect_args = {"check_same_thread": False}
__engine = create_engine(__sqlite_url, connect_args=__connect_args)
__db_url = getenv("BOSWACHTER_DB_URL")
__engine = create_engine(__db_url)

def create_db_and_tables():
SQLModel.metadata.create_all(__engine)
Expand Down
20 changes: 20 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
api:
build: .
ports:
- "8000:8000"
environment:
BOSWACHTER_DB_USER: boswachter
BOSWACHTER_DB_PASSWORD: highsecurity
BOSWACHTER_DB_URL: "postgresql://boswachter:highsecurity@database:5432/boswachter"
develop:
watch:
- action: sync
path: ./app
target: /code/app

database:
image: postgres
environment:
POSTGRES_PASSWORD: highsecurity
POSTGRES_USER: boswachter
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fastapi[standard]==0.115.4
sqlmodel==0.0.22
fastapi[standard]
sqlmodel
psycopg2

0 comments on commit 8541203

Please sign in to comment.