23 lines
1.1 KiB
Bash
23 lines
1.1 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
set +x
|
|
CA=/root/.mc/certs/CAs/service-ca.crt
|
|
[ "$S3_BUCKET" = "messenger-attachments" ] || { echo "S3_BUCKET must remain messenger-attachments because IAM policies are scoped to that bucket" >&2; exit 2; }
|
|
ready=0
|
|
for attempt in $(seq 1 30); do
|
|
if mc alias set local "https://minio:9000" "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" --api S3v4 >/dev/null 2>&1; then
|
|
ready=1
|
|
break
|
|
fi
|
|
sleep 2
|
|
done
|
|
[ "$ready" -eq 1 ] || { echo "S3 service did not become ready" >&2; exit 1; }
|
|
mc mb --ignore-existing "local/${S3_BUCKET}"
|
|
mc admin policy create local messenger-api /policies/api-policy.json >/dev/null 2>&1 || true
|
|
mc admin policy create local messenger-worker /policies/worker-policy.json >/dev/null 2>&1 || true
|
|
mc admin user add local "$S3_ACCESS_KEY" "$S3_SECRET_KEY" || true
|
|
mc admin user add local "$S3_WORKER_ACCESS_KEY" "$S3_WORKER_SECRET_KEY" || true
|
|
mc admin policy attach local messenger-api --user "$S3_ACCESS_KEY"
|
|
mc admin policy attach local messenger-worker --user "$S3_WORKER_ACCESS_KEY"
|
|
echo "S3 bucket and scoped API/worker users are ready. Secret values were not printed."
|