Skip to content

Commit

Permalink
configmaptocrs: improve docker build cache
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Pitasi <[email protected]>
  • Loading branch information
Pitasi authored and fedepaol committed Dec 12, 2023
1 parent fff6cfb commit 23f0337
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions configmaptocrs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
# syntax=docker/dockerfile:1.2

FROM --platform=$BUILDPLATFORM docker.io/golang:1.20.10 AS builder
ARG GIT_COMMIT=dev
ARG GIT_BRANCH=dev
WORKDIR $GOPATH/go.universe.tf/metallb

# Cache the downloads
COPY go.mod go.sum ./
RUN go mod download

# COPY internals
COPY internal internal
COPY api api

# COPY configmaptocrs
COPY configmaptocrs/*.go configmaptocrs/
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x

ARG GIT_COMMIT=dev
ARG GIT_BRANCH=dev
ARG TARGETARCH
ARG TARGETOS
ARG TARGETPLATFORM

# have to manually convert as building the different arms can cause issues
# Extract variant
# have to manually convert as building the different arms can cause issues
RUN case ${TARGETPLATFORM} in \
"linux/arm/v6") export VARIANT="6" ;; \
"linux/arm/v7") export VARIANT="7" ;; \
*) export VARIANT="" ;; \
esac

# Cache builds directory for faster rebuild
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=internal,target=internal \
--mount=type=bind,source=api,target=api \
--mount=type=bind,source=configmaptocrs,target=configmaptocrs \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$VARIANT \
go build -v -o /build/configmaptocrs \
-ldflags "-X 'go.universe.tf/metallb/internal/version.gitCommit=${GIT_COMMIT}' -X 'go.universe.tf/metallb/internal/version.gitBranch=${GIT_BRANCH}'" \
go.universe.tf/metallb/configmaptocrs
./configmaptocrs

FROM docker.io/alpine:latest

Expand Down

0 comments on commit 23f0337

Please sign in to comment.