mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
One site/cloudflare.config.ts defines the production Worker hex (anoma.ly/hex, bucket hex-production-files) and the dev Worker hex-dev (dev.anoma.ly/hex, bucket hex-dev-files), deployed only from CI with cf deploy --prebuilt --mode. The Worker serves the site and the release bucket; apps, scripts, the release workflow, and docs use https://anoma.ly/hex/files. Staging releases publish to the dev bucket; stable releases deploy the production site.
31 lines
1.2 KiB
Shell
Executable file
31 lines
1.2 KiB
Shell
Executable file
#!/bin/sh
|
|
# Upload one object to a Hex files bucket (HEX_RELEASE_BUCKET:
|
|
# hex-production-files or hex-dev-files) through its S3 API, using the
|
|
# bucket-scoped CI credentials (R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY).
|
|
# HEX_RELEASE_PREFIX (e.g. staging/<run>/) is prepended to every key.
|
|
#
|
|
# r2-put.sh <key> <file> <content-type> <cache-control> [content-disposition]
|
|
set -eu
|
|
|
|
[ $# -ge 4 ] || {
|
|
echo "Usage: $0 <key> <file> <content-type> <cache-control> [content-disposition]" >&2
|
|
exit 1
|
|
}
|
|
: "${R2_ACCESS_KEY_ID:?Set R2_ACCESS_KEY_ID}"
|
|
: "${R2_SECRET_ACCESS_KEY:?Set R2_SECRET_ACCESS_KEY}"
|
|
account=${R2_ACCOUNT_ID:-15d29c8639fd3733b1b5486a2acfd968}
|
|
bucket=${HEX_RELEASE_BUCKET:?Set HEX_RELEASE_BUCKET}
|
|
key="${HEX_RELEASE_PREFIX:-}$1"
|
|
test -f "$2"
|
|
|
|
# The secret travels in a curl config on stdin, never in argv.
|
|
printf 'user = "%s:%s"\n' "$R2_ACCESS_KEY_ID" "$R2_SECRET_ACCESS_KEY" |
|
|
curl --config - --fail-with-body --silent --show-error --retry 3 \
|
|
--aws-sigv4 aws:amz:auto:s3 \
|
|
--header "Content-Type: $3" \
|
|
--header "Cache-Control: $4" \
|
|
${5:+--header} ${5:+"Content-Disposition: $5"} \
|
|
--upload-file "$2" \
|
|
--output /dev/null \
|
|
"https://$account.r2.cloudflarestorage.com/$bucket/$key"
|
|
echo "Uploaded $key" >&2
|