complete level 5 track 1

This commit is contained in:
2026-10-15 13:04:16 +03:00
parent 9d0080db10
commit 4918969c6b
40 changed files with 877 additions and 53 deletions
+90 -12
View File
@@ -1,7 +1,6 @@
services:
db:
image: postgres:16-alpine
container_name: messenger-db
restart: unless-stopped
environment:
POSTGRES_DB_FILE: /run/secrets/postgres_db
@@ -21,10 +20,17 @@ services:
timeout: 5s
retries: 10
start_period: 10s
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
redis:
image: redis:7.4-alpine
container_name: messenger-redis
restart: unless-stopped
command: >
redis-server
@@ -41,34 +47,85 @@ services:
timeout: 3s
retries: 10
start_period: 5s
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
api:
migrate:
build:
context: .
dockerfile: Dockerfile
container_name: messenger-api
restart: unless-stopped
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
entrypoint: ["sh", "-c"]
command:
- "exec java -Dfile.encoding=UTF-8 -Dspring.main.web-application-type=none -jar app.jar"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
SPRING_DATASOURCE_USERNAME_FILE: /run/secrets/postgres_user
SPRING_DATASOURCE_PASSWORD_FILE: /run/secrets/postgres_password
SPRING_FLYWAY_ENABLED: "true"
secrets:
- postgres_user
- postgres_password
depends_on:
db:
condition: service_healthy
restart: "no"
networks:
- messenger-net
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 128M
api:
stop_grace_period: 40s
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
entrypoint:
- "sh"
- "-c"
- "export INSTANCE_ID=\"$$(cat /etc/hostname)\"; exec java -Dfile.encoding=UTF-8 $$JAVA_OPTS -jar app.jar"
environment:
RATE_PER_MINUTE: ${RATE_PER_MINUTE:-100000}
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
SPRING_DATASOURCE_USERNAME_FILE: /run/secrets/postgres_user
SPRING_DATASOURCE_PASSWORD_FILE: /run/secrets/postgres_password
SPRING_PROFILES_ACTIVE: ${APP_ENV:-lab}
SPRING_FLYWAY_ENABLED: "false"
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-400}
SESSION_STORE: ${SESSION_STORE:-postgres}
SPRING_DATA_REDIS_HOST: redis
SPRING_DATA_REDIS_PORT: 6379
ports:
- "127.0.0.1:8080:8080"
secrets:
- postgres_user
- postgres_password
networks:
- messenger-net
deploy:
replicas: 2
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/health/ready | grep -q '\"status\":\"ok\"'"]
interval: 5s
@@ -76,6 +133,27 @@ services:
retries: 20
start_period: 40s
lb:
image: nginx:1.27-alpine
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api:
condition: service_healthy
networks:
- messenger-net
deploy:
resources:
limits:
cpus: '0.5'
memory: 128M
reservations:
cpus: '0.1'
memory: 32M
volumes:
pgdata:
redisdata: