Bash · 1073 bytes Raw Blame History
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: AGPL-3.0-or-later
3 #
4 # Apply the Actions object retention policy to the primary object bucket.
5 # Runs from the operator laptop after s3cmd is configured for the same
6 # DigitalOcean Spaces account used by shithub's S3 object storage.
7 #
8 # Usage:
9 # SHITHUB_OBJECT_BUCKET=shithub-prod-objects \
10 # ./deploy/cutover/apply-actions-lifecycle.sh
11
12 set -euo pipefail
13
14 BUCKET="${SHITHUB_OBJECT_BUCKET:?set SHITHUB_OBJECT_BUCKET to the object bucket name}"
15 LIFECYCLE_FILE="${LIFECYCLE_FILE:-deploy/spaces/actions-lifecycle.json}"
16 S3CMD="${S3CMD:-s3cmd}"
17
18 if ! command -v "$S3CMD" >/dev/null 2>&1; then
19 echo "fatal: $S3CMD not on PATH; install/configure s3cmd first" >&2
20 exit 2
21 fi
22 if [[ ! -f "$LIFECYCLE_FILE" ]]; then
23 echo "fatal: lifecycle file not found: $LIFECYCLE_FILE" >&2
24 exit 2
25 fi
26
27 echo "applying Actions lifecycle to s3://$BUCKET from $LIFECYCLE_FILE" >&2
28 "$S3CMD" setlifecycle "$LIFECYCLE_FILE" "s3://$BUCKET"
29
30 echo "current lifecycle for s3://$BUCKET:" >&2
31 "$S3CMD" getlifecycle "s3://$BUCKET"