parent
19447a898a
commit
58992935d3
31
Dockerfile
31
Dockerfile
|
|
@ -1,22 +1,31 @@
|
||||||
FROM golang:alpine AS builder
|
FROM golang:alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
|
||||||
|
|
||||||
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
|
# 安装 ca-certificates 和 upx 包
|
||||||
RUN go mod download
|
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/
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-s -w -extldflags "-static"' -o override && upx --best /app/override
|
||||||
COPY config.json.example /app/config.json
|
|
||||||
|
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
|
WORKDIR /app
|
||||||
VOLUME /app
|
|
||||||
|
|
||||||
EXPOSE 8080
|
ENTRYPOINT ["/app/override"]
|
||||||
CMD ["override"]
|
|
||||||
|
EXPOSE 8181
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue