wujian_develop_tool/template/api/docker/golang/Dockerfile.tpl

20 lines
535 B
Docker
Raw Normal View History

2022-01-06 00:19:22 +08:00
FROM golang:1.17 as builder
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io,direct
WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
2022-01-07 00:39:21 +08:00
RUN go mod download -x
2022-01-06 00:19:22 +08:00
WORKDIR /go/src
ADD . .
RUN go mod tidy
2022-01-10 20:26:14 +08:00
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o api_{{ .Name }} ./{{ .Root }}
2022-01-06 00:19:22 +08:00
2022-01-06 20:27:18 +08:00
FROM reg.icechen.cn/alpine as {{ .Name }}
2022-01-06 00:19:22 +08:00
WORKDIR /go/src
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
2022-01-06 20:27:18 +08:00
COPY --from=builder /go/src/api_{{ .Name }} ./
2022-01-06 00:19:22 +08:00
ENV TZ=Asia/Shanghai
2022-01-06 20:27:18 +08:00
RUN chmod +x ./api_{{ .Name }}
2022-01-06 00:19:22 +08:00
EXPOSE 8080
2022-01-06 20:27:18 +08:00
CMD ["./api_{{ .Name }}"]