ops: add balanced replicated stack
This commit is contained in:
+125
-16
@@ -32,31 +32,107 @@ services:
|
||||
mem_limit: ${VALKEY_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab2}
|
||||
env_file: .env
|
||||
ports:
|
||||
- "${API_BIND_ADDRESS}:${APP_PORT}"
|
||||
migrate:
|
||||
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: 10s
|
||||
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:
|
||||
api:
|
||||
nginx:
|
||||
condition: service_healthy
|
||||
cpus: ${SWAGGER_CPUS}
|
||||
mem_limit: ${SWAGGER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
tests:
|
||||
@@ -68,23 +144,30 @@ services:
|
||||
TEST_DATABASE_URL: ${DATABASE_URL}
|
||||
TEST_CACHE_URL: ${CACHE_URL}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
cpus: ${TEST_CPUS}
|
||||
mem_limit: ${TEST_MEMORY}
|
||||
|
||||
experiment:
|
||||
profiles: ["research"]
|
||||
build:
|
||||
context: .
|
||||
target: experiment
|
||||
env_file: .env
|
||||
command: ["go", "run", "./cmd/lab2experiment", "-output=/output/lab2-track2.json"]
|
||||
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:
|
||||
postgres:
|
||||
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
|
||||
@@ -96,6 +179,8 @@ services:
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
valkey-exporter:
|
||||
@@ -107,12 +192,25 @@ services:
|
||||
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
|
||||
@@ -121,16 +219,25 @@ services:
|
||||
- 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}
|
||||
@@ -141,6 +248,8 @@ services:
|
||||
- "${GRAFANA_BIND_ADDRESS}:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
cpus: ${GRAFANA_CPUS}
|
||||
mem_limit: ${GRAFANA_MEMORY}
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user