Files
asset_helper/backend/scripts/push-image.sh
2026-04-25 22:16:51 +08:00

38 lines
967 B
Bash
Executable File
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
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="${SCRIPT_DIR}/../.env.registry"
REGISTRY="registry.fishestlife.com"
if [[ ! -f "$ENV_FILE" ]]; then
echo "错误:找不到 ${ENV_FILE}"
echo "请从模板创建并填入账号密码"
exit 1
fi
# shellcheck source=/dev/null
source "$ENV_FILE"
if [[ -z "${REGISTRY_USER:-}" || -z "${REGISTRY_PASS:-}" ]]; then
echo "错误REGISTRY_USER 或 REGISTRY_PASS 未设置"
echo "请编辑 ${ENV_FILE} 填入凭证"
exit 1
fi
echo "登录镜像仓库 ${REGISTRY} ..."
echo "$REGISTRY_PASS" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin
# 推送参数:镜像名:标签
IMAGE="${1:-}"
if [[ -z "$IMAGE" ]]; then
echo "用法:$0 <镜像名:标签>"
echo "示例:$0 user-service:latest"
exit 1
fi
echo "推送镜像 ${IMAGE} ..."
docker push "${REGISTRY}/${IMAGE}"
echo "完成:${REGISTRY}/${IMAGE}"