Use docker compose
This commit is contained in:
parent
8c2f5acccf
commit
bea6455b3a
14
Makefile
14
Makefile
@ -13,20 +13,10 @@ install-dev:
|
|||||||
$(VENV_DIR)/bin/pip install -r $(REQ_FILE) -r requirements-dev.txt
|
$(VENV_DIR)/bin/pip install -r $(REQ_FILE) -r requirements-dev.txt
|
||||||
|
|
||||||
start:
|
start:
|
||||||
docker compose up -d db
|
docker compose up
|
||||||
@echo "Waiting for the database to be ready..."
|
|
||||||
@while ! nc -z localhost 5432; do \
|
|
||||||
sleep 1; \
|
|
||||||
done
|
|
||||||
uvicorn backend.app.main:app --reload --host 0.0.0.0 --port 8080 --reload-include backend/app
|
|
||||||
|
|
||||||
start-db:
|
|
||||||
docker-compose up -d db
|
|
||||||
|
|
||||||
stop-db:
|
|
||||||
docker-compose down
|
|
||||||
|
|
||||||
clean-db:
|
clean-db:
|
||||||
|
docker compose down
|
||||||
docker compose down -v db
|
docker compose down -v db
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@ -1,20 +1,13 @@
|
|||||||
# Use the official Python image from the Docker Hub
|
|
||||||
FROM python:3.9-slim
|
FROM python:3.9-slim
|
||||||
|
|
||||||
# Set the working directory in the container
|
WORKDIR /code
|
||||||
WORKDIR /app
|
COPY ./requirements.txt /code/requirements.txt
|
||||||
|
|
||||||
# Copy the pyproject.toml file to the container
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY pyproject.toml ./
|
|
||||||
|
|
||||||
# Install the dependencies using pyproject.toml
|
COPY ./app /code/app
|
||||||
RUN pip install --no-cache-dir .
|
COPY .env /code/.env
|
||||||
|
|
||||||
# Copy the rest of the application code to the container
|
EXPOSE 8080
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Expose the port the app runs on
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
|
||||||
EXPOSE 8000
|
|
||||||
|
|
||||||
# Command to run the application
|
|
||||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
||||||
@ -21,7 +21,7 @@ settings = get_settings()
|
|||||||
|
|
||||||
async def _get_async_engine() -> AsyncEngine:
|
async def _get_async_engine() -> AsyncEngine:
|
||||||
return create_async_engine(
|
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,
|
future=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ async def get_connection() -> AsyncGenerator[AsyncConnection, None]:
|
|||||||
|
|
||||||
def _get_engine() -> Engine:
|
def _get_engine() -> Engine:
|
||||||
return create_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}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ class _DbSettings(_BaseConfig):
|
|||||||
username: str = Field(default=os.getenv("PG_USER"))
|
username: str = Field(default=os.getenv("PG_USER"))
|
||||||
password: str = Field(default=os.getenv("PG_PASSWORD"))
|
password: str = Field(default=os.getenv("PG_PASSWORD"))
|
||||||
db_name: str = Field(default=os.getenv("PG_DB_NAME"))
|
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):
|
class _Settings(_BaseConfig):
|
||||||
|
|||||||
@ -5,3 +5,4 @@ pydantic
|
|||||||
sqlalchemy
|
sqlalchemy
|
||||||
pydantic-settings
|
pydantic-settings
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
pg8000
|
||||||
|
|||||||
@ -1,13 +1,20 @@
|
|||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
web:
|
backend:
|
||||||
build: .
|
build:
|
||||||
|
context: ./backend
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8080:8080"
|
||||||
environment:
|
environment:
|
||||||
- ENV=production
|
- ENVIRONMENT=development
|
||||||
command: ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
- PG_HOST=db
|
||||||
|
- PG_PORT=5432
|
||||||
|
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080", "--reload"]
|
||||||
|
volumes:
|
||||||
|
- ./backend/app:/code/app
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:15
|
image: postgres:15
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user