Files
mtusi2026lab7/infra/minio-bootstrap.sh
T
Zyulina_Ekaterina 5b8c2a22e1
Skeleton contracts / contracts (pull_request) Blocked by required conditions
ЛР7 - БВТ2302 - Зюлина - на 3
2026-11-29 12:55:09 +03:00

24 lines
1.9 KiB
Bash

#!/bin/sh
set -eu
until mc alias set local https://minio:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" >/dev/null 2>&1; do sleep 2; done
mc mb --ignore-existing "local/$S3_BUCKET"
mc anonymous set none "local/$S3_BUCKET"
cat >/tmp/api-policy.json <<EOF
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::$S3_BUCKET"],"Condition":{"StringLike":{"s3:prefix":["original/*","variants/*"]}}},{"Effect":"Allow","Action":["s3:PutObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/staging/*"]},{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/original/*","arn:aws:s3:::$S3_BUCKET/variants/*"]}]}
EOF
cat >/tmp/worker-policy.json <<EOF
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::$S3_BUCKET"],"Condition":{"StringLike":{"s3:prefix":["staging/*","original/*","variants/*"]}}},{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/staging/*"]},{"Effect":"Allow","Action":["s3:PutObject","s3:DeleteObject"],"Resource":["arn:aws:s3:::$S3_BUCKET/original/*","arn:aws:s3:::$S3_BUCKET/variants/*","arn:aws:s3:::$S3_BUCKET/staging/*"]}]}
EOF
for policy in attachments-api attachments-worker; do
file=/tmp/api-policy.json; [ "$policy" = attachments-worker ] && file=/tmp/worker-policy.json
if ! mc admin policy info local "$policy" >/dev/null 2>&1; then
mc admin policy create local "$policy" "$file"
fi
done
for credential in "$S3_ACCESS_KEY:$S3_SECRET_KEY:attachments-api" "$S3_WORKER_ACCESS_KEY:$S3_WORKER_SECRET_KEY:attachments-worker"; do
access=${credential%%:*}; rest=${credential#*:}; secret=${rest%%:*}; policy=${rest##*:}
if ! mc admin user info local "$access" >/dev/null 2>&1; then mc admin user add local "$access" "$secret" >/dev/null; fi
mc admin policy attach local "$policy" --user "$access" >/dev/null
done