add article
This commit is contained in:
42
Dockerfile.worker
Normal file
42
Dockerfile.worker
Normal file
@@ -0,0 +1,42 @@
|
||||
# 使用官方 Go 镜像作为构建环境
|
||||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 go mod 文件
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# 下载依赖
|
||||
RUN go mod download
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建 Worker 可执行文件
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker cmd/worker/main.go
|
||||
|
||||
# 使用轻量级的 alpine 镜像作为运行环境
|
||||
FROM alpine:latest
|
||||
|
||||
# 安装必要的包
|
||||
RUN apk --no-cache add ca-certificates tzdata
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /root/
|
||||
|
||||
# 复制可执行文件
|
||||
COPY --from=builder /app/worker .
|
||||
|
||||
# 复制配置文件
|
||||
COPY --from=builder /app/config.yaml .
|
||||
COPY --from=builder /app/configs ./configs
|
||||
|
||||
# 设置时区
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# 暴露端口(如果需要)
|
||||
# EXPOSE 8080
|
||||
|
||||
# 运行 Worker
|
||||
CMD ["./worker"]
|
||||
Reference in New Issue
Block a user