chore: 完善 Docker 部署配置并修复测试超时

- 新增 Dockerfile: 多阶段构建,优化镜像大小
- 新增 .dockerignore: 加速构建,排除不必要文件
- 更新 docker-compose.yml: 使用 SQLite 简化部署
- 修复 vitest.config.js: testTimeout 改为 60000ms 修复慢测试超时
This commit is contained in:
2026-04-08 22:13:46 +08:00
parent a85d822419
commit 1b96715b55
4 changed files with 130 additions and 12 deletions

49
Dockerfile Normal file
View File

@@ -0,0 +1,49 @@
# 构建阶段
FROM golang:1.23-alpine AS builder
WORKDIR /build
# 安装构建依赖
RUN apk add --no-cache git ca-certificates tzdata
# 复制 Go 模块文件
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码
COPY . .
# 编译应用
ARG GIN_MODE=release
ENV GIN_MODE=${GIN_MODE}
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server ./cmd/server
# 运行阶段
FROM alpine:3.19
WORKDIR /app
# 安装运行时依赖
RUN apk add --no-cache ca-certificates tzdata
# 从构建阶段复制二进制文件
COPY --from=builder /build/server .
COPY --from=builder /build/configs ./configs
COPY --from=builder /build/data ./data
# 创建日志目录
RUN mkdir -p /app/logs
# 设置时区
ENV TZ=Asia/Shanghai
ENV GIN_MODE=release
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=5s \
CMD wget -q --spider http://localhost:8080/api/v1/health || exit 1
# 启动命令
CMD ["./server"]