2022-06-15 10:58:05 +08:00
|
|
|
|
FROM golang:1.18 as builder
|
2022-06-15 11:43:40 +08:00
|
|
|
|
|
2022-06-15 11:57:45 +08:00
|
|
|
|
# 启用go module
|
|
|
|
|
ENV GO111MODULE=on \
|
|
|
|
|
GOPROXY=https://goproxy.cn,direct
|
2022-06-15 11:43:40 +08:00
|
|
|
|
|
|
|
|
|
WORKDIR /builder
|
2022-06-15 10:58:05 +08:00
|
|
|
|
COPY . .
|
2022-06-15 11:43:40 +08:00
|
|
|
|
RUN go mod download && go build -o app && upx -9 app
|
|
|
|
|
RUN ls -lh && chmod +x ./app
|
|
|
|
|
|
2022-06-15 11:57:45 +08:00
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# 指定OS等,并go build
|
|
|
|
|
RUN GOOS=linux GOARCH=amd64 go build .
|
|
|
|
|
|
|
|
|
|
# 运行阶段指定scratch作为基础镜像
|
|
|
|
|
FROM alpine
|
2022-06-15 11:43:40 +08:00
|
|
|
|
|
2022-06-15 10:58:05 +08:00
|
|
|
|
WORKDIR /app
|
2022-06-15 11:43:40 +08:00
|
|
|
|
COPY --from=builder /builder/app ./app
|
2022-06-15 11:57:45 +08:00
|
|
|
|
CMD ./app
|
|
|
|
|
|
|
|
|
|
ENTRYPOINT ["./app"]
|