From 15986b78cd9fa8157aa422b9b65a01baaf9459d1 Mon Sep 17 00:00:00 2001 From: Daniel 'f0o' Preussker Date: Sun, 8 Sep 2024 11:08:28 +0000 Subject: [PATCH] Optimize Docker Builds --- Dockerfile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b48881..b2b3ae1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM bufbuild/buf:latest AS buf-builder +FROM --platform=$BUILDPLATFORM bufbuild/buf:latest AS buf-builder WORKDIR /opt/protobuf COPY protobuf /opt/protobuf RUN buf generate -FROM node:alpine AS node-builder +FROM --platform=$BUILDPLATFORM node:alpine AS node-builder WORKDIR /opt COPY webui /opt/webui COPY --from=buf-builder /opt/protobuf /opt/protobuf @@ -13,9 +13,10 @@ RUN cd protobuf \ && npm install \ && npm run build -FROM golang:alpine AS go-builder +FROM --platform=$BUILDPLATFORM golang:alpine AS go-builder ENV CGO_ENABLED=0 ARG VERSION=untracked +ARG TARGETOS TARGETARCH WORKDIR /opt COPY pkg /opt/pkg COPY cmd/server /opt/cmd/server @@ -23,13 +24,13 @@ COPY go.mod go.sum /opt/. COPY --from=buf-builder /opt/protobuf /opt/protobuf COPY --from=node-builder /opt/cmd/server/dist /opt/cmd/server/dist RUN apk --no-cache add ca-certificates \ - && go mod tidy \ - && go build -ldflags="-X github.com/AS203038/looking-glass/pkg/utils.release=${VERSION}" -o /opt/looking-glass /opt/cmd/server + && go mod download \ + && GOOS=$TARGETOS GOARCH=$TARGETARCH go build -x -ldflags="-X github.com/AS203038/looking-glass/pkg/utils.release=${VERSION}" -o /opt/looking-glass /opt/cmd/server -FROM scratch -LABEL org.opencontainers.image.source https://github.com/AS203038/looking-glass -LABEL org.opencontainers.image.description Yet another looking glass project -LABEL org.opencontainers.image.licenses GPL-3.0-or-later +FROM scratch AS final +LABEL org.opencontainers.image.source=https://github.com/AS203038/looking-glass +LABEL org.opencontainers.image.description="Yet another looking glass project" +LABEL org.opencontainers.image.licenses=GPL-3.0-or-later WORKDIR / COPY --from=go-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=go-builder /opt/looking-glass /looking-glass