parent
19447a898a
commit
58992935d3
31
Dockerfile
31
Dockerfile
|
|
@ -1,22 +1,31 @@
|
|||
FROM golang:alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
|
||||
RUN go mod download
|
||||
# 安装 ca-certificates 和 upx 包
|
||||
RUN apk --no-cache add ca-certificates upx
|
||||
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o override
|
||||
ENV GO111MODULE=on GOSUMDB=off GOPROXY=https://goproxy.cn
|
||||
|
||||
FROM alpine:latest
|
||||
ADD . .
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
RUN go mod tidy
|
||||
|
||||
COPY --from=builder /app/override /usr/local/bin/
|
||||
COPY config.json.example /app/config.json
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-s -w -extldflags "-static"' -o override && upx --best /app/override
|
||||
|
||||
FROM scratch
|
||||
|
||||
# 将操作系统 CA 证书复制到最终镜像
|
||||
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
|
||||
|
||||
# 复制静态二进制文件
|
||||
COPY --from=builder /app/override /app/override
|
||||
|
||||
# 复制配置文件
|
||||
# COPY --from=builder /app/config.json /app/config.json
|
||||
|
||||
WORKDIR /app
|
||||
VOLUME /app
|
||||
|
||||
EXPOSE 8080
|
||||
CMD ["override"]
|
||||
ENTRYPOINT ["/app/override"]
|
||||
|
||||
EXPOSE 8181
|
||||
|
|
|
|||
Loading…
Reference in New Issue