fix: 修复并优化部署流程 #75

Merged
huanghaosheng merged 7 commits from develop into main 2026-06-14 14:57:21 +08:00
8 changed files with 17 additions and 55 deletions

View File

@@ -12,11 +12,6 @@ jobs:
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
runs-on: aliyun runs-on: aliyun
steps: steps:
- name: Setup Node.js
run: |
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk add --no-cache nodejs
- name: Checkout - name: Checkout
uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4" uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4"
@@ -35,11 +30,6 @@ jobs:
if: github.event_name == 'push' if: github.event_name == 'push'
runs-on: aliyun runs-on: aliyun
steps: steps:
- name: Setup Node.js
run: |
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk add --no-cache nodejs
- name: Checkout - name: Checkout
uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4" uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4"
@@ -48,16 +38,3 @@ jobs:
chmod +x deploy.sh chmod +x deploy.sh
./deploy.sh build ./deploy.sh build
./deploy.sh restart ./deploy.sh restart
- name: Health Check
run: |
for i in $(seq 1 10); do
if curl -sf http://localhost/api/health > /dev/null 2>&1; then
echo "服务启动成功"
exit 0
fi
echo "等待服务启动... ($i/10)"
sleep 3
done
echo "服务启动超时"
exit 1

9
backend/.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
bin
tmp
.git
.gitignore
*.md
.env*
.vscode
.idea
vendor

View File

@@ -27,7 +27,6 @@ require (
github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-json v0.10.2 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/leodido/go-urn v1.4.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect

View File

@@ -44,8 +44,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=

View File

@@ -5,7 +5,6 @@ import (
"os" "os"
"strings" "strings"
"github.com/joho/godotenv"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -161,12 +160,6 @@ func Load() (*Config, error) {
_ = v.MergeInConfig() _ = v.MergeInConfig()
} }
// 加载 .env 文件(不覆盖已有环境变量)
// 按优先级尝试:当前目录、上级目录(兼容从 backend/ 或项目根目录启动)
_ = godotenv.Load()
_ = godotenv.Load("../.env")
_ = godotenv.Load("../../.env") // 兼容从 backend/cmd/server/ 启动
// 环境变量覆盖 // 环境变量覆盖
v.SetEnvPrefix("CAMTALK") v.SetEnvPrefix("CAMTALK")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

View File

@@ -5,29 +5,10 @@ PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR" cd "$PROJECT_DIR"
# 颜色输出 # 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; } info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
# 确保 .env 存在
ensure_env() {
if [ ! -f .env ]; then
if [ -f .env.example ]; then
warn ".env 文件不存在,从 .env.example 复制模板"
cp .env.example .env
warn "请编辑 .env 填入实际的 API Key然后重新运行"
exit 1
else
error ".env.example 也不存在,请手动创建 .env"
exit 1
fi
fi
}
cmd_build() { cmd_build() {
info "构建 Docker 镜像..." info "构建 Docker 镜像..."
@@ -36,7 +17,6 @@ cmd_build() {
} }
cmd_up() { cmd_up() {
ensure_env
info "启动服务..." info "启动服务..."
docker compose up -d docker compose up -d
info "服务已启动" info "服务已启动"

View File

@@ -17,8 +17,6 @@ services:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: camtalk-backend container_name: camtalk-backend
env_file:
- .env
environment: environment:
- APP_ENV=production - APP_ENV=production
networks: networks:

8
frontend/.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
node_modules
dist
.git
.gitignore
*.md
.env*
.vscode
.idea