Files

31 lines
973 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# 判空:没配凭据时跳过(Phase 0 本地/未配 OSS 时不阻塞)
if [ -z "${OSS_ACCESS_KEY_ID:-}" ] || [ -z "${OSS_BUCKET:-}" ]; then
echo "[deploy-oss] 未配置 OSS 凭据,跳过同步。"
exit 0
fi
: "${OSS_ACCESS_KEY_SECRET:?需 OSS_ACCESS_KEY_SECRET}"
: "${OSS_ENDPOINT:?需 OSS_ENDPOINT}"
: "${OSS_BUCKET:?需 OSS_BUCKET}"
DIST_DIR="${1:-dist}"
[ -d "$DIST_DIR" ] || { echo "[deploy-oss] $DIST_DIR 不存在,请先 build"; exit 1; }
echo "[deploy-oss] 同步 $DIST_DIR → oss://$OSS_BUCKET/"
ossutil sync "$DIST_DIR" "oss://$OSS_BUCKET/" \
-i "$OSS_ACCESS_KEY_ID" \
-k "$OSS_ACCESS_KEY_SECRET" \
-e "$OSS_ENDPOINT" \
--force --delete
echo "[deploy-oss] 刷新 CDN(如配了 CDN_DOMAIN"
if [ -n "${CDN_DOMAIN:-}" ]; then
ossutil cdn refresh --dirs "https://${CDN_DOMAIN}/" \
-i "$OSS_ACCESS_KEY_ID" -k "$OSS_ACCESS_KEY_SECRET" -e "$OSS_ENDPOINT" || true
fi
echo "[deploy-oss] 完成"