Skip to content

Commit f17e63a

Browse files
committed
ci: bake CDN default MIRROR_URL into mirrored install.sh
The copy served from the CDN now defaults MIRROR_URL to the CDN (injected at upload time via the new MIRROR_PUBLIC_URL secret), so `curl <cdn>/install.sh | sh` pulls binaries from the CDN without the caller passing MIRROR_URL. The repo / GitHub copy stays generic (defaults to GitHub). A grep guard fails the job if the default line ever stops matching, so the injection can't silently no-op.
1 parent f05115f commit f17e63a

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

.github/workflows/install-scripts.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
BUCKET: ${{ secrets.MIRROR_S3_BUCKET }}
4646
ENDPOINT: ${{ secrets.MIRROR_S3_ENDPOINT }}
4747
PREFIX: ${{ secrets.MIRROR_S3_PATH_PREFIX }}
48+
MIRROR_PUBLIC_URL: ${{ secrets.MIRROR_PUBLIC_URL }}
4849
run: |
4950
set -eu
5051
if [ -z "${BUCKET:-}" ] || [ -z "${ENDPOINT:-}" ]; then
@@ -59,8 +60,18 @@ jobs:
5960
aws configure set default.response_checksum_validation when_required
6061
PREFIX="${PREFIX#/}"; PREFIX="${PREFIX%/}"
6162
63+
# Bake the CDN as the default MIRROR_URL into the copy we serve from the
64+
# CDN, so `curl <cdn>/install.sh | sh` pulls binaries from the CDN with
65+
# no MIRROR_URL arg. The repo / GitHub copy stays generic (GitHub default).
66+
src_sh=install.sh
67+
if [ -n "${MIRROR_PUBLIC_URL:-}" ]; then
68+
pub="${MIRROR_PUBLIC_URL%/}${PREFIX:+/${PREFIX}}"
69+
sed "s#MIRROR_URL=\"\${MIRROR_URL:-}\"#MIRROR_URL=\"\${MIRROR_URL:-${pub}}\"#" install.sh > /tmp/install.sh
70+
grep -q "MIRROR_URL:-${pub}" /tmp/install.sh || { echo "ERROR: MIRROR_URL default not injected (install.sh default line changed?)" >&2; exit 1; }
71+
src_sh=/tmp/install.sh
72+
fi
6273
sh_key="${PREFIX:+${PREFIX}/}install.sh"
63-
aws --endpoint-url="$ENDPOINT" s3 cp install.sh "s3://${BUCKET}/${sh_key}" \
74+
aws --endpoint-url="$ENDPOINT" s3 cp "$src_sh" "s3://${BUCKET}/${sh_key}" \
6475
--cache-control "public, max-age=300" \
6576
--content-type "text/x-shellscript; charset=utf-8"
6677

.github/workflows/release.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
BUCKET: ${{ secrets.MIRROR_S3_BUCKET }}
5454
ENDPOINT: ${{ secrets.MIRROR_S3_ENDPOINT }}
5555
PREFIX: ${{ secrets.MIRROR_S3_PATH_PREFIX }}
56+
MIRROR_PUBLIC_URL: ${{ secrets.MIRROR_PUBLIC_URL }}
5657
VERSION: ${{ github.ref_name }}
5758
run: |
5859
set -eu
@@ -102,8 +103,18 @@ jobs:
102103
# ships a stale/missing installer (install-scripts.yml only fires when
103104
# install.sh/.ps1 change on main; the scripts are version-agnostic, so
104105
# re-uploading the current copy here is the belt-and-suspenders guarantee).
106+
# Bake the CDN as the default MIRROR_URL into the served copy so
107+
# `curl <cdn>/install.sh | sh` pulls binaries from the CDN with no
108+
# MIRROR_URL arg. The repo / GitHub copy stays generic (GitHub default).
109+
src_sh=install.sh
110+
if [ -n "${MIRROR_PUBLIC_URL:-}" ]; then
111+
pub="${MIRROR_PUBLIC_URL%/}${PREFIX:+/${PREFIX}}"
112+
sed "s#MIRROR_URL=\"\${MIRROR_URL:-}\"#MIRROR_URL=\"\${MIRROR_URL:-${pub}}\"#" install.sh > /tmp/install.sh
113+
grep -q "MIRROR_URL:-${pub}" /tmp/install.sh || { echo "ERROR: MIRROR_URL default not injected (install.sh default line changed?)" >&2; exit 1; }
114+
src_sh=/tmp/install.sh
115+
fi
105116
sh_key="${PREFIX:+${PREFIX}/}install.sh"
106-
aws --endpoint-url="$ENDPOINT" s3 cp install.sh "s3://${BUCKET}/${sh_key}" \
117+
aws --endpoint-url="$ENDPOINT" s3 cp "$src_sh" "s3://${BUCKET}/${sh_key}" \
107118
--cache-control "public, max-age=300" \
108119
--content-type "text/x-shellscript; charset=utf-8"
109120
ps1_key="${PREFIX:+${PREFIX}/}install.ps1"

0 commit comments

Comments
 (0)