From 4b41e7f2ddc95f6435bb55c37fcacc5bcad6f455 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 25 Apr 2026 22:16:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Docker=20=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=8E=A8=E9=80=81=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ backend/scripts/push-image.sh | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 backend/scripts/push-image.sh diff --git a/.gitignore b/.gitignore index 0edadae..979636a 100644 --- a/.gitignore +++ b/.gitignore @@ -549,3 +549,6 @@ backend/desc.md # Claude Code .claude/ + +# Registry credentials +.env.registry diff --git a/backend/scripts/push-image.sh b/backend/scripts/push-image.sh new file mode 100755 index 0000000..d8660db --- /dev/null +++ b/backend/scripts/push-image.sh @@ -0,0 +1,37 @@ +#!/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}"