forked from mtusi2026/mtusi2026lab3
ops: add balanced replicated stack
This commit is contained in:
+261
@@ -0,0 +1,261 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.6-alpine3.22
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${POSTGRES_CPUS}
|
||||
mem_limit: ${POSTGRES_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.4-alpine
|
||||
command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec", "--requirepass", "${VALKEY_PASSWORD}"]
|
||||
environment:
|
||||
VALKEY_PASSWORD: ${VALKEY_PASSWORD}
|
||||
volumes:
|
||||
- valkey_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "valkey-cli --no-auth-warning -a \"$$VALKEY_PASSWORD\" ping | grep -q PONG"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${VALKEY_CPUS}
|
||||
mem_limit: ${VALKEY_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
migrate:
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab3}
|
||||
command: ["/app/migrate"]
|
||||
environment:
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
DB_MIN_CONNS: ${DB_MIN_CONNS}
|
||||
DB_MAX_CONNS: ${DB_MAX_CONNS}
|
||||
DB_MAX_CONNECTION_AGE_SECONDS: ${DB_MAX_CONNECTION_AGE_SECONDS}
|
||||
DB_MAX_CONNECTION_IDLE_SECONDS: ${DB_MAX_CONNECTION_IDLE_SECONDS}
|
||||
DB_HEALTH_CHECK_SECONDS: ${DB_HEALTH_CHECK_SECONDS}
|
||||
DEPENDENCY_TIMEOUT_SECONDS: ${DEPENDENCY_TIMEOUT_SECONDS}
|
||||
MIGRATION_TIMEOUT_SECONDS: ${MIGRATION_TIMEOUT_SECONDS}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
cpus: ${MIGRATE_CPUS}
|
||||
mem_limit: ${MIGRATE_MEMORY}
|
||||
restart: "no"
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab3}
|
||||
environment:
|
||||
APP_HOST: ${APP_HOST}
|
||||
APP_PORT: ${APP_PORT}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
CACHE_URL: ${CACHE_URL}
|
||||
SESSION_STORE: ${SESSION_STORE}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS}
|
||||
DB_MIN_CONNS: ${DB_MIN_CONNS}
|
||||
DB_MAX_CONNS: ${DB_MAX_CONNS}
|
||||
DB_MAX_CONNECTION_AGE_SECONDS: ${DB_MAX_CONNECTION_AGE_SECONDS}
|
||||
DB_MAX_CONNECTION_IDLE_SECONDS: ${DB_MAX_CONNECTION_IDLE_SECONDS}
|
||||
DB_HEALTH_CHECK_SECONDS: ${DB_HEALTH_CHECK_SECONDS}
|
||||
DEPENDENCY_TIMEOUT_SECONDS: ${DEPENDENCY_TIMEOUT_SECONDS}
|
||||
REQUEST_TIMEOUT_SECONDS: ${REQUEST_TIMEOUT_SECONDS}
|
||||
HTTP_READ_HEADER_TIMEOUT_SECONDS: ${HTTP_READ_HEADER_TIMEOUT_SECONDS}
|
||||
HTTP_READ_TIMEOUT_SECONDS: ${HTTP_READ_TIMEOUT_SECONDS}
|
||||
HTTP_WRITE_TIMEOUT_SECONDS: ${HTTP_WRITE_TIMEOUT_SECONDS}
|
||||
HTTP_IDLE_TIMEOUT_SECONDS: ${HTTP_IDLE_TIMEOUT_SECONDS}
|
||||
HTTP_SHUTDOWN_TIMEOUT_SECONDS: ${HTTP_SHUTDOWN_TIMEOUT_SECONDS}
|
||||
PASSWORD_MEMORY_KIB: ${PASSWORD_MEMORY_KIB}
|
||||
PASSWORD_ITERATIONS: ${PASSWORD_ITERATIONS}
|
||||
PASSWORD_PARALLELISM: ${PASSWORD_PARALLELISM}
|
||||
PASSWORD_SALT_LENGTH: ${PASSWORD_SALT_LENGTH}
|
||||
PASSWORD_KEY_LENGTH: ${PASSWORD_KEY_LENGTH}
|
||||
SWAGGER_PORT: ${SWAGGER_PORT}
|
||||
expose:
|
||||
- "8080"
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:${APP_PORT}/health/ready || exit 1"]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
start_period: 5s
|
||||
retries: 2
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
cpus: ${API_CPUS}
|
||||
mem_limit: ${API_MEMORY}
|
||||
stop_grace_period: 8s
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
build:
|
||||
context: .
|
||||
target: loadbalancer
|
||||
image: ${NGINX_IMAGE:-mtusi-nginx:lab3}
|
||||
ports:
|
||||
- "${API_BIND_ADDRESS}:8080"
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8081/stub_status || exit 1"]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 10
|
||||
cpus: ${NGINX_CPUS}
|
||||
mem_limit: ${NGINX_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
swagger:
|
||||
build:
|
||||
context: .
|
||||
target: swagger
|
||||
image: ${SWAGGER_IMAGE:-mtusi-swagger:lab3}
|
||||
ports:
|
||||
- "${SWAGGER_BIND_ADDRESS}:8080"
|
||||
depends_on:
|
||||
nginx:
|
||||
condition: service_healthy
|
||||
cpus: ${SWAGGER_CPUS}
|
||||
mem_limit: ${SWAGGER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
tests:
|
||||
profiles: ["tests"]
|
||||
build:
|
||||
context: .
|
||||
target: test
|
||||
environment:
|
||||
TEST_DATABASE_URL: ${DATABASE_URL}
|
||||
TEST_CACHE_URL: ${CACHE_URL}
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
cpus: ${TEST_CPUS}
|
||||
mem_limit: ${TEST_MEMORY}
|
||||
|
||||
experiment:
|
||||
profiles: ["research"]
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab3}
|
||||
command:
|
||||
- /app/lab3experiment
|
||||
- -base-url=http://nginx:8080
|
||||
- -prometheus-url=http://prometheus:9090
|
||||
- -output=/output/lab3-scale.json
|
||||
volumes:
|
||||
- ./evidence:/output
|
||||
depends_on:
|
||||
nginx:
|
||||
condition: service_healthy
|
||||
prometheus:
|
||||
condition: service_healthy
|
||||
cpus: ${TEST_CPUS}
|
||||
mem_limit: ${TEST_MEMORY}
|
||||
|
||||
postgres-exporter:
|
||||
image: quay.io/prometheuscommunity/postgres-exporter:v0.20.1
|
||||
environment:
|
||||
DATA_SOURCE_URI: postgres:5432/${POSTGRES_DB}?sslmode=disable
|
||||
DATA_SOURCE_USER: ${POSTGRES_USER}
|
||||
DATA_SOURCE_PASS: ${POSTGRES_PASSWORD}
|
||||
PG_EXPORTER_COLLECTION_TIMEOUT: 5s
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
valkey-exporter:
|
||||
image: oliver006/redis_exporter:v1.89.0-alpine
|
||||
environment:
|
||||
REDIS_ADDR: redis://valkey:6379
|
||||
REDIS_USER: default
|
||||
REDIS_PASSWORD: ${VALKEY_PASSWORD}
|
||||
depends_on:
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
nginx-exporter:
|
||||
image: nginx/nginx-prometheus-exporter:1.5.1
|
||||
command: ["--nginx.scrape-uri=http://nginx:8081/stub_status"]
|
||||
depends_on:
|
||||
nginx:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
prometheus:
|
||||
build:
|
||||
context: .
|
||||
target: prometheus
|
||||
image: ${PROMETHEUS_IMAGE:-mtusi-prometheus:lab3}
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
volumes:
|
||||
- prometheus_data:/prometheus
|
||||
ports:
|
||||
- "${PROMETHEUS_BIND_ADDRESS}:9090"
|
||||
healthcheck:
|
||||
test: ["CMD", "promtool", "query", "instant", "http://127.0.0.1:9090", "up"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
depends_on:
|
||||
- api
|
||||
- nginx-exporter
|
||||
- postgres-exporter
|
||||
- valkey-exporter
|
||||
cpus: ${PROMETHEUS_CPUS}
|
||||
mem_limit: ${PROMETHEUS_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
build:
|
||||
context: .
|
||||
target: grafana
|
||||
image: ${GRAFANA_IMAGE:-mtusi-grafana:lab3}
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD}
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
ports:
|
||||
- "${GRAFANA_BIND_ADDRESS}:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
cpus: ${GRAFANA_CPUS}
|
||||
mem_limit: ${GRAFANA_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
valkey_data:
|
||||
prometheus_data:
|
||||
grafana_data:
|
||||
Reference in New Issue
Block a user