25 lines
1023 B
Bash
25 lines
1023 B
Bash
#!/bin/sh
|
|
set -eu
|
|
mkdir -p /tmp/mc/certs/CAs
|
|
cp /run/tls/ca.crt /tmp/mc/certs/CAs/lab.crt
|
|
export MC_CONFIG_DIR=/tmp/mc
|
|
attempt=0
|
|
until mc alias set store https://s3:9000 "$(cat /run/secrets/minio_root_user)" "$(cat /run/secrets/minio_root_password)" >/dev/null 2>&1; do
|
|
attempt=$((attempt + 1))
|
|
if [ "$attempt" -ge 60 ]; then
|
|
echo "MinIO unavailable over trusted HTTPS" >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
mc mb --ignore-existing store/messenger-attachments >/dev/null
|
|
printf messenger-ready | mc pipe store/messenger-attachments/system/readiness >/dev/null
|
|
for role in api worker; do
|
|
mc admin user add store "lab7-$role" "$(cat "/run/secrets/s3_$role")" >/dev/null
|
|
mc admin policy create store "lab7-$role" "/policies/$role.json" >/dev/null
|
|
if ! mc admin user info --json store "lab7-$role" | grep -q "\"policyName\":\"lab7-$role\""; then
|
|
mc admin policy attach store "lab7-$role" --user "lab7-$role" >/dev/null
|
|
fi
|
|
done
|
|
echo "MinIO bucket and two scoped policies are ready."
|