Embed the checked lab 5 preparation: RabbitMQ 4.1.8 pinned by digest with a fixed node hostname, a volume, a read-only root and 512 MiB, whose topology (vhost messenger, exchange attachments, quorum queue attachments.process with a dead letter exchange, delivery limit 10 and reject-publish overflow) and users come from definitions imported on every boot. The relay may only write to the exchange, the worker may only read the queue, configure belongs to the operator, there is no guest, and the management UI is published on 127.0.0.1 only. The relay and the worker run from the application image with a heartbeat health check, init, a read-only root and their own limits; the worker gets its own S3 user that reads staging and writes originals and variants, and s3-init creates it idempotently. The API has no broker credentials. make secrets also creates the broker passwords, URLs, hashed users and the worker S3 keys; the restart hook now stops the balancer, the API, the relay and the worker and restarts PostgreSQL, Valkey, S3 and the broker with their volumes; worker.sh and broker.sh stop, start and inspect the processes for the failure demonstrations; the limits policy covers the new services and the loopback UI port. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
27 lines
1.6 KiB
Bash
Executable File
27 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
secret() { tr -d '\r\n' < "/run/secrets/$1"; }
|
|
bucket="${S3_BUCKET:-messenger-attachments}"
|
|
endpoint="${S3_ENDPOINT:-http://s3:9000}"
|
|
policy="${S3_API_POLICY:-messenger-api}"
|
|
RC_HOST_root="${endpoint%%://*}://$(secret s3_root_user):$(secret s3_root_password)@${endpoint#*://}"
|
|
export RC_HOST_root
|
|
api_key=$(secret s3_access_key_id)
|
|
rc ready root --timeout 10 >/dev/null
|
|
rc bucket create --ignore-existing "root/$bucket" >/dev/null
|
|
rc bucket anonymous set private "root/$bucket" >/dev/null
|
|
sed "s/messenger-attachments/$bucket/g" /s3/api-policy.json > /tmp/api-policy.json
|
|
rc admin policy create root "$policy" /tmp/api-policy.json >/dev/null
|
|
rc admin user add root "$api_key" "$(secret s3_secret_access_key)" >/dev/null
|
|
rc admin policy attach root "$policy" --user "$api_key" >/dev/null
|
|
worker_key=$(secret s3_worker_access_key_id)
|
|
sed "s/messenger-attachments/$bucket/g" /s3/worker-policy.json > /tmp/worker-policy.json
|
|
rc admin policy create root messenger-worker /tmp/worker-policy.json >/dev/null
|
|
rc admin user add root "$worker_key" "$(secret s3_worker_secret_access_key)" >/dev/null
|
|
rc admin policy attach root messenger-worker --user "$worker_key" >/dev/null
|
|
rc bucket lifecycle rule import "root/$bucket" /s3/lifecycle.json >/dev/null
|
|
rc bucket anonymous get "root/$bucket" --json | grep -q '"permission": *"private"'
|
|
rc admin user info root "$api_key" --json | grep -q "\"$policy\""
|
|
rc admin user info root "$worker_key" --json | grep -q '"messenger-worker"'
|
|
echo "s3-init: bucket=$bucket anonymous=private policy=$policy worker=messenger-worker lifecycle=abort-incomplete-uploads"
|