Skip to content

Commit

Permalink
Optimize Docker Builds
Browse files Browse the repository at this point in the history
  • Loading branch information
f0o committed Sep 8, 2024
1 parent ef79acf commit 15986b7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,23 +13,24 @@ 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
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
Expand Down

0 comments on commit 15986b7

Please sign in to comment.