Use docker compose

This commit is contained in:
Jacob Windsor
2025-02-19 15:36:28 +01:00
parent 8c2f5acccf
commit bea6455b3a
6 changed files with 27 additions and 34 deletions
+7 -14
View File
@@ -1,20 +1,13 @@
# Use the official Python image from the Docker Hub
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
# Copy the pyproject.toml file to the container
COPY pyproject.toml ./
RUN pip install --no-cache-dir -r requirements.txt
# Install the dependencies using pyproject.toml
RUN pip install --no-cache-dir .
COPY ./app /code/app
COPY .env /code/.env
# Copy the rest of the application code to the container
COPY . .
EXPOSE 8080
# Expose the port the app runs on
EXPOSE 8000
# Command to run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
+2 -2
View File
@@ -21,7 +21,7 @@ settings = get_settings()
async def _get_async_engine() -> AsyncEngine:
return create_async_engine(
f"postgresql+asyncpg://{settings.db.username}:{settings.db.password}@localhost/{settings.db.db_name}",
f"postgresql+asyncpg://{settings.db.username}:{settings.db.password}@{settings.db.host}:{settings.db.port}/{settings.db.db_name}",
future=True,
)
@@ -54,7 +54,7 @@ async def get_connection() -> AsyncGenerator[AsyncConnection, None]:
def _get_engine() -> Engine:
return create_engine(
f"postgresql+pg8000://{settings.db.username}:{settings.db.password}@localhost/{settings.db.db_name}"
f"postgresql+pg8000://{settings.db.username}:{settings.db.password}@{settings.db.host}:{settings.db.port}/{settings.db.db_name}"
)
+2
View File
@@ -19,6 +19,8 @@ class _DbSettings(_BaseConfig):
username: str = Field(default=os.getenv("PG_USER"))
password: str = Field(default=os.getenv("PG_PASSWORD"))
db_name: str = Field(default=os.getenv("PG_DB_NAME"))
host: str = Field(default=os.getenv("PG_HOST"))
port: int = Field(default=os.getenv("PG_PORT"))
class _Settings(_BaseConfig):
+2 -1
View File
@@ -4,4 +4,5 @@ sqlmodel
pydantic
sqlalchemy
pydantic-settings
python-dotenv
python-dotenv
pg8000