57 lines
1.3 KiB
Bash
57 lines
1.3 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
# Applies an S3 lifecycle configuration to the docs bucket.
|
|
#
|
|
# This is an operator tool (it has side effects). It is still automatable and scriptable.
|
|
#
|
|
# Required env:
|
|
# - S3_ENDPOINT
|
|
# - S3_REGION
|
|
# - S3_BUCKET_DOCS
|
|
#
|
|
# Optional env:
|
|
# - S3_LIFECYCLE_JSON (path to JSON file; default: docs/usage/s3_lifecycle_docs_default.json)
|
|
#
|
|
# Usage:
|
|
# export S3_ENDPOINT=...
|
|
# export S3_REGION=...
|
|
# export S3_BUCKET_DOCS=...
|
|
# sh docker/scripts/s3_apply_lifecycle_docs.sh
|
|
|
|
need() {
|
|
name="$1"
|
|
val="$(printenv "$name" 2>/dev/null || true)"
|
|
if [ -z "$val" ]; then
|
|
echo "missing env: $name" >&2
|
|
exit 2
|
|
fi
|
|
}
|
|
|
|
need S3_ENDPOINT
|
|
need S3_REGION
|
|
need S3_BUCKET_DOCS
|
|
|
|
if ! command -v aws >/dev/null 2>&1; then
|
|
echo "missing dependency: aws (AWS CLI v2 recommended)" >&2
|
|
exit 2
|
|
fi
|
|
|
|
export AWS_EC2_METADATA_DISABLED=true
|
|
export AWS_DEFAULT_REGION="$S3_REGION"
|
|
export AWS_REGION="$S3_REGION"
|
|
|
|
S3_LIFECYCLE_JSON="${S3_LIFECYCLE_JSON:-docs/usage/s3_lifecycle_docs_default.json}"
|
|
if [ ! -f "$S3_LIFECYCLE_JSON" ]; then
|
|
echo "missing lifecycle config file: $S3_LIFECYCLE_JSON" >&2
|
|
exit 2
|
|
fi
|
|
|
|
aws s3api put-bucket-lifecycle-configuration \
|
|
--endpoint-url "$S3_ENDPOINT" \
|
|
--bucket "$S3_BUCKET_DOCS" \
|
|
--lifecycle-configuration "file://$S3_LIFECYCLE_JSON" >/dev/null
|
|
|
|
echo "ok: applied lifecycle config to bucket $S3_BUCKET_DOCS"
|
|
|