forked from mtusi2026/mtusi2026lab3
chore(app) transferred codebase from Lab2
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
# AGENT: Single local stack for lab 2 grade 4. PostgreSQL is the source of
|
||||
# truth, Redis stores sessions with AOF persistence. Both have named volumes,
|
||||
# so `docker compose restart` preserves data and `down -v` is never needed.
|
||||
name: mtusi2026lab2
|
||||
|
||||
x-api-environment: &api-environment
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8080"
|
||||
DB_POOL_MAX_CONNS: ${DB_POOL_MAX_CONNS:-10}
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger}?sslmode=disable
|
||||
CACHE_URL: redis://redis:6379/0
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.10-alpine
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
start_period: 5s
|
||||
|
||||
redis:
|
||||
image: redis:7.4.7-alpine
|
||||
restart: unless-stopped
|
||||
# AOF survives a container restart and keeps absolute key TTLs, which is
|
||||
# exactly what the session-persistence check needs.
|
||||
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec", "--save", ""]
|
||||
volumes:
|
||||
- redisdata:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
start_period: 3s
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
<<: *api-environment
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
ports:
|
||||
- "${APP_PORT_PUBLISH:-8080}:8080"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8080/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 4s
|
||||
retries: 12
|
||||
start_period: 15s
|
||||
stop_grace_period: 15s
|
||||
|
||||
# AGENT: Only for the short-TTL expiry check. It shares PostgreSQL and Redis
|
||||
# with the main API, so its 2-second sessions are visible to every instance.
|
||||
api-short-ttl:
|
||||
profiles: ["checks"]
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
<<: *api-environment
|
||||
SESSION_TTL_SECONDS: "2"
|
||||
ports:
|
||||
- "${APP_SHORT_TTL_PORT:-8081}:8080"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8080/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 4s
|
||||
retries: 12
|
||||
start_period: 15s
|
||||
stop_grace_period: 15s
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
redisdata:
|
||||
Reference in New Issue
Block a user