diff --git a/Makefile b/Makefile index 7d6227297c..103b2b8508 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,7 @@ GOARCH := $(eval GOARCH := $(shell go env GOARCH))$(GOARCH) GOBIN := $(eval GOBIN := $(or $(shell go env GOBIN),$(GOPATH)/bin))$(GOBIN) GOCACHE := $(eval GOCACHE := $(shell go env GOCACHE))$(GOCACHE) GOOS := $(eval GOOS := $(shell go env GOOS))$(GOOS) +GO_CLEAN_DEPS := true GOTEST_TIMEOUT = 30m TEST_NOT_IMPL_PLACEHOLDER = NOT IMPLEMENTED BELOW diff --git a/Makefile.d/dependencies.mk b/Makefile.d/dependencies.mk index f423031547..1969ff2756 100644 --- a/Makefile.d/dependencies.mk +++ b/Makefile.d/dependencies.mk @@ -47,19 +47,22 @@ go/download: .PHONY: go/deps ## install Go package dependencies go/deps: - rm -rf $(ROOTDIR)/vendor \ - /go/pkg \ - $(GOCACHE) \ - $(ROOTDIR)/go.sum \ - $(ROOTDIR)/go.mod - cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod - GOPRIVATE=$(GOPRIVATE) go mod tidy - go clean -cache -modcache -testcache -i -r - rm -rf $(ROOTDIR)/vendor \ - /go/pkg \ - $(GOCACHE) \ - $(ROOTDIR)/go.sum \ - $(ROOTDIR)/go.mod + if $(GO_CLEAN_DEPS); then \ + rm -rf $(ROOTDIR)/vendor \ + /go/pkg \ + $(GOCACHE) \ + $(ROOTDIR)/go.sum \ + $(ROOTDIR)/go.mod ; \ + cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod ; \ + GOPRIVATE=$(GOPRIVATE) go mod tidy ; \ + go clean -cache -modcache -testcache -i -r ; \ + rm -rf $(ROOTDIR)/vendor \ + /go/pkg \ + $(GOCACHE) \ + $(ROOTDIR)/go.sum \ + $(ROOTDIR)/go.mod ; \ + cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod ; \ + fi cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod GOPRIVATE=$(GOPRIVATE) go mod tidy go get -u all 2>/dev/null || true diff --git a/dockers/agent/core/ngt/Dockerfile b/dockers/agent/core/ngt/Dockerfile index 5670b1baf2..d98150a793 100644 --- a/dockers/agent/core/ngt/Dockerfile +++ b/dockers/agent/core/ngt/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -65,7 +67,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -87,7 +91,9 @@ COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} RUN make ngt/install -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/agent/sidecar/Dockerfile b/dockers/agent/sidecar/Dockerfile index 46fe904f2f..7784edf21a 100644 --- a/dockers/agent/sidecar/Dockerfile +++ b/dockers/agent/sidecar/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV GOPATH /go ENV GOROOT /opt/go @@ -58,7 +60,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -79,7 +83,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" FROM --platform=${BUILDPLATFORM} ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} diff --git a/dockers/ci/base/Dockerfile b/dockers/ci/base/Dockerfile index d60dd98cf7..2bb5787508 100644 --- a/dockers/ci/base/Dockerfile +++ b/dockers/ci/base/Dockerfile @@ -23,6 +23,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder LABEL maintainer="${MAINTAINER}" +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -71,9 +73,13 @@ COPY apis/proto apis/proto COPY versions versions COPY hack/go.mod.default hack/go.mod.default -RUN make deps ROOTDIR=$ROOTDIR +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make deps ROOTDIR=$ROOTDIR GO_CLEAN_DEPS=false -RUN make ngt/install \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make ngt/install \ && make helm/install \ && make helm-docs/install \ && make kind/install \ diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 166285a93d..7a33529525 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -21,6 +21,8 @@ ARG MAINTAINER="vdaas.org vald team " FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/vscode/devcontainers/go:1 AS base LABEL maintainer="${MAINTAINER}" +ARG TARGETARCH + # skipcq: DOK-DL3008 RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ @@ -51,7 +53,9 @@ COPY versions versions COPY hack/go.mod.default hack/go.mod.default # basic deps -RUN make deps \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make deps GO_CLEAN_DEPS=false \ && make ngt/install \ && make helm/install \ && make helm-docs/install \ @@ -62,7 +66,9 @@ RUN make deps \ && make kubectl/install # additional deps -RUN make k3d/install \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make k3d/install \ && make buf/install \ && make k9s/install \ && make minikube/install diff --git a/dockers/discoverer/k8s/Dockerfile b/dockers/discoverer/k8s/Dockerfile index 788c40ffe5..7de2fd243a 100644 --- a/dockers/discoverer/k8s/Dockerfile +++ b/dockers/discoverer/k8s/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -58,7 +60,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -76,7 +80,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/gateway/filter/Dockerfile b/dockers/gateway/filter/Dockerfile index 2f6717ad3e..2ca5eb6301 100644 --- a/dockers/gateway/filter/Dockerfile +++ b/dockers/gateway/filter/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/gateway/lb/Dockerfile b/dockers/gateway/lb/Dockerfile index f9d872d8b8..7d67100c8c 100644 --- a/dockers/gateway/lb/Dockerfile +++ b/dockers/gateway/lb/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/gateway/mirror/Dockerfile b/dockers/gateway/mirror/Dockerfile index 438790483a..58d41d32f1 100644 --- a/dockers/gateway/mirror/Dockerfile +++ b/dockers/gateway/mirror/Dockerfile @@ -19,9 +19,11 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static ARG DISTROLESS_IMAGE_TAG=nonroot ARG MAINTAINER="vdaas.org vald team " -FROM golang:${GO_VERSION} AS golang +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang -FROM ubuntu:devel AS builder +FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder + +ARG TARGETARCH ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive @@ -53,7 +55,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} COPY go.mod . COPY go.sum . -RUN go mod download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + go mod download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -77,10 +81,12 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} COPY Makefile . COPY .git . -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" -FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} +FROM --platform=${BUILDPLATFORM} ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} LABEL maintainer "${MAINTAINER}" ENV APP_NAME mirror diff --git a/dockers/index/job/correction/Dockerfile b/dockers/index/job/correction/Dockerfile index 5625c1193e..b230baa3e8 100644 --- a/dockers/index/job/correction/Dockerfile +++ b/dockers/index/job/correction/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/index/job/creation/Dockerfile b/dockers/index/job/creation/Dockerfile index daa8bb6c79..aec6cded89 100644 --- a/dockers/index/job/creation/Dockerfile +++ b/dockers/index/job/creation/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/index/job/readreplica/rotate/Dockerfile b/dockers/index/job/readreplica/rotate/Dockerfile index 787405e48e..d22f7a6e95 100644 --- a/dockers/index/job/readreplica/rotate/Dockerfile +++ b/dockers/index/job/readreplica/rotate/Dockerfile @@ -20,9 +20,11 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static ARG DISTROLESS_IMAGE_TAG=nonroot ARG MAINTAINER="vdaas.org vald team " -FROM golang:${GO_VERSION} AS golang +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang -FROM ubuntu:devel AS builder +FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder + +ARG TARGETARCH ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,13 +79,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} RUN cp sample.yaml /tmp/config.yaml -FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} +FROM --platform=${BUILDPLATFORM} ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} LABEL maintainer="${MAINTAINER}" ENV APP_NAME readreplica-rotate diff --git a/dockers/index/job/save/Dockerfile b/dockers/index/job/save/Dockerfile index 7c543d8744..9146892bba 100644 --- a/dockers/index/job/save/Dockerfile +++ b/dockers/index/job/save/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/manager/index/Dockerfile b/dockers/manager/index/Dockerfile index 0c5457160d..056624f3ff 100644 --- a/dockers/manager/index/Dockerfile +++ b/dockers/manager/index/Dockerfile @@ -24,6 +24,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,7 +79,9 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} diff --git a/dockers/tools/benchmark/job/Dockerfile b/dockers/tools/benchmark/job/Dockerfile index 6a3111f26d..acef095c7e 100644 --- a/dockers/tools/benchmark/job/Dockerfile +++ b/dockers/tools/benchmark/job/Dockerfile @@ -23,13 +23,14 @@ ARG DISTROLESS_IMAGE_TAG=nonroot ARG UPX_OPTIONS=-9 ARG MAINTAINER="vdaas.org vald team " -FROM golang:${GO_VERSION} AS golang +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang -FROM ubuntu:devel AS builder +FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG UPX_OPTIONS ARG ZLIB_VERSION ARG HDF5_VERSION +ARG TARGETARCH ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive @@ -88,7 +89,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -106,13 +109,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} RUN cp sample.yaml /tmp/config.yaml -FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} +FROM --platform=${BUILDPLATFORM} ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} LABEL maintainer="${MAINTAINER}" ENV APP_NAME job diff --git a/dockers/tools/benchmark/operator/Dockerfile b/dockers/tools/benchmark/operator/Dockerfile index ba3dc24266..e629f68ca1 100644 --- a/dockers/tools/benchmark/operator/Dockerfile +++ b/dockers/tools/benchmark/operator/Dockerfile @@ -21,9 +21,11 @@ ARG DISTROLESS_IMAGE_TAG=nonroot ARG UPX_OPTIONS=-9 ARG MAINTAINER="vdaas.org vald team " -FROM golang:${GO_VERSION} AS golang +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang -FROM ubuntu:devel AS builder +FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder + +ARG TARGETARCH ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive @@ -62,7 +64,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN go mod download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -80,13 +84,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} RUN cp sample.yaml /tmp/config.yaml -FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} +FROM --platform=${BUILDPLATFORM} ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} LABEL maintainer="${MAINTAINER}" ENV APP_NAME operator diff --git a/dockers/tools/cli/loadtest/Dockerfile b/dockers/tools/cli/loadtest/Dockerfile index b086da97db..eeabbc9dda 100644 --- a/dockers/tools/cli/loadtest/Dockerfile +++ b/dockers/tools/cli/loadtest/Dockerfile @@ -22,6 +22,8 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,7 +59,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal .