Implement durable S3 attachments and reconciliation
This commit is contained in:
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
# Generate the local, synthetic stand's secrets and .env.
|
||||
# Values are written to ./secrets (git-ignored, mode 0600) and never printed.
|
||||
# Re-running is safe: existing files are kept unless FORCE=1.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
PYTHON="${PYTHON:-python}"
|
||||
SECRETS_DIR="${SECRETS_DIR:-secrets}"
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
cp .env.example .env
|
||||
printf '%s\n' "created .env from .env.example"
|
||||
fi
|
||||
|
||||
mkdir -p "$SECRETS_DIR"
|
||||
chmod 700 "$SECRETS_DIR" 2>/dev/null || true
|
||||
|
||||
umask 077
|
||||
|
||||
random_password() {
|
||||
"$PYTHON" -c 'import secrets; print(secrets.token_hex(24))'
|
||||
}
|
||||
|
||||
write_if_missing() {
|
||||
path="$SECRETS_DIR/$1"
|
||||
if [ -f "$path" ] && [ "${FORCE:-0}" != "1" ]; then
|
||||
return 0
|
||||
fi
|
||||
printf '%s' "$2" > "$path"
|
||||
chmod 600 "$path" 2>/dev/null || true
|
||||
}
|
||||
|
||||
postgres_password="$(random_password)"
|
||||
valkey_password="$(random_password)"
|
||||
s3_access_key_id="messenger-api"
|
||||
s3_secret_access_key="$(random_password)"
|
||||
s3_bootstrap_access_key_id="messenger-bootstrap"
|
||||
s3_bootstrap_secret_access_key="$(random_password)"
|
||||
|
||||
write_if_missing postgres_password "$postgres_password"
|
||||
write_if_missing valkey_password "$valkey_password"
|
||||
write_if_missing database_url "postgresql://messenger:${postgres_password}@postgres:5432/messenger"
|
||||
write_if_missing cache_url "redis://:${valkey_password}@valkey:6379/0"
|
||||
write_if_missing s3_access_key_id "$s3_access_key_id"
|
||||
write_if_missing s3_secret_access_key "$s3_secret_access_key"
|
||||
write_if_missing s3_bootstrap_access_key_id "$s3_bootstrap_access_key_id"
|
||||
write_if_missing s3_bootstrap_secret_access_key "$s3_bootstrap_secret_access_key"
|
||||
|
||||
# SeaweedFS consumes an S3 identity policy file. API has only data-plane rights;
|
||||
# bucket creation uses a separate identity unavailable to API processes.
|
||||
if [ ! -f "$SECRETS_DIR/s3.json" ] || [ "${FORCE:-0}" = "1" ]; then
|
||||
cat >"$SECRETS_DIR/s3.json" <<EOF
|
||||
{"identities":[{"name":"messenger-api","credentials":[{"accessKey":"$s3_access_key_id","secretKey":"$s3_secret_access_key"}],"actions":["Read","Write","List","Tagging"]},{"name":"messenger-bootstrap","credentials":[{"accessKey":"$s3_bootstrap_access_key_id","secretKey":"$s3_bootstrap_secret_access_key"}],"actions":["Read","Write","List","Tagging","Admin"]}]}
|
||||
EOF
|
||||
chmod 600 "$SECRETS_DIR/s3.json" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
printf '%s\n' "wrote secrets to $SECRETS_DIR: postgres, valkey, restricted S3 API and bootstrap credentials"
|
||||
printf '%s\n' "next: docker compose --env-file .env up -d --build"
|
||||
Reference in New Issue
Block a user