Добавить compose-стенд, секреты и restart hook
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
name: grigoriev-lab2
|
||||
|
||||
x-app-env: &app-env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
APP_ENV: ${APP_ENV:-lab}
|
||||
APP_SHUTDOWN_TIMEOUT: ${APP_SHUTDOWN_TIMEOUT:-5}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
SESSION_CACHE_TTL_SECONDS: ${SESSION_CACHE_TTL_SECONDS:-60}
|
||||
DB_POOL_MIN: ${DB_POOL_MIN:-1}
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-10}
|
||||
DB_POOL_TIMEOUT_SECONDS: ${DB_POOL_TIMEOUT_SECONDS:-2}
|
||||
DB_STATEMENT_TIMEOUT_MS: ${DB_STATEMENT_TIMEOUT_MS:-5000}
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL: ${CACHE_URL:-redis://valkey:6379/0}
|
||||
|
||||
x-dns-opt: &dns-opt
|
||||
- timeout:1
|
||||
- attempts:1
|
||||
|
||||
x-postgres: &postgres
|
||||
image: postgres:17.11-alpine@sha256:266d3c257594e195b309ae9d1805e54c788f1d7b375f56bf6c367aac6c917e7b
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
command: ["postgres", "-c", "track_io_timing=on"]
|
||||
secrets: [postgres_password]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 10s
|
||||
stop_grace_period: 30s
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
services:
|
||||
postgres:
|
||||
<<: *postgres
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.11-alpine@sha256:2602ace2be6569bc2bbb06f873776516ab9089821525be34f4305c67eb9db02a
|
||||
command: ["valkey-server", "--save", "", "--appendonly", "no",
|
||||
"--maxmemory", "64mb", "--maxmemory-policy", "volatile-ttl"]
|
||||
healthcheck:
|
||||
test: ["CMD", "valkey-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
migrate:
|
||||
build: .
|
||||
image: mtusi-messenger:lab2
|
||||
command: ["python", "src/migrate.py"]
|
||||
environment: *app-env
|
||||
secrets: [database_url]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
networks: [backend]
|
||||
restart: "no"
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: mtusi-messenger:lab2
|
||||
environment: *app-env
|
||||
secrets: [database_url]
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
valkey:
|
||||
condition: service_started
|
||||
dns_opt: *dns-opt
|
||||
stop_grace_period: 10s
|
||||
networks: [frontend, backend]
|
||||
restart: unless-stopped
|
||||
|
||||
postgres-restore:
|
||||
<<: *postgres
|
||||
profiles: [restore]
|
||||
volumes:
|
||||
- pgdata_restore:/var/lib/postgresql/data
|
||||
|
||||
api-restore:
|
||||
image: mtusi-messenger:lab2
|
||||
profiles: [restore]
|
||||
environment:
|
||||
<<: *app-env
|
||||
DATABASE_URL_FILE: /run/secrets/database_url_restore
|
||||
CACHE_URL: ""
|
||||
dns_opt: *dns-opt
|
||||
secrets: [database_url_restore]
|
||||
ports:
|
||||
- "127.0.0.1:8081:8080"
|
||||
depends_on:
|
||||
postgres-restore:
|
||||
condition: service_healthy
|
||||
networks: [frontend, backend]
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
pgdata_restore:
|
||||
|
||||
networks:
|
||||
frontend:
|
||||
backend:
|
||||
internal: true
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
database_url_restore:
|
||||
file: ./secrets/database_url_restore
|
||||
Reference in New Issue
Block a user