-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (39 loc) · 1021 Bytes
/
Dockerfile
File metadata and controls
52 lines (39 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 构建阶段
FROM golang:1.23-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV CGO_ENABLED=1
ENV GOOS=linux
ENV GOARCH=amd64
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
# 安装必要的系统依赖
RUN apk add --no-cache \
git \
ca-certificates \
tzdata \
sqlite \
build-base \
&& rm -rf /var/cache/apk/*
# 复制go mod和sum文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download && go mod verify
# 复制源代码
COPY . .
# 构建应用
RUN go build -ldflags="-w -s" -o housing-monitor .
# 运行阶段
FROM alpine:3.19
# 安装基本运行时依赖
RUN apk add --no-cache ca-certificates tzdata
# 设置时区和配置文件路径环境变量
ENV TZ=Asia/Shanghai
ENV CONFIG_PATH=/app/config.json
# 设置工作目录
WORKDIR /app
# 复制构建的二进制文件
COPY --from=builder /app/housing-monitor .
# 运行程序,使用环境变量指定配置文件路径
CMD ["sh", "-c", "./housing-monitor -config ${CONFIG_PATH}"]