Files
billai/server/Dockerfile
clz bb717faac3
Some checks failed
Deploy BillAI / Deploy to Production (push) Has been cancelled
fix: resolve CHANGELOG.md path issue for Docker deployment
- 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.
2026-04-02 20:45:24 +08:00

54 lines
1.2 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Go 服务 Dockerfile
# 多阶段构建:编译阶段 + 运行阶段
# 构建上下文项目根目录docker-compose context: .
# ===== 编译阶段 =====
FROM golang:1.24-alpine AS builder
WORKDIR /build
# 配置 Go 代理(国内镜像)
ENV GOPROXY=https://goproxy.cn,direct
# 先复制依赖文件,利用 Docker 缓存
COPY server/go.mod server/go.sum ./
RUN go mod download
# 复制源代码并编译
COPY server/ .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o billai-server .
# ===== 运行阶段 =====
FROM alpine:latest
WORKDIR /app
# 配置 Alpine 镜像源(国内)
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装必要工具
RUN apk --no-cache add ca-certificates tzdata curl
# 设置时区
ENV TZ=Asia/Shanghai
# 从编译阶段复制二进制文件
COPY --from=builder /build/billai-server .
COPY --from=builder /build/config.yaml .
# 复制项目根目录的 CHANGELOG.md
COPY CHANGELOG.md .
# 创建必要目录
RUN mkdir -p uploads outputs
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=10s --timeout=5s --retries=5 \
CMD curl -f http://localhost:8080/health || exit 1
# 启动服务
CMD ["./billai-server"]