# Стенд: сервисы, порты, лимиты, секреты, миграции, топология брокера
# date: 2026-11-20T14:30:52Z
# commit: d83876f

$ docker compose ps -a --format table {{.Service}}\t{{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}
SERVICE          NAME                                    IMAGE                                                                                                                  STATUS                      PORTS
api              messenger-lab6-api-1                    mtusi-messenger-lab6-api:dev                                                                                           Up 13 seconds (healthy)     8080/tcp
api              messenger-lab6-api-2                    mtusi-messenger-lab6-api:dev                                                                                           Up 13 seconds (healthy)     8080/tcp
grafana          messenger-lab6-grafana-1                grafana/grafana:11.4.0@sha256:d8ea37798ccc41061a62ab080f2676dda6bf7815558499f901bdb0f533a456fb                         Up 19 seconds (healthy)     127.0.0.1:3000->3000/tcp
lb               messenger-lab6-lb-1                     haproxy:3.0.6-alpine                                                                                                   Up 7 seconds                127.0.0.1:8080->8080/tcp
loki             messenger-lab6-loki-1                   grafana/loki:3.3.2@sha256:8af2de1abbdd7aa92b27c9bcc96f0f4140c9096b507c77921ffddf1c6ad6c48f                             Up 25 seconds               3100/tcp
migrate          messenger-lab6-migrate-1                mtusi-messenger-lab6-migrate:dev                                                                                       Exited (0) 14 seconds ago   
otel-collector   messenger-lab6-otel-collector-1         otel/opentelemetry-collector-contrib:0.115.1@sha256:d2da12c4336a79758826700be9e21ecf4a9f7d945b7f8a58ba55ee3fa45427c8   Up 25 seconds               4317-4318/tcp, 55678-55679/tcp
postgres         messenger-lab6-postgres-1               postgres:17.2-alpine                                                                                                   Up 24 seconds (healthy)     5432/tcp
prometheus       messenger-lab6-prometheus-1             prom/prometheus:v3.1.0@sha256:6559acbd5d770b15bb3c954629ce190ac3cbbdb2b7f1c30f0385c4e05104e218                         Up 25 seconds (healthy)     9090/tcp
rabbitmq         messenger-lab6-rabbitmq-1               rabbitmq:4.0.5-alpine@sha256:e045b5166b9188a38eee5c99411709aa1f0ffa2ac75664053e64cb69411f7c32                          Up 24 seconds (healthy)     4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
reconciler       messenger-lab6-reconciler-1             mtusi-messenger-lab6-api:dev                                                                                           Up 13 seconds               8080/tcp
redis            messenger-lab6-redis-1                  redis:7.4.1-alpine                                                                                                     Up 24 seconds (healthy)     6379/tcp
relay            messenger-lab6-relay-1                  mtusi-messenger-lab6-api:dev                                                                                           Up 7 seconds                8080/tcp
s3               messenger-lab6-s3-1                     pgsty/minio:RELEASE.2026-08-04T00-00-00Z@sha256:b6bfe7239bfc83fb90d31612d9704d86039dd714f7904b3f1ad68f211e602372       Up 24 seconds (healthy)     9000/tcp
s3-init          messenger-lab6-s3-init-1                pgsty/mc:RELEASE.2026-10-26T00-00-00Z@sha256:ce62c9053c69ce12a527a322345b5ad9f44b5f8a7b8189f82e516f2e3f30f1d8          Exited (0) 14 seconds ago   
secrets-init     messenger-lab6-secrets-init-1           alpine:3.20.3                                                                                                          Exited (0) 24 seconds ago   
tempo            messenger-lab6-tempo-1                  grafana/tempo:2.6.1@sha256:ef4384fce6e8ad22b95b243d8fc165628cda655376fd50e7850536ad89d71d50                            Up 25 seconds               
tools            messenger-lab6-tools-run-68bd7ed38f92   mtusi-messenger-lab6-tools:dev                                                                                         Up 5 seconds                
worker           messenger-lab6-worker-1                 mtusi-messenger-lab6-api:dev                                                                                           Up 7 seconds                8080/tcp

## CPU/RAM-лимиты (NanoCpus: 1e9 = 1 CPU; Memory в байтах)
$ sh -c docker inspect -f '{{.Name}} cpus={{.HostConfig.NanoCpus}} memory={{.HostConfig.Memory}}' $(docker compose ps -aq)
/messenger-lab6-api-1 cpus=500000000 memory=268435456
/messenger-lab6-api-2 cpus=500000000 memory=268435456
/messenger-lab6-grafana-1 cpus=500000000 memory=268435456
/messenger-lab6-lb-1 cpus=250000000 memory=67108864
/messenger-lab6-loki-1 cpus=500000000 memory=536870912
/messenger-lab6-migrate-1 cpus=500000000 memory=536870912
/messenger-lab6-otel-collector-1 cpus=500000000 memory=268435456
/messenger-lab6-postgres-1 cpus=1000000000 memory=536870912
/messenger-lab6-prometheus-1 cpus=500000000 memory=536870912
/messenger-lab6-rabbitmq-1 cpus=500000000 memory=536870912
/messenger-lab6-reconciler-1 cpus=250000000 memory=134217728
/messenger-lab6-redis-1 cpus=250000000 memory=134217728
/messenger-lab6-relay-1 cpus=250000000 memory=134217728
/messenger-lab6-s3-1 cpus=500000000 memory=536870912
/messenger-lab6-s3-init-1 cpus=250000000 memory=268435456
/messenger-lab6-secrets-init-1 cpus=100000000 memory=33554432
/messenger-lab6-tempo-1 cpus=500000000 memory=536870912
/messenger-lab6-tools-run-68bd7ed38f92 cpus=1000000000 memory=268435456
/messenger-lab6-worker-1 cpus=1000000000 memory=805306368

## Опубликованные порты: только LB и Grafana на 127.0.0.1; OTLP, Prometheus, Loki, Tempo наружу не открыты
$ sh -c docker compose ps --format '{{.Service}} {{.Ports}}' | grep -v '^\S* *$' || true
api 8080/tcp
api 8080/tcp
grafana 127.0.0.1:3000->3000/tcp
lb 127.0.0.1:8080->8080/tcp
loki 3100/tcp
otel-collector 4317-4318/tcp, 55678-55679/tcp
postgres 5432/tcp
prometheus 9090/tcp
rabbitmq 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
reconciler 8080/tcp
redis 6379/tcp
relay 8080/tcp
s3 9000/tcp
worker 8080/tcp

## Сети телеметрии: хранилища только во внутренней сети telemetry
$ sh -c for s in otel-collector prometheus loki tempo grafana api worker; do printf '%s: ' $s; docker inspect -f '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}' $(docker compose ps -q $s | head -1); done
otel-collector: messenger-lab6_default messenger-lab6_telemetry 
prometheus: messenger-lab6_telemetry 
loki: messenger-lab6_telemetry 
tempo: messenger-lab6_telemetry 
grafana: messenger-lab6_default messenger-lab6_telemetry 
api: messenger-lab6_default 
worker: messenger-lab6_default 

$ docker network inspect -f {{.Name}} internal={{.Internal}} messenger-lab6_telemetry
messenger-lab6_telemetry internal=true

## Секреты: каждый сервис видит только свои файлы (содержимое не выводится)
$ docker compose exec -T postgres ls /run/secrets
pg_password

$ docker compose exec -T redis ls /run/secrets
redis_password

$ docker compose exec -T s3 ls /run/secrets
s3_root_password
s3_root_user

$ docker compose exec -T api ls /run/secrets
cache_url
database_url
s3_access_key_id
s3_secret_access_key

$ docker compose exec -T reconciler ls /run/secrets
database_url
s3_access_key_id
s3_secret_access_key

$ docker compose exec -T relay ls /run/secrets
broker_url
database_url

$ docker compose exec -T worker ls /run/secrets
broker_url
database_url
s3_access_key_id
s3_secret_access_key

$ docker compose exec -T grafana ls /run/secrets
admin_password

$ docker compose exec -T rabbitmq ls /etc/rabbitmq/conf.d
10-messenger.conf

$ docker compose exec -T lb sh -c ls /run/secrets 2>/dev/null || echo "no /run/secrets"
no /run/secrets

## Версии
$ docker compose exec -T lb haproxy -v
HAProxy version 3.0.6-c2c0090 2024/11/07 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2029.
Known bugs: http://www.haproxy.org/bugs/bugs-3.0.6.html
Running on: Linux 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64

$ docker compose exec -T postgres postgres --version
postgres (PostgreSQL) 17.2

$ docker compose exec -T redis redis-server --version
Redis server v=7.4.1 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=a93ce81042b3a6d7

$ docker compose exec -T s3 minio --version
minio version RELEASE.2026-08-04T00-00-00Z (commit-id=d88f46ccee345a9c2fabe2d221d9a9e56bc11aec)
Runtime: go1.26.5 linux/amd64
License: GNU AGPLv3 - https://www.gnu.org/licenses/agpl-3.0.html
Copyright: 2015-2026 MinIO, Inc.

$ docker compose exec -T rabbitmq rabbitmqctl -q version
4.0.5

$ sh -c docker compose images otel-collector prometheus loki tempo grafana
CONTAINER                         REPOSITORY                             TAG                 IMAGE ID            SIZE
messenger-lab6-grafana-1          grafana/grafana                        <none>              d8ea37798ccc        133MB
messenger-lab6-loki-1             grafana/loki                           <none>              8af2de1abbdd        33.3MB
messenger-lab6-otel-collector-1   otel/opentelemetry-collector-contrib   <none>              d2da12c4336a        74.3MB
messenger-lab6-prometheus-1       prom/prometheus                        <none>              6559acbd5d77        117MB
messenger-lab6-tempo-1            grafana/tempo                          <none>              ef4384fce6e8        52.4MB

## Топология брокера: durable quorum-очереди, delivery-limit и DLQ
$ docker compose exec -T rabbitmq rabbitmqctl -q list_queues name type durable arguments messages
name	type	durable	arguments	messages
attachment.jobs	quorum	true	[{"x-queue-type","quorum"},{"x-delivery-limit",20},{"x-dead-letter-exchange",[]},{"x-dead-letter-routing-key","attachment.jobs.dlq"}]	0
attachment.jobs.dlq	quorum	true	[{"x-queue-type","quorum"}]	0

$ docker compose exec -T rabbitmq rabbitmqctl -q list_consumers queue_name prefetch_count ack_required
queue_name	ack_required	prefetch_count
attachment.jobs	true	2

## Таблицы
$ docker compose exec -T postgres psql -U messenger -d messenger -c \d attachments -c \d attachment_variants -c \d attachment_jobs -c \d outbox -c \d job_events
                              Table "public.attachments"
    Column    |            Type             | Collation | Nullable |      Default      
--------------+-----------------------------+-----------+----------+-------------------
 id           | uuid                        |           | not null | 
 chat_id      | uuid                        |           | not null | 
 owner_id     | uuid                        |           | not null | 
 filename     | character varying(255)      |           | not null | 
 content_type | character varying(32)       |           | not null | 
 size_bytes   | integer                     |           | not null | 
 sha256       | character(64)               |           | not null | 
 object_key   | character varying(128)      |           | not null | 
 created_at   | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
 updated_at   | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
 staging_key  | character varying(128)      |           |          | 
 status       | character varying(16)       |           | not null | 
 error_code   | character varying(64)       |           |          | 
Indexes:
    "attachments_pkey" PRIMARY KEY, btree (id)
    "attachments_chat_id_idx" btree (chat_id)
    "attachments_object_key_key" UNIQUE, btree (object_key)
    "attachments_owner_id_idx" btree (owner_id)
    "attachments_staging_key_key" UNIQUE, btree (staging_key)
Check constraints:
    "attachments_content_type_allowed" CHECK (content_type::text = ANY (ARRAY['image/png'::character varying, 'image/jpeg'::character varying]::text[]))
    "attachments_error_code_when_failed" CHECK ((status::text = 'failed'::text) = (error_code IS NOT NULL))
    "attachments_filename_not_blank" CHECK (btrim(filename::text) <> ''::text)
    "attachments_sha256_format" CHECK (sha256 ~ '^[a-f0-9]{64}$'::text)
    "attachments_size_range" CHECK (size_bytes >= 1 AND size_bytes <= 10485760)
    "attachments_status_allowed" CHECK (status::text = ANY (ARRAY['queued'::character varying, 'processing'::character varying, 'ready'::character varying, 'failed'::character varying]::text[]))
Foreign-key constraints:
    "attachments_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON UPDATE CASCADE ON DELETE CASCADE
    "attachments_owner_id_fkey" FOREIGN KEY (owner_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT
Referenced by:
    TABLE "attachment_jobs" CONSTRAINT "attachment_jobs_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE "attachment_variants" CONSTRAINT "attachment_variants_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE "message_attachments" CONSTRAINT "message_attachments_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON UPDATE CASCADE

                            Table "public.attachment_variants"
      Column      |            Type             | Collation | Nullable |      Default      
------------------+-----------------------------+-----------+----------+-------------------
 attachment_id    | uuid                        |           | not null | 
 pipeline_version | integer                     |           | not null | 
 name             | character varying(16)       |           | not null | 
 content_type     | character varying(32)       |           | not null | 
 object_key       | character varying(128)      |           | not null | 
 size_bytes       | integer                     |           | not null | 
 width            | integer                     |           | not null | 
 height           | integer                     |           | not null | 
 sha256           | character(64)               |           | not null | 
 created_at       | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
Indexes:
    "attachment_variants_pkey" PRIMARY KEY, btree (attachment_id, pipeline_version, name)
    "attachment_variants_object_key_key" UNIQUE, btree (object_key)
Check constraints:
    "attachment_variants_content_type_allowed" CHECK (content_type::text = ANY (ARRAY['image/jpeg'::character varying, 'image/png'::character varying, 'image/webp'::character varying]::text[]))
    "attachment_variants_name_allowed" CHECK (name::text = ANY (ARRAY['thumbnail'::character varying, 'crop'::character varying, 'optimized'::character varying]::text[]))
    "attachment_variants_positive" CHECK (pipeline_version >= 1 AND size_bytes >= 1 AND width >= 1 AND height >= 1)
    "attachment_variants_sha256_format" CHECK (sha256 ~ '^[a-f0-9]{64}$'::text)
Foreign-key constraints:
    "attachment_variants_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON UPDATE CASCADE ON DELETE CASCADE

                              Table "public.attachment_jobs"
      Column      |            Type             | Collation | Nullable |      Default      
------------------+-----------------------------+-----------+----------+-------------------
 id               | uuid                        |           | not null | 
 attachment_id    | uuid                        |           | not null | 
 pipeline_version | integer                     |           | not null | 
 status           | character varying(16)       |           | not null | 
 attempt          | integer                     |           | not null | 
 max_attempts     | integer                     |           | not null | 
 next_attempt_at  | timestamp(3) with time zone |           | not null | 
 lease_owner      | uuid                        |           |          | 
 lease_until      | timestamp(3) with time zone |           |          | 
 error_code       | character varying(64)       |           |          | 
 last_error       | character varying(200)      |           |          | 
 created_at       | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
 updated_at       | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
 finished_at      | timestamp(3) with time zone |           |          | 
Indexes:
    "attachment_jobs_pkey" PRIMARY KEY, btree (id)
    "attachment_jobs_attachment_id_pipeline_version_key" UNIQUE, btree (attachment_id, pipeline_version)
    "attachment_jobs_status_lease_until_idx" btree (status, lease_until)
Check constraints:
    "attachment_jobs_attempt_range" CHECK (pipeline_version >= 1 AND attempt >= 1 AND attempt <= max_attempts)
    "attachment_jobs_error_code_when_failed" CHECK ((status::text = 'failed'::text) = (error_code IS NOT NULL))
    "attachment_jobs_lease_when_processing" CHECK (status::text <> 'processing'::text OR lease_owner IS NOT NULL AND lease_until IS NOT NULL)
    "attachment_jobs_status_allowed" CHECK (status::text = ANY (ARRAY['queued'::character varying, 'processing'::character varying, 'ready'::character varying, 'failed'::character varying]::text[]))
Foreign-key constraints:
    "attachment_jobs_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id) ON UPDATE CASCADE ON DELETE CASCADE
Referenced by:
    TABLE "job_events" CONSTRAINT "job_events_job_id_fkey" FOREIGN KEY (job_id) REFERENCES attachment_jobs(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE "outbox" CONSTRAINT "outbox_job_id_fkey" FOREIGN KEY (job_id) REFERENCES attachment_jobs(id) ON UPDATE CASCADE ON DELETE CASCADE

                                           Table "public.outbox"
      Column      |            Type             | Collation | Nullable |              Default               
------------------+-----------------------------+-----------+----------+------------------------------------
 id               | bigint                      |           | not null | nextval('outbox_id_seq'::regclass)
 job_id           | uuid                        |           | not null | 
 payload          | jsonb                       |           | not null | 
 available_at     | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
 published_at     | timestamp(3) with time zone |           |          | 
 publish_attempts | integer                     |           | not null | 0
 created_at       | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
Indexes:
    "outbox_pkey" PRIMARY KEY, btree (id)
    "outbox_job_id_idx" btree (job_id)
    "outbox_published_at_available_at_idx" btree (published_at, available_at)
Foreign-key constraints:
    "outbox_job_id_fkey" FOREIGN KEY (job_id) REFERENCES attachment_jobs(id) ON UPDATE CASCADE ON DELETE CASCADE

                                        Table "public.job_events"
   Column   |            Type             | Collation | Nullable |                Default                 
------------+-----------------------------+-----------+----------+----------------------------------------
 id         | bigint                      |           | not null | nextval('job_events_id_seq'::regclass)
 job_id     | uuid                        |           | not null | 
 attempt    | integer                     |           | not null | 
 event      | character varying(32)       |           | not null | 
 detail     | character varying(200)      |           |          | 
 created_at | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP
Indexes:
    "job_events_pkey" PRIMARY KEY, btree (id)
    "job_events_job_id_idx" btree (job_id)
Foreign-key constraints:
    "job_events_job_id_fkey" FOREIGN KEY (job_id) REFERENCES attachment_jobs(id) ON UPDATE CASCADE ON DELETE CASCADE


## Миграции: отдельный one-shot сервис, повторный запуск ничего не применяет, схема совпадает с БД
$ docker compose run --rm migrate
 Container messenger-lab6-secrets-init-1  Created
 Container messenger-lab6-postgres-1  Running
 Container messenger-lab6-secrets-init-1  Starting
 Container messenger-lab6-secrets-init-1  Started
 Container messenger-lab6-secrets-init-1  Waiting
 Container messenger-lab6-secrets-init-1  Exited
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "messenger", schema "public" at "postgres:5432"

5 migrations found in prisma/migrations


No pending migrations to apply.

$ docker compose run --rm --no-deps migrate sh -c export DATABASE_URL="$(cat "$DATABASE_URL_FILE")"; npx prisma migrate diff --from-url "$DATABASE_URL" --to-schema-datamodel prisma/schema.prisma --exit-code
No difference detected.


$ docker compose exec -T postgres psql -U messenger -d messenger -c SELECT migration_name, finished_at FROM _prisma_migrations ORDER BY started_at
         migration_name          |          finished_at          
---------------------------------+-------------------------------
 20261021000000_init             | 2026-11-20 14:30:37.860315+00
 20261021010000_auth_sessions    | 2026-11-20 14:30:37.880522+00
 20261101000000_idempotency_keys | 2026-11-20 14:30:37.895909+00
 20261105000000_attachments      | 2026-11-20 14:30:37.918762+00
 20261115000000_attachment_jobs  | 2026-11-20 14:30:37.951618+00
(5 rows)


