diff --git a/compose.yaml b/compose.yaml index 85e4ab8..93a1b6c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -91,6 +91,30 @@ services: networks: - internal + mc-init: + image: pgsty/silo:RELEASE.2026-09-16T00-00-00Z + restart: "no" + depends_on: + minio: + condition: service_healthy + entrypoint: ["/bin/sh", "/init.sh"] + environment: + MINIO_ENDPOINT: "http://minio:9000" + MINIO_BUCKET: "${S3_BUCKET:-messenger-attachments}" + ROOT_USER_FILE: /run/secrets/minio_root_user + ROOT_PASSWORD_FILE: /run/secrets/minio_root_password + API_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id + API_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key + volumes: + - ./infra/minio-init.sh:/init.sh:ro + secrets: + - minio_root_user + - minio_root_password + - s3_access_key_id + - s3_secret_access_key + networks: + - internal + migrate: build: context: . diff --git a/infra/minio-init.sh b/infra/minio-init.sh new file mode 100644 index 0000000..320cca4 --- /dev/null +++ b/infra/minio-init.sh @@ -0,0 +1,50 @@ +#!/bin/sh +set -eu + +: "${MINIO_ENDPOINT:?MINIO_ENDPOINT не задан}" +: "${MINIO_BUCKET:?MINIO_BUCKET не задан}" +: "${ROOT_USER_FILE:?ROOT_USER_FILE не задан}" +: "${ROOT_PASSWORD_FILE:?ROOT_PASSWORD_FILE не задан}" +: "${API_ACCESS_KEY_ID_FILE:?API_ACCESS_KEY_ID_FILE не задан}" +: "${API_SECRET_ACCESS_KEY_FILE:?API_SECRET_ACCESS_KEY_FILE не задан}" + +ROOT_USER="$(cat "$ROOT_USER_FILE")" +ROOT_PASS="$(cat "$ROOT_PASSWORD_FILE")" +API_ID="$(cat "$API_ACCESS_KEY_ID_FILE")" +API_SECRET="$(cat "$API_SECRET_ACCESS_KEY_FILE")" + +mc alias set bootstrap "$MINIO_ENDPOINT" "$ROOT_USER" "$ROOT_PASS" --api S3v4 >/dev/null + +mc mb --ignore-existing "bootstrap/$MINIO_BUCKET" + +if ! mc admin user info bootstrap "$API_ID" >/dev/null 2>&1; then + mc admin user add bootstrap "$API_ID" "$API_SECRET" +fi + +POLICY_FILE="/tmp/minio-policy.json" +trap 'rm -f "$POLICY_FILE"' EXIT +cat >"$POLICY_FILE" </dev/null | grep -qw 'messenger-api'; then + mc admin policy create bootstrap messenger-api "$POLICY_FILE" +fi + +mc admin policy attach bootstrap messenger-api --user "$API_ID" 2>/dev/null || true + +echo "minio bootstrap в норме: bucket=${MINIO_BUCKET} user=${API_ID}" \ No newline at end of file