feat: multi-stage builds
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
lab 2021-12-05 01:21:24 +08:00
parent 955aec1f16
commit b877f2b9e8
2 changed files with 11 additions and 6 deletions

View File

@ -20,6 +20,12 @@ steps:
commands:
- echo bonjour monde
- name: build
image: golang:1.17-alpine
pull: if-not-exists
commands:
- CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build -ldflags="-s -w" -tags timetzdata -o app main.go
- name: docker
image: plugins/docker
settings:

View File

@ -1,22 +1,21 @@
FROM golang:alpine as builder
FROM alpine:3.14 as builder
ENV CGO_ENABLED=0
ENV GOOS="linux"
ENV GOARCH="amd64"
ADD ./ /src
WORKDIR /src
RUN apk --no-cache add ca-certificates
RUN go build -ldflags="-s -w" -tags timetzdata -o app main.go
#RUN go build -ldflags="-s -w" -tags timetzdata -o app main.go
FROM scratch as production
ENV TZ="Asia/Shanghai"
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /src/app .
ADD ./app .
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
#COPY --from=builder /src/app .
CMD ["./app"]