refactor: reorganize modules and add Linux build tooling
This commit is contained in:
59
module/base/fts/Dockerfile
Normal file
59
module/base/fts/Dockerfile
Normal file
@@ -0,0 +1,59 @@
|
||||
# 构建阶段
|
||||
FROM golang:1.26.5-alpine AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 安装必要的工具
|
||||
RUN apk add --no-cache git ca-certificates tzdata
|
||||
|
||||
# 设置Go环境变量
|
||||
ENV GO111MODULE=on \
|
||||
GOPROXY=https://goproxy.cn,direct \
|
||||
GOPRIVATE=git.apinb.com/* \
|
||||
GONOPROXY=git.apinb.com/* \
|
||||
GOINSECURE=git.apinb.com/* \
|
||||
GONOSUMDB=git.apinb.com/* \
|
||||
GOEXPERIMENT=jsonv2
|
||||
|
||||
# 复制go模块文件
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# 下载依赖
|
||||
RUN go mod download
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建应用
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w -s' -o fts ./cmd/main/main.go
|
||||
|
||||
# 运行阶段
|
||||
FROM alpine:latest
|
||||
|
||||
# 设置时区
|
||||
RUN apk --no-cache add ca-certificates tzdata \
|
||||
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||
&& apk del tzdata
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# 从构建阶段复制二进制文件
|
||||
COPY --from=builder /app/fts .
|
||||
|
||||
# 复制配置文件
|
||||
COPY --from=builder /app/etc ./etc
|
||||
|
||||
# 创建日志目录
|
||||
RUN mkdir -p /var/log/fts
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8080
|
||||
|
||||
# 设置健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/ || exit 1
|
||||
|
||||
# 运行应用
|
||||
CMD ["./fts"]
|
||||
Reference in New Issue
Block a user