From f68adfa02ebcf5c7ccd9f8f102fe759d86ffed4e Mon Sep 17 00:00:00 2001 From: Kiichiro YUKAWA Date: Tue, 23 Jan 2024 11:30:13 +0900 Subject: [PATCH 1/2] Add go cache for improvement docker build performance (#2297) * :whale: Add go cache for improvement docker build performance Signed-off-by: vankichi * :whale: Fix Signed-off-by: vankichi * :whale: Fix Signed-off-by: vankichi * :whale: Add skip clean deps flag Signed-off-by: vankichi * :whale: Fix Signed-off-by: vankichi * :whale: Fix Signed-off-by: vankichi * :whale: remove Signed-off-by: vankichi * :whale: convert /tmp to /home/vankichi Signed-off-by: vankichi --------- Signed-off-by: vankichi --- Makefile | 1 + Makefile.d/dependencies.mk | 29 ++++++++++--------- dockers/agent/core/ngt/Dockerfile | 11 +++++-- dockers/agent/sidecar/Dockerfile | 11 +++++-- dockers/ci/base/Dockerfile | 11 +++++-- dockers/dev/Dockerfile | 12 ++++++-- dockers/discoverer/k8s/Dockerfile | 11 +++++-- dockers/gateway/filter/Dockerfile | 11 +++++-- dockers/gateway/lb/Dockerfile | 11 +++++-- dockers/gateway/mirror/Dockerfile | 11 +++++-- dockers/index/job/correction/Dockerfile | 11 +++++-- dockers/index/job/creation/Dockerfile | 11 +++++-- .../index/job/readreplica/rotate/Dockerfile | 11 +++++-- dockers/index/job/save/Dockerfile | 11 +++++-- dockers/manager/index/Dockerfile | 11 +++++-- dockers/tools/benchmark/job/Dockerfile | 10 +++++-- dockers/tools/benchmark/operator/Dockerfile | 11 +++++-- dockers/tools/cli/loadtest/Dockerfile | 7 ++++- 18 files changed, 158 insertions(+), 44 deletions(-) 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..a13e92d0bd 100644 --- a/dockers/agent/core/ngt/Dockerfile +++ b/dockers/agent/core/ngt/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -65,7 +68,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -87,7 +92,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..c602fbd43b 100644 --- a/dockers/agent/sidecar/Dockerfile +++ b/dockers/agent/sidecar/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV GOPATH /go ENV GOROOT /opt/go @@ -58,7 +61,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -79,7 +84,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..edf2db83d7 100644 --- a/dockers/ci/base/Dockerfile +++ b/dockers/ci/base/Dockerfile @@ -23,6 +23,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder LABEL maintainer="${MAINTAINER}" +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -71,9 +74,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make deps ROOTDIR=$ROOTDIR GO_CLEAN_DEPS=false -RUN make ngt/install \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..00ae3fa9da 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -21,6 +21,10 @@ ARG MAINTAINER="vdaas.org vald team " FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/vscode/devcontainers/go:1 AS base LABEL maintainer="${MAINTAINER}" +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} + # skipcq: DOK-DL3008 RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ @@ -51,7 +55,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make deps GO_CLEAN_DEPS=false \ && make ngt/install \ && make helm/install \ && make helm-docs/install \ @@ -62,7 +68,9 @@ RUN make deps \ && make kubectl/install # additional deps -RUN make k3d/install \ +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..d6819fe551 100644 --- a/dockers/discoverer/k8s/Dockerfile +++ b/dockers/discoverer/k8s/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -58,7 +61,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -76,7 +81,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..23dcafa1dd 100644 --- a/dockers/gateway/filter/Dockerfile +++ b/dockers/gateway/filter/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..d54cd7b49d 100644 --- a/dockers/gateway/lb/Dockerfile +++ b/dockers/gateway/lb/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..d146917731 100644 --- a/dockers/gateway/mirror/Dockerfile +++ b/dockers/gateway/mirror/Dockerfile @@ -23,6 +23,9 @@ FROM golang:${GO_VERSION} AS golang FROM ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -53,7 +56,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + go mod download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -77,7 +82,9 @@ 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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ && mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} diff --git a/dockers/index/job/correction/Dockerfile b/dockers/index/job/correction/Dockerfile index 5625c1193e..bb7c3e3d3c 100644 --- a/dockers/index/job/correction/Dockerfile +++ b/dockers/index/job/correction/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..a0bd366138 100644 --- a/dockers/index/job/creation/Dockerfile +++ b/dockers/index/job/creation/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..36e19db46f 100644 --- a/dockers/index/job/readreplica/rotate/Dockerfile +++ b/dockers/index/job/readreplica/rotate/Dockerfile @@ -24,6 +24,9 @@ FROM golang:${GO_VERSION} AS golang FROM ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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/save/Dockerfile b/dockers/index/job/save/Dockerfile index 7c543d8744..6b5a6beb39 100644 --- a/dockers/index/job/save/Dockerfile +++ b/dockers/index/job/save/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..72a77f0cd7 100644 --- a/dockers/manager/index/Dockerfile +++ b/dockers/manager/index/Dockerfile @@ -24,6 +24,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -75,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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..3d678ee7ba 100644 --- a/dockers/tools/benchmark/job/Dockerfile +++ b/dockers/tools/benchmark/job/Dockerfile @@ -30,7 +30,9 @@ FROM ubuntu:devel AS builder ARG UPX_OPTIONS ARG ZLIB_VERSION ARG HDF5_VERSION +ARG TARGETARCH +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -88,7 +90,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN make go/download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -106,7 +110,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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/operator/Dockerfile b/dockers/tools/benchmark/operator/Dockerfile index ba3dc24266..22e298b3f2 100644 --- a/dockers/tools/benchmark/operator/Dockerfile +++ b/dockers/tools/benchmark/operator/Dockerfile @@ -25,6 +25,9 @@ FROM golang:${GO_VERSION} AS golang FROM ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -62,7 +65,9 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN go mod download +RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . @@ -80,7 +85,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + 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/cli/loadtest/Dockerfile b/dockers/tools/cli/loadtest/Dockerfile index b086da97db..22c181fc9c 100644 --- a/dockers/tools/cli/loadtest/Dockerfile +++ b/dockers/tools/cli/loadtest/Dockerfile @@ -22,6 +22,9 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS golang FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder +ARG TARGETARCH + +ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -57,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-${ARCH}" \ + --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ + make go/download WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal COPY internal . From 07570a1ff28780ddf25d7fc7db8cc548b88898f4 Mon Sep 17 00:00:00 2001 From: Yusuke Kadowaki Date: Tue, 23 Jan 2024 14:49:14 +0900 Subject: [PATCH 2/2] Stop using ENV ARCH and add --platform in Dockerfile (#2304) * Stop using ENV ARCH * Update Dockerfile platform specification --- dockers/agent/core/ngt/Dockerfile | 9 ++++----- dockers/agent/sidecar/Dockerfile | 9 ++++----- dockers/ci/base/Dockerfile | 9 ++++----- dockers/dev/Dockerfile | 10 ++++------ dockers/discoverer/k8s/Dockerfile | 9 ++++----- dockers/gateway/filter/Dockerfile | 9 ++++----- dockers/gateway/lb/Dockerfile | 9 ++++----- dockers/gateway/mirror/Dockerfile | 15 +++++++-------- dockers/index/job/correction/Dockerfile | 9 ++++----- dockers/index/job/creation/Dockerfile | 9 ++++----- dockers/index/job/readreplica/rotate/Dockerfile | 15 +++++++-------- dockers/index/job/save/Dockerfile | 9 ++++----- dockers/manager/index/Dockerfile | 9 ++++----- dockers/tools/benchmark/job/Dockerfile | 15 +++++++-------- dockers/tools/benchmark/operator/Dockerfile | 15 +++++++-------- dockers/tools/cli/loadtest/Dockerfile | 5 ++--- 16 files changed, 74 insertions(+), 91 deletions(-) diff --git a/dockers/agent/core/ngt/Dockerfile b/dockers/agent/core/ngt/Dockerfile index a13e92d0bd..d98150a793 100644 --- a/dockers/agent/core/ngt/Dockerfile +++ b/dockers/agent/core/ngt/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -68,8 +67,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -92,8 +91,8 @@ COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} RUN make ngt/install -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/agent/sidecar/Dockerfile b/dockers/agent/sidecar/Dockerfile index c602fbd43b..7784edf21a 100644 --- a/dockers/agent/sidecar/Dockerfile +++ b/dockers/agent/sidecar/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV GOPATH /go ENV GOROOT /opt/go @@ -61,8 +60,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -84,8 +83,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/ci/base/Dockerfile b/dockers/ci/base/Dockerfile index edf2db83d7..2bb5787508 100644 --- a/dockers/ci/base/Dockerfile +++ b/dockers/ci/base/Dockerfile @@ -25,7 +25,6 @@ LABEL maintainer="${MAINTAINER}" ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -74,12 +73,12 @@ COPY apis/proto apis/proto COPY versions versions COPY hack/go.mod.default hack/go.mod.default -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 \ diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 00ae3fa9da..7a33529525 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -23,8 +23,6 @@ LABEL maintainer="${MAINTAINER}" ARG TARGETARCH -ENV ARCH=${TARGETARCH} - # skipcq: DOK-DL3008 RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ @@ -55,8 +53,8 @@ COPY versions versions COPY hack/go.mod.default hack/go.mod.default # basic deps -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 \ @@ -68,8 +66,8 @@ RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ && make kubectl/install # additional deps -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 \ diff --git a/dockers/discoverer/k8s/Dockerfile b/dockers/discoverer/k8s/Dockerfile index d6819fe551..7de2fd243a 100644 --- a/dockers/discoverer/k8s/Dockerfile +++ b/dockers/discoverer/k8s/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -61,8 +60,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -81,8 +80,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/gateway/filter/Dockerfile b/dockers/gateway/filter/Dockerfile index 23dcafa1dd..2ca5eb6301 100644 --- a/dockers/gateway/filter/Dockerfile +++ b/dockers/gateway/filter/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/gateway/lb/Dockerfile b/dockers/gateway/lb/Dockerfile index d54cd7b49d..7d67100c8c 100644 --- a/dockers/gateway/lb/Dockerfile +++ b/dockers/gateway/lb/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/gateway/mirror/Dockerfile b/dockers/gateway/mirror/Dockerfile index d146917731..58d41d32f1 100644 --- a/dockers/gateway/mirror/Dockerfile +++ b/dockers/gateway/mirror/Dockerfile @@ -19,13 +19,12 @@ 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 ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -56,8 +55,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -82,12 +81,12 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} COPY Makefile . COPY .git . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 bb7c3e3d3c..b230baa3e8 100644 --- a/dockers/index/job/correction/Dockerfile +++ b/dockers/index/job/correction/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/index/job/creation/Dockerfile b/dockers/index/job/creation/Dockerfile index a0bd366138..aec6cded89 100644 --- a/dockers/index/job/creation/Dockerfile +++ b/dockers/index/job/creation/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/index/job/readreplica/rotate/Dockerfile b/dockers/index/job/readreplica/rotate/Dockerfile index 36e19db46f..d22f7a6e95 100644 --- a/dockers/index/job/readreplica/rotate/Dockerfile +++ b/dockers/index/job/readreplica/rotate/Dockerfile @@ -20,13 +20,12 @@ 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 ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,15 +79,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 6b5a6beb39..9146892bba 100644 --- a/dockers/index/job/save/Dockerfile +++ b/dockers/index/job/save/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/manager/index/Dockerfile b/dockers/manager/index/Dockerfile index 72a77f0cd7..056624f3ff 100644 --- a/dockers/manager/index/Dockerfile +++ b/dockers/manager/index/Dockerfile @@ -26,7 +26,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -80,8 +79,8 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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}" diff --git a/dockers/tools/benchmark/job/Dockerfile b/dockers/tools/benchmark/job/Dockerfile index 3d678ee7ba..acef095c7e 100644 --- a/dockers/tools/benchmark/job/Dockerfile +++ b/dockers/tools/benchmark/job/Dockerfile @@ -23,16 +23,15 @@ 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 ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -90,8 +89,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -110,15 +109,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 22e298b3f2..e629f68ca1 100644 --- a/dockers/tools/benchmark/operator/Dockerfile +++ b/dockers/tools/benchmark/operator/Dockerfile @@ -21,13 +21,12 @@ 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 ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -65,8 +64,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 @@ -85,15 +84,15 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions COPY versions . WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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 22c181fc9c..eeabbc9dda 100644 --- a/dockers/tools/cli/loadtest/Dockerfile +++ b/dockers/tools/cli/loadtest/Dockerfile @@ -24,7 +24,6 @@ FROM --platform=${BUILDPLATFORM} ubuntu:devel AS builder ARG TARGETARCH -ENV ARCH=${TARGETARCH} ENV GO111MODULE on ENV DEBIAN_FRONTEND noninteractive ENV INITRD No @@ -60,8 +59,8 @@ COPY .git . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${ARCH}" \ - --mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${ARCH}" \ +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