fix: resolve CHANGELOG.md path issue for Docker deployment
Some checks failed
Deploy BillAI / Deploy to Production (push) Has been cancelled
Some checks failed
Deploy BillAI / Deploy to Production (push) Has been cancelled
- Update changelog.go to use binary directory as base path - Uses os.Executable() instead of relative path '..' - Automatically adapts to local and Docker environments - Modify server Dockerfile build context - Change context from ./server to project root (.) - Update COPY commands for new context - Add CHANGELOG.md to container image - Update AGENTS.md guidelines - Explicitly specify relative path format for file references This ensures the changelog API works correctly in both local development and Docker deployment environments.
This commit is contained in:
@@ -120,4 +120,4 @@ Upload: ZIP/XLSX → Extract → Convert UTF-8 CSV → Detect bill type → Dedu
|
|||||||
- **Dependencies:** Check `package.json`/`go.mod`/`requirements.txt` before adding new packages
|
- **Dependencies:** Check `package.json`/`go.mod`/`requirements.txt` before adding new packages
|
||||||
- **Tests:** Always run relevant test suite before committing changes
|
- **Tests:** Always run relevant test suite before committing changes
|
||||||
- **Git commits:** Provide clear messages explaining the "why" of changes
|
- **Git commits:** Provide clear messages explaining the "why" of changes
|
||||||
- **File references:** Use `file_path:line_number` format when mentioning code locations
|
- **File references:** Use relative `file_path:line_number` format (e.g., `server/handler/changelog.go:12`) when mentioning code locations
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ services:
|
|||||||
# Go 后端服务
|
# Go 后端服务
|
||||||
server:
|
server:
|
||||||
build:
|
build:
|
||||||
context: ./server
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: server/Dockerfile
|
||||||
container_name: billai-server
|
container_name: billai-server
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Go 服务 Dockerfile
|
# Go 服务 Dockerfile
|
||||||
# 多阶段构建:编译阶段 + 运行阶段
|
# 多阶段构建:编译阶段 + 运行阶段
|
||||||
|
# 构建上下文:项目根目录(docker-compose context: .)
|
||||||
|
|
||||||
# ===== 编译阶段 =====
|
# ===== 编译阶段 =====
|
||||||
FROM golang:1.24-alpine AS builder
|
FROM golang:1.24-alpine AS builder
|
||||||
@@ -10,11 +11,11 @@ WORKDIR /build
|
|||||||
ENV GOPROXY=https://goproxy.cn,direct
|
ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
# 先复制依赖文件,利用 Docker 缓存
|
# 先复制依赖文件,利用 Docker 缓存
|
||||||
COPY go.mod go.sum ./
|
COPY server/go.mod server/go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
# 复制源代码并编译
|
# 复制源代码并编译
|
||||||
COPY . .
|
COPY server/ .
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o billai-server .
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o billai-server .
|
||||||
|
|
||||||
# ===== 运行阶段 =====
|
# ===== 运行阶段 =====
|
||||||
@@ -35,6 +36,9 @@ ENV TZ=Asia/Shanghai
|
|||||||
COPY --from=builder /build/billai-server .
|
COPY --from=builder /build/billai-server .
|
||||||
COPY --from=builder /build/config.yaml .
|
COPY --from=builder /build/config.yaml .
|
||||||
|
|
||||||
|
# 复制项目根目录的 CHANGELOG.md
|
||||||
|
COPY CHANGELOG.md .
|
||||||
|
|
||||||
# 创建必要目录
|
# 创建必要目录
|
||||||
RUN mkdir -p uploads outputs
|
RUN mkdir -p uploads outputs
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ func ParseChangelog() ([]ChangelogEntry, error) {
|
|||||||
// 获取项目根目录
|
// 获取项目根目录
|
||||||
rootDir := os.Getenv("PROJECT_ROOT")
|
rootDir := os.Getenv("PROJECT_ROOT")
|
||||||
if rootDir == "" {
|
if rootDir == "" {
|
||||||
// 如果未设置,使用相对路径推测
|
// 使用二进制文件所在目录作为基准
|
||||||
rootDir = ".."
|
execPath, err := os.Executable()
|
||||||
|
if err == nil {
|
||||||
|
rootDir = filepath.Dir(execPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changelogPath := filepath.Join(rootDir, "CHANGELOG.md")
|
changelogPath := filepath.Join(rootDir, "CHANGELOG.md")
|
||||||
|
|||||||
Reference in New Issue
Block a user