forked from mtusi2026/mtusi2026lab3
feat:report
This commit is contained in:
+26
-83
@@ -1,9 +1,8 @@
|
||||
x-api-base: &api-base
|
||||
x-api: &api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
env_file:
|
||||
- .env
|
||||
env_file: [.env]
|
||||
environment:
|
||||
APP_HOST: "0.0.0.0"
|
||||
APP_PORT: "8080"
|
||||
@@ -12,22 +11,12 @@ x-api-base: &api-base
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
SESSION_STORE: "postgres"
|
||||
SESSION_TTL_SECONDS: "3600"
|
||||
secrets:
|
||||
- database_url
|
||||
- cache_url
|
||||
# INSTANCE_ID сгенерируется в config.go
|
||||
secrets: [database_url, cache_url]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
postgres: { condition: service_healthy }
|
||||
redis: { condition: service_healthy }
|
||||
networks: [backend]
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.75"
|
||||
memory: 256M
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
|
||||
services:
|
||||
postgres:
|
||||
@@ -36,10 +25,8 @@ services:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
POSTGRES_DB: messenger
|
||||
secrets:
|
||||
- postgres_password
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
secrets: [postgres_password]
|
||||
volumes: [pgdata:/var/lib/postgresql/data]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 5s
|
||||
@@ -48,65 +35,36 @@ services:
|
||||
networks: [backend]
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 512M
|
||||
limits: { cpus: "${PG_CPUS:-1.0}", memory: "${PG_MEM:-512M}" }
|
||||
|
||||
redis:
|
||||
image: redis:7.2.5-alpine
|
||||
command: ["redis-server", "--appendonly", "yes", "--save", "60", "1"]
|
||||
volumes:
|
||||
- redisdata:/data
|
||||
command: ["redis-server", "--appendonly", "yes", "--save"]
|
||||
volumes: [redisdata:/data]
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
networks: [backend]
|
||||
api:
|
||||
<<: *api
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.5"
|
||||
memory: 256M
|
||||
|
||||
api1:
|
||||
<<: *api-base
|
||||
environment:
|
||||
APP_HOST: "0.0.0.0"
|
||||
APP_PORT: "8080"
|
||||
APP_ENV: "lab"
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
SESSION_STORE: "postgres"
|
||||
SESSION_TTL_SECONDS: "3600"
|
||||
INSTANCE_ID: "api-1"
|
||||
|
||||
api2:
|
||||
<<: *api-base
|
||||
environment:
|
||||
APP_HOST: "0.0.0.0"
|
||||
APP_PORT: "8080"
|
||||
APP_ENV: "lab"
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
SESSION_STORE: "postgres"
|
||||
SESSION_TTL_SECONDS: "3600"
|
||||
INSTANCE_ID: "api-2"
|
||||
cpus: "${API_CPU_PER_REPLICA:-0.5}"
|
||||
memory: "${API_MEM_PER_REPLICA:-128M}"
|
||||
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
<<: *api
|
||||
entrypoint: ["/app/migrate.sh"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
secrets:
|
||||
- database_url
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
networks: [backend]
|
||||
restart: "no"
|
||||
postgres: { condition: service_healthy }
|
||||
deploy:
|
||||
replicas: 1
|
||||
restart_policy:
|
||||
condition: "no"
|
||||
|
||||
lb:
|
||||
image: nginx:1.27.0-alpine
|
||||
@@ -114,20 +72,8 @@ services:
|
||||
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- api1
|
||||
- api2
|
||||
depends_on: [api]
|
||||
networks: [backend]
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/health/live"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.5"
|
||||
memory: 128M
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
@@ -138,9 +84,6 @@ networks:
|
||||
driver: bridge
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password.txt
|
||||
database_url:
|
||||
file: ./secrets/database_url.txt
|
||||
cache_url:
|
||||
file: ./secrets/cache_url.txt
|
||||
postgres_password: { file: ./secrets/postgres_password.txt }
|
||||
database_url: { file: ./secrets/database_url.txt }
|
||||
cache_url: { file: ./secrets/cache_url.txt }
|
||||
Reference in New Issue
Block a user