From 9e77de6b465f3182e08b21357876baacf3b781d7 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Sat, 7 Nov 2020 20:06:07 +0800 Subject: [PATCH] frontend: scratch-based docker image --- frontend/Dockerfile.amd64 | 14 +++++--------- frontend/Dockerfile.arm32v7 | 14 +++++--------- frontend/Dockerfile.arm64v8 | 14 +++++--------- frontend/Dockerfile.i386 | 14 +++++--------- 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/frontend/Dockerfile.amd64 b/frontend/Dockerfile.amd64 index 9c081ce..bccf851 100644 --- a/frontend/Dockerfile.amd64 +++ b/frontend/Dockerfile.amd64 @@ -1,13 +1,9 @@ -FROM amd64/debian:buster - -LABEL Lan Tian "lantian@lantian.pub" -ENV GOOS=linux GOARCH=amd64 +FROM golang:buster AS step_0 +ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on WORKDIR /root COPY . . -RUN apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get -qq install -y golang git \ - && cd /root && go get github.com/gorilla/handlers && go build -o /frontend \ - && cd / && rm -rf /root/* \ - && apt-get -qq purge -y golang git \ - && apt-get -qq autoremove --purge -y && apt-get clean && rm -rf /var/lib/apt/lists +RUN go build -o /frontend +FROM scratch AS step_1 +COPY --from=step_0 /frontend / ENTRYPOINT ["/frontend"] diff --git a/frontend/Dockerfile.arm32v7 b/frontend/Dockerfile.arm32v7 index 1794dd5..1ccd2ed 100644 --- a/frontend/Dockerfile.arm32v7 +++ b/frontend/Dockerfile.arm32v7 @@ -1,13 +1,9 @@ -FROM multiarch/debian-debootstrap:armhf-buster - -LABEL Lan Tian "lantian@lantian.pub" -ENV GOOS=linux GOARCH=arm +FROM golang:buster AS step_0 +ENV CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on WORKDIR /root COPY . . -RUN apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get -qq install -y golang git \ - && cd /root && go get github.com/gorilla/handlers && go build -o /frontend \ - && cd / && rm -rf /root/* \ - && apt-get -qq purge -y golang git \ - && apt-get -qq autoremove --purge -y && apt-get clean && rm -rf /var/lib/apt/lists +RUN go build -o /frontend +FROM scratch AS step_1 +COPY --from=step_0 /frontend / ENTRYPOINT ["/frontend"] diff --git a/frontend/Dockerfile.arm64v8 b/frontend/Dockerfile.arm64v8 index c83d355..129d810 100644 --- a/frontend/Dockerfile.arm64v8 +++ b/frontend/Dockerfile.arm64v8 @@ -1,13 +1,9 @@ -FROM multiarch/debian-debootstrap:arm64-buster - -LABEL Lan Tian "lantian@lantian.pub" -ENV GOOS=linux GOARCH=arm64 +FROM golang:buster AS step_0 +ENV CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on WORKDIR /root COPY . . -RUN apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get -qq install -y golang git \ - && cd /root && go get github.com/gorilla/handlers && go build -o /frontend \ - && cd / && rm -rf /root/* \ - && apt-get -qq purge -y golang git \ - && apt-get -qq autoremove --purge -y && apt-get clean && rm -rf /var/lib/apt/lists +RUN go build -o /frontend +FROM scratch AS step_1 +COPY --from=step_0 /frontend / ENTRYPOINT ["/frontend"] diff --git a/frontend/Dockerfile.i386 b/frontend/Dockerfile.i386 index 12c5d77..7db318f 100644 --- a/frontend/Dockerfile.i386 +++ b/frontend/Dockerfile.i386 @@ -1,13 +1,9 @@ -FROM i386/debian:buster - -LABEL Lan Tian "lantian@lantian.pub" -ENV GOOS=linux GOARCH=386 +FROM golang:buster AS step_0 +ENV CGO_ENABLED=0 GOOS=linux GOARCH=386 GO111MODULE=on WORKDIR /root COPY . . -RUN apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get -qq install -y golang git \ - && cd /root && go get github.com/gorilla/handlers && go build -o /frontend \ - && cd / && rm -rf /root/* \ - && apt-get -qq purge -y golang git \ - && apt-get -qq autoremove --purge -y && apt-get clean && rm -rf /var/lib/apt/lists +RUN go build -o /frontend +FROM scratch AS step_1 +COPY --from=step_0 /frontend / ENTRYPOINT ["/frontend"]