Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1

# Postgres
POSTGRES_HOST=localhost
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=devdb
POSTGRES_USER=devdb
POSTGRES_PASSWORD=secret

# Redis
REDIS_HOST=localhost
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=2

Expand Down
94 changes: 94 additions & 0 deletions compose-ha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
services:
api1:
container_name: panettone_api1
build: .
environment:
- PYTHONPATH=/panettone
env_file:
- .env
- .secrets
command: bash -c "
uvicorn app.main:app
--host 0.0.0.0 --port 8080
--lifespan=on --use-colors --loop uvloop --http httptools
"
volumes:
- ./app:/panettone/app
- ./tests:/panettone/tests
- ./templates:/panettone/templates
- ./alembic:/panettone/alembic
ports:
- "8081:8080"
depends_on:
- postgres
- redis

api2:
container_name: panettone_api2
build: .
environment:
- PYTHONPATH=/panettone
env_file:
- .env
- .secrets
command: bash -c "
uvicorn app.main:app
--host 0.0.0.0 --port 8080
--lifespan=on --use-colors --loop uvloop --http httptools
"
volumes:
- ./app:/panettone/app
- ./tests:/panettone/tests
- ./templates:/panettone/templates
- ./alembic:/panettone/alembic
ports:
- "8082:8080"
depends_on:
- postgres
- redis


postgres:
container_name: panettone_postgres
build:
context: ./db
dockerfile: Dockerfile
volumes:
- panettone_postgres_data:/var/lib/postgresql/data
env_file:
- .env
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
healthcheck:
test:
[
"CMD-SHELL", "pg_isready -d $POSTGRES_DB -U $POSTGRES_USER"
]
interval: 5s
timeout: 5s
retries: 5

redis:
image: redis:latest
container_name: panettone_redis
ports:
- "6379:6379"
env_file:
- .env
entrypoint: redis-server --appendonly yes

loadbalancer:
container_name: panettone_loadbalancer
build: ./nginx
ports:
- "8080:80"
depends_on:
- api1
- api2
Comment on lines +84 to +91
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The load balancer depends_on configuration only ensures containers start in order but doesn't wait for the API services to be ready. Consider adding health checks to the API services and using depends_on with condition: service_healthy to ensure the load balancer only starts when backends are actually ready to serve traffic.

Copilot uses AI. Check for mistakes.


volumes:
panettone_postgres_data: {}
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
12 changes: 12 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
upstream loadbalancer {
server api1:8080 weight=1;
server api2:8080 weight=1;
}

server {
listen 80;

location / {
proxy_pass http://loadbalancer;
}
}
Comment on lines +6 to +12
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nginx configuration lacks security headers and basic hardening. Consider adding security headers like X-Frame-Options, X-Content-Type-Options, and configuring proper error pages to avoid information disclosure.

Copilot uses AI. Check for mistakes.