Move lab4 to lab5

This commit is contained in:
2026-11-16 19:54:38 +03:00
parent 276dbdad8a
commit cd84a6fd36
208 changed files with 9611 additions and 25 deletions
+57
View File
@@ -0,0 +1,57 @@
# Single public entry point in front of the API replicas.
# Backends are discovered through Docker DNS (service name `api`) and receive traffic only while /health/ready is 200.
global
log stdout format raw local0 info
# Without it HAProxy sizes buffers from the file descriptor limit and uses ~100 MB.
maxconn 4096
defaults
mode http
log global
option httplog
option dontlognull
option forwardfor
timeout connect 1s
timeout client 30s
timeout server 30s
timeout http-request 10s
timeout http-keep-alive 5s
# Retried only when the connection to a replica fails, i.e. before the request was sent:
# a POST that reached a replica is never repeated by the balancer.
retries 2
option redispatch 1
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 2s
hold other 2s
hold refused 2s
hold nx 2s
hold timeout 2s
hold obsolete 2s
accepted_payload_size 8192
frontend http
bind :8080
default_backend api
# Not published: container healthcheck and the backend table (wget -qO- "http://127.0.0.1:8404/stats;csv").
frontend internal
bind :8404
monitor-uri /healthz
stats enable
stats uri /stats
stats refresh 5s
backend api
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
# A replica leaves rotation after 2 failed checks 1 s apart and returns after 2 successful ones.
default-server check inter 1s fall 2 rise 2 resolvers docker init-addr none
# Up to 4 replicas; slots without a resolved address stay in maintenance.
server-template api 4 api:8080
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
set -eu
# No tracing: credentials must not appear in logs.
mc alias set local http://s3:9000 "$(cat /run/secrets/s3_access_key_id)" "$(cat /run/secrets/s3_secret_access_key)" >/dev/null
mc mb --ignore-existing "local/$S3_BUCKET"
mc anonymous set none "local/$S3_BUCKET"
api_user=$(cat /run/secrets/s3_api_access_key_id)
mc admin user add local "$api_user" "$(cat /run/secrets/s3_api_secret_access_key)" >/dev/null
cat > /tmp/attachment-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::$S3_BUCKET"]},
{"Effect":"Allow","Action":["s3:GetObject","s3:PutObject","s3:DeleteObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/originals/*"]}
]
}
EOF
mc admin policy create local attachments-api /tmp/attachment-policy.json >/dev/null
mc admin policy attach local attachments-api --user "$api_user" >/dev/null