From b877f2b9e87fd803070fb6ee67ccef3a21f47b47 Mon Sep 17 00:00:00 2001 From: lab Date: Sun, 5 Dec 2021 01:21:24 +0800 Subject: [PATCH] feat: multi-stage builds --- .drone.yml | 6 ++++++ Dockerfile | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index ac31c8d..b15bc54 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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: diff --git a/Dockerfile b/Dockerfile index d5f8b4c..5399273 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file