From 2b1d9b4e8da21841c9d5a1238d43a4333073c97d Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 7 Oct 2025 10:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 1 + README.md | 6 +- api_delete/.dockerignore | 26 +++++++++ api_gateway/.dockerignore | 26 +++++++++ api_login/.dockerignore | 26 +++++++++ api_register/.dockerignore | 26 +++++++++ api_template/.dockerignore | 26 +++++++++ api_update_account/.dockerignore | 26 +++++++++ api_update_password/.dockerignore | 26 +++++++++ deploy.py => build_service.py | 0 build.py => create_api.py | 0 deploy.sh | 93 ++++++++++++++++++++++++++++++ 13 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 api_delete/.dockerignore create mode 100644 api_gateway/.dockerignore create mode 100644 api_login/.dockerignore create mode 100644 api_register/.dockerignore create mode 100644 api_template/.dockerignore create mode 100644 api_update_account/.dockerignore create mode 100644 api_update_password/.dockerignore rename deploy.py => build_service.py (100%) rename build.py => create_api.py (100%) create mode 100644 deploy.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c1e8fd13352aa64d0fb6ab898739152271284c3a GIT binary patch literal 6148 zcmeHK%}(1u5S~p!q z^YokD4FVCaK&u&R_M6?ES?_*p?Rtnv4X5cgQJ;uBC}XRKVu^4+>oaM&mJU#vF;W^) z4y~Xf{{jQNcdHcBm@NUcmzA95>HKKLUmZ KDTIMnW#BJU!eBfA literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore index 1e64010..27c0aba 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ dist/ # 临时文件目录 tmp/ temp/ +shared_data/ # 日志文件 *.log diff --git a/README.md b/README.md index 34f10cd..2ae4671 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# REAMDME \ No newline at end of file +# REAMDME + +create_api.py -- 创建 API 模块。 +build_service.py -- 编译服务,需要本地编译成功后,才能提交和打标签。 +deploy.sh -- 服务器部署脚本。 \ No newline at end of file diff --git a/api_delete/.dockerignore b/api_delete/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_delete/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_gateway/.dockerignore b/api_gateway/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_gateway/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_login/.dockerignore b/api_login/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_login/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_register/.dockerignore b/api_register/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_register/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_template/.dockerignore b/api_template/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_template/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_update_account/.dockerignore b/api_update_account/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_update_account/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/api_update_password/.dockerignore b/api_update_password/.dockerignore new file mode 100644 index 0000000..3d1e553 --- /dev/null +++ b/api_update_password/.dockerignore @@ -0,0 +1,26 @@ +# 排除Go编译产物 +*.exe +*.exe~ +*.dll +*.so +*.dylib +app # 排除本地已构建的二进制文件 + +# 排除依赖目录 +vendor/ +go/pkg/ +db +scripts +shared_data + +# 排除版本控制和日志文件 +.git/ +.gitignore +logs/ +*.log +*.md +*.sql + +# 排除IDE配置文件 +.idea/ +.vscode/ \ No newline at end of file diff --git a/deploy.py b/build_service.py similarity index 100% rename from deploy.py rename to build_service.py diff --git a/build.py b/create_api.py similarity index 100% rename from build.py rename to create_api.py diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..fb37c0c --- /dev/null +++ b/deploy.sh @@ -0,0 +1,93 @@ +#!/bin/bash +set -e # 遇到错误立即退出,确保部署流程的可靠性 + +# 颜色输出配置(增强可读性) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # 重置颜色 + +# 步骤1:停止当前运行的 docker-compose 编排 +echo -e "${YELLOW}===== 第一步:停止当前 docker-compose 服务 ====="${NC} +if [ -f "./docker-compose.yaml" ]; then + echo "正在停止现有服务..." + docker-compose -f ./docker-compose.yaml down + if [ $? -eq 0 ]; then + echo -e "${GREEN}现有 docker-compose 服务已成功停止${NC}" + else + echo -e "${RED}停止 docker-compose 服务失败!${NC}" + exit 1 + fi +else + echo -e "${RED}错误:未找到当前目录下的 docker-compose.yaml 文件${NC}" + exit 1 +fi + +# 步骤2:遍历 api_ 开头的目录并执行 release.sh +echo -e "\n${YELLOW}===== 第二步:处理 api_ 开头的服务目录 ====="${NC} +for dir in ./api_*/; do + # 提取目录名称(移除路径和末尾斜杠) + dir_name=$(basename "${dir%/}") + + # 步骤3:跳过 api_template 目录 + if [ "$dir_name" = "api_template" ]; then + echo -e "${YELLOW} 跳过目录:$dir_name${NC}" + continue + fi + + # 检查目录是否有效 + if [ ! -d "$dir" ]; then + echo -e "${RED} 警告:$dir 不是有效目录,已跳过${NC}" + continue + fi + + echo -e "\n处理目录:$dir_name" + # 进入目标目录 + cd "$dir" || { + echo -e "${RED} 错误:无法进入目录 $dir_name${NC}" + exit 1 + } + + # 检查并执行 release.sh + if [ -f "release.sh" ]; then + # 添加执行权限 + chmod +x release.sh + echo " 已为 release.sh 添加执行权限" + + # 执行脚本 + echo " 正在执行 release.sh..." + ./release.sh + if [ $? -eq 0 ]; then + echo -e " ${GREEN}release.sh 执行成功${NC}" + else + echo -e " ${RED}release.sh 执行失败!${NC}" + exit 1 + fi + else + echo -e "${YELLOW} 警告:目录 $dir_name 中未找到 release.sh,已跳过${NC}" + fi + + # 返回上级目录,继续处理其他目录 + cd .. || { + echo -e "${RED} 错误:无法返回上级目录${NC}" + exit 1 + } +done + +# 步骤4:启动新的 docker-compose 编排 +echo -e "\n${YELLOW}===== 第三步:启动新的 docker-compose 服务 ====="${NC} +if [ -f "./docker-compose.yaml" ]; then + echo "正在启动服务..." + docker-compose -f ./docker-compose.yaml up -d + if [ $? -eq 0 ]; then + echo -e "${GREEN}docker-compose 服务启动成功!${NC}" + else + echo -e "${RED}启动 docker-compose 服务失败!${NC}" + exit 1 + fi +else + echo -e "${RED}错误:未找到当前目录下的 docker-compose.yaml 文件${NC}" + exit 1 +fi + +echo -e "\n${GREEN}===== 所有部署步骤已完成 ====="${NC} \ No newline at end of file