-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (35 loc) · 1003 Bytes
/
Dockerfile
File metadata and controls
48 lines (35 loc) · 1003 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
# Build stage
FROM golang:1.23-alpine AS builder
# 设置构建参数
ARG VERSION=dev
# 设置工作目录
WORKDIR /build
# 复制源代码
COPY . .
RUN go mod tidy
RUN go mod vendor
# 构建应用
RUN BUILD_TIME=$(date +%Y%m%d%H%M%S) && \
go build \
-ldflags "-s -w -X 'pkg.Version=${VERSION}' -X 'pkg.BuildTime=${BUILD_TIME}'" \
-o /build/verge cmd/main.go
# Runtime stage
FROM alpine:3.23
# 安装必要的运行时依赖
#RUN apk add --no-cache ca-certificates tzdata
# 创建非 root 用户
RUN addgroup -g 1000 verge && \
adduser -u 1000 -G verge -s /bin/sh -D verge
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder --chown=verge:verge /build/verge /app/verge
# 复制资源文件
#COPY --from=builder /build/res /app/res
#COPY --from=builder /build/platform/linux/start.sh /app/start.sh
# 切换到非 root 用户
USER verge
# 暴露端口(根据应用需要调整)
# EXPOSE 8080
# 设置启动命令
CMD ["/app/verge"]