ci(docker): prune old image versions

This commit is contained in:
2026-07-09 10:23:34 +08:00
parent fc92c3a5d5
commit e8b745d991
6 changed files with 255 additions and 35 deletions
+7 -32
View File
@@ -5,28 +5,6 @@ warn() {
printf 'Notification warning: %s\n' "$*" >&2
}
generate_chat_id() {
if [ -n "${ACTION_NOTIFY_CHAT_ID:-}" ]; then
printf '%s' "$ACTION_NOTIFY_CHAT_ID"
return 0
fi
if command -v node >/dev/null 2>&1; then
node <<'NODE'
const { randomUUID } = require("node:crypto");
process.stdout.write(`oc_${randomUUID().replaceAll("-", "")}`);
NODE
return 0
fi
if command -v openssl >/dev/null 2>&1; then
printf 'oc_%s' "$(openssl rand -hex 16)"
return 0
fi
printf 'oc_%s%s' "$(date +%s)" "$$"
}
branch_name="${BRANCH_NAME:-${GITHUB_REF_NAME:-}}"
if [ -z "$branch_name" ] && [ -n "${GITHUB_REF:-}" ]; then
branch_name="${GITHUB_REF#refs/heads/}"
@@ -43,9 +21,11 @@ if [ -z "$short_sha" ]; then
short_sha="unknown"
fi
base_url="${FLOW_NOTIFY_BASE_URL:-https://flow.banlv-ai.com}"
base_url="${base_url%/}"
chat_id="$(generate_chat_id)"
notify_url="${ACTION_NOTIFY_WEBHOOK_URL:-}"
if [ -z "$notify_url" ]; then
warn "ACTION_NOTIFY_WEBHOOK_URL is not configured, skip notification."
exit 0
fi
deploy_env="${DEPLOY_ENV:-unknown}"
image_tag="${IMAGE_VERSION_TAG:-unknown}"
@@ -84,11 +64,6 @@ process.stdout.write(JSON.stringify(payload));
NODE
)"
encoded_chat_id="$(
node -e 'process.stdout.write(encodeURIComponent(process.argv[1] || ""))' "$chat_id"
)"
notify_url="$base_url/webhooks/action-notify?chat_id=$encoded_chat_id"
if [ "${FLOW_NOTIFY_DRY_RUN:-}" = "1" ]; then
printf 'Action notification dry run URL: %s\n' "$notify_url"
printf 'Action notification dry run payload: %s\n' "$payload"
@@ -99,8 +74,8 @@ if ! curl -fsS \
-X POST "$notify_url" \
-H "Content-Type: application/json" \
-d "$payload" >/dev/null; then
warn "failed to send action notification for $chat_id"
warn "failed to send action notification."
exit 0
fi
echo "Sent action notification for $chat_id."
echo "Sent action notification."