forked from mtusi2026/mtusi2026lab5
init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
FROM nginx:1.27.4-bookworm
|
||||
COPY swarm/nginx.conf /etc/nginx/nginx.conf
|
||||
HEALTHCHECK --interval=2s --timeout=2s --retries=15 CMD nginx -t
|
||||
@@ -0,0 +1,86 @@
|
||||
worker_processes auto;
|
||||
worker_shutdown_timeout 10s;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
client_max_body_size 11m;
|
||||
client_body_timeout 10s;
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
resolver 127.0.0.11 valid=2s ipv6=off;
|
||||
resolver_timeout 1s;
|
||||
|
||||
upstream api_backend {
|
||||
zone api_backend 64k;
|
||||
least_conn;
|
||||
server tasks.hla-app_api:8080 resolve max_fails=1 fail_timeout=2s;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
proxy_intercept_errors on;
|
||||
error_page 502 503 504 = @no_ready_api;
|
||||
|
||||
location = /nginx-health {
|
||||
default_type application/json;
|
||||
return 200 '{"status":"ok"}';
|
||||
}
|
||||
|
||||
location @no_ready_api {
|
||||
internal;
|
||||
default_type application/json;
|
||||
add_header X-Request-Id $request_id always;
|
||||
add_header X-Instance-Id nginx always;
|
||||
add_header Cache-Control "no-store" always;
|
||||
return 503 '{"error":{"code":"unavailable","message":"No ready API backend","request_id":"$request_id"}}';
|
||||
}
|
||||
|
||||
location ~ ^/api/v1/chats/[0-9a-fA-F-]+/messages$ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_request_buffering on;
|
||||
proxy_connect_timeout 500ms;
|
||||
proxy_send_timeout 4s;
|
||||
proxy_read_timeout 4s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504 non_idempotent;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
|
||||
location ~ ^/api/v1/chats/[0-9a-fA-F-]+/attachments$ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_request_buffering on;
|
||||
proxy_connect_timeout 500ms;
|
||||
proxy_send_timeout 20s;
|
||||
proxy_read_timeout 20s;
|
||||
proxy_next_upstream off;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_connect_timeout 500ms;
|
||||
proxy_send_timeout 4s;
|
||||
proxy_read_timeout 4s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
api:
|
||||
image: hla-swarm-registry:5000/hla-lab4-api:swarm
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
DATABASE_URL: jdbc:postgresql://hla-state_postgres:5432/${DATABASE_NAME:-messenger}
|
||||
DATABASE_USER: ${DATABASE_USER:-messenger}
|
||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD:?DATABASE_PASSWORD is required}
|
||||
DATABASE_POOL_SIZE: 10
|
||||
DATABASE_MIN_IDLE: 2
|
||||
DATABASE_QUERY_TIMEOUT_SECONDS: 5
|
||||
DATABASE_TRANSACTION_TIMEOUT_SECONDS: 5
|
||||
REDIS_HOST: hla-state_redis
|
||||
REDIS_PORT: 6379
|
||||
REDIS_CONNECT_TIMEOUT: 1s
|
||||
REDIS_COMMAND_TIMEOUT: 500ms
|
||||
SESSION_TTL_SECONDS: 3600
|
||||
USER_CACHE_TTL_SECONDS: 300
|
||||
IDEMPOTENCY_TTL_SECONDS: 86400
|
||||
S3_ENDPOINT: http://hla-state_minio:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?S3_ACCESS_KEY_ID is required}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?S3_SECRET_ACCESS_KEY is required}
|
||||
MAX_UPLOAD_BYTES: 10485760
|
||||
MAX_IMAGE_PIXELS: 40000000
|
||||
MAX_CONCURRENT_UPLOADS: 3
|
||||
UPLOAD_PERMIT_WAIT_MILLIS: 10000
|
||||
ATTACHMENT_CLEANUP_GRACE_SECONDS: 3600
|
||||
ATTACHMENT_CLEANUP_DRY_RUN: "false"
|
||||
ATTACHMENT_RECONCILE_INTERVAL_MILLIS: 600000
|
||||
ATTACHMENT_RECONCILE_INITIAL_DELAY_MILLIS: 60000
|
||||
FLYWAY_ENABLED: "false"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "--fail", "--silent", "http://localhost:8080/health/ready"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 20
|
||||
start_period: 45s
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 2
|
||||
endpoint_mode: dnsrr
|
||||
placement:
|
||||
max_replicas_per_node: 1
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 2s
|
||||
update_config:
|
||||
parallelism: 1
|
||||
order: start-first
|
||||
monitor: 15s
|
||||
failure_action: rollback
|
||||
rollback_config:
|
||||
parallelism: 1
|
||||
order: stop-first
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.75"
|
||||
memory: 768M
|
||||
|
||||
nginx:
|
||||
image: hla-swarm-registry:5000/hla-lab4-nginx:swarm
|
||||
ports:
|
||||
- target: 80
|
||||
published: 8080
|
||||
protocol: tcp
|
||||
mode: ingress
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.hla.lb == true
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
networks:
|
||||
backend:
|
||||
external: true
|
||||
name: hla-state_backend
|
||||
@@ -0,0 +1,123 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.4-bookworm
|
||||
environment:
|
||||
POSTGRES_DB: ${DATABASE_NAME:-messenger}
|
||||
POSTGRES_USER: ${DATABASE_USER:-messenger}
|
||||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:?DATABASE_PASSWORD is required}
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.hla.state == true
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.00"
|
||||
memory: 768M
|
||||
|
||||
redis:
|
||||
image: redis:7.4-bookworm
|
||||
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
|
||||
volumes:
|
||||
- redis-data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.hla.state == true
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 256M
|
||||
|
||||
minio:
|
||||
image: bitnamilegacy/minio:2025.4.22-debian-12-r1@sha256:d7cd0e172c4cc0870f4bdc3142018e2a37be9acf04d68f386600daad427e0cab
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?MINIO_ROOT_USER is required}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?MINIO_ROOT_PASSWORD is required}
|
||||
volumes:
|
||||
- minio-data:/bitnami/minio/data
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "--fail", "--silent", "http://localhost:9000/minio/health/live"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.hla.state == true
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.75"
|
||||
memory: 512M
|
||||
|
||||
minio-init:
|
||||
image: bitnamilegacy/minio-client:2025.4.16-debian-12-r0@sha256:28e38f52642c06a2344fa974cf55786b4c52601b6b9b0676c68d40ee0876a5bc
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?MINIO_ROOT_USER is required}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?MINIO_ROOT_PASSWORD is required}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?S3_ACCESS_KEY_ID is required}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?S3_SECRET_ACCESS_KEY is required}
|
||||
configs:
|
||||
- source: minio_api_policy
|
||||
target: /policy/minio-api-policy.json
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
command:
|
||||
- |
|
||||
set -eu
|
||||
until mc alias set local http://minio:9000 "$$MINIO_ROOT_USER" "$$MINIO_ROOT_PASSWORD"; do sleep 2; done
|
||||
mc mb --ignore-existing "local/$$S3_BUCKET"
|
||||
mc anonymous set none "local/$$S3_BUCKET"
|
||||
sed "s/__S3_BUCKET__/$$S3_BUCKET/g" /policy/minio-api-policy.json > /tmp/minio-api-policy.json
|
||||
mc admin user add local "$$S3_ACCESS_KEY_ID" "$$S3_SECRET_ACCESS_KEY" || true
|
||||
mc admin policy create local messenger-attachments-rw /tmp/minio-api-policy.json || true
|
||||
mc admin policy attach local messenger-attachments-rw --user "$$S3_ACCESS_KEY_ID"
|
||||
networks: [backend]
|
||||
deploy:
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints:
|
||||
- node.labels.hla.state == true
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 2s
|
||||
max_attempts: 20
|
||||
|
||||
networks:
|
||||
backend:
|
||||
driver: overlay
|
||||
attachable: true
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
redis-data:
|
||||
minio-data:
|
||||
|
||||
configs:
|
||||
minio_api_policy:
|
||||
file: ../infra/minio-api-policy.json
|
||||
Reference in New Issue
Block a user