ci(deploy): deploy images over ssh from gitea actions

This commit is contained in:
2026-07-07 15:02:02 +08:00
parent 9cb9534459
commit e699ff13b3
8 changed files with 290 additions and 62 deletions
+4 -4
View File
@@ -1,9 +1,9 @@
#!/bin/bash
# 推送指定分支到指定远端
# 期望服务器端 post-receive hook 已就位;本脚本只做 git push,不负责构建/启动
# 调用方:deploy_web.shproduction)→ push_to_remote "production" "main"
# deploy_web_test.shtest)→ push_to_remote "test" "test"
# 推送指定分支到指定远端
# 当前发布由 Gitea Actions 构建镜像并通过 SSH 部署;本脚本只负责触发分支 push。
# 调用方:deploy_web.shproduction)→ push_to_remote "gitea" "main"
# deploy_web_test.shtest)→ push_to_remote "gitea" "test"
push_to_remote() {
local remote="$1"
local branch="$2"
+3 -3
View File
@@ -1,6 +1,6 @@
#!/bin/bash
# ==========================================
# 生产环境 Web 部署脚本(Next.js + git push 模型)
# 生产环境 Web 部署脚本(Next.js + Gitea Actions SSH 部署模型)
# 原始 Dart: scripts/deploy/deploy_web.sh
# ==========================================
@@ -11,8 +11,8 @@ source "$SCRIPT_DIR/_deploy_lib.sh"
# 主函数
main() {
push_to_remote "production" "main"
purge_cdn_cache
push_to_remote "gitea" "main"
# NEW_VERSION=$(bump_version)
}
main
+2 -3
View File
@@ -1,6 +1,6 @@
#!/bin/bash
# ==========================================
# 测试环境 Web 部署脚本(Next.js + git push 模型)
# 测试环境 Web 部署脚本(Next.js + Gitea Actions SSH 部署模型)
# 原始 Dart: scripts/deploy/deploy_web_test.sh
# ==========================================
@@ -11,8 +11,7 @@ source "$SCRIPT_DIR/_deploy_lib.sh"
# 主函数
main() {
push_to_remote "test" "test"
purge_cdn_cache
push_to_remote "gitea" "test"
}
main
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
IMAGE="${1:-}"
ENV_FILE="${2:-}"
HOST_PORT="${3:-}"
CONTAINER_NAME="${4:-}"
PROJECT_NAME="${5:-}"
if [ -z "$IMAGE" ] || [ -z "$ENV_FILE" ] || [ -z "$HOST_PORT" ] || [ -z "$CONTAINER_NAME" ] || [ -z "$PROJECT_NAME" ]; then
echo "Usage: $0 <image> <env-file> <host-port> <container-name> <compose-project-name>" >&2
exit 64
fi
if [ ! -f "docker-compose.yml" ]; then
echo "Missing docker-compose.yml in $(pwd)" >&2
exit 66
fi
if [ ! -f "$ENV_FILE" ]; then
echo "Missing env file: $ENV_FILE" >&2
exit 66
fi
if docker compose version >/dev/null 2>&1; then
COMPOSE=(docker compose)
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE=(docker-compose)
else
echo "docker compose command not found" >&2
exit 127
fi
export COZSWEET_IMAGE="$IMAGE"
export COZSWEET_ENV_FILE="$ENV_FILE"
export COZSWEET_HOST_PORT="$HOST_PORT"
export COZSWEET_CONTAINER_NAME="$CONTAINER_NAME"
export COMPOSE_PROJECT_NAME="$PROJECT_NAME"
echo "=== deploy image: $COZSWEET_IMAGE ==="
echo "=== env file: $COZSWEET_ENV_FILE ==="
echo "=== host port: $COZSWEET_HOST_PORT ==="
echo "=== container: $COZSWEET_CONTAINER_NAME ==="
echo "=== compose project: $COMPOSE_PROJECT_NAME ==="
"${COMPOSE[@]}" pull web
"${COMPOSE[@]}" up -d --remove-orphans --no-build web
"${COMPOSE[@]}" ps
docker image prune -f
echo "=== deploy done ==="