Skip to content

Commit

Permalink
add docker buildx cache
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed Dec 6, 2023
1 parent 4fddfb0 commit 4448dc3
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 135 deletions.
173 changes: 76 additions & 97 deletions Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,37 @@ docker/name/org/alter:
docker/platforms:
@echo "linux/amd64,linux/arm64"

.PHONY: docker/build/image
## Generalized docker build function
docker/build/image:
DOCKER_BUILDKIT=1 $(DOCKER) buildx build \
$(DOCKER_OPTS) \
--cache-to type=registry,ref=$(ORG)/$(IMAGE):$(TAG)-buildcache,mode=max \
--cache-from type=registry,ref=$(ORG)/$(IMAGE):$(TAG)-buildcache \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER) \
$(EXTRA_ARGS) \
-t $(ORG)/$(IMAGE):$(TAG) \
--push \
-f $(DOCKERFILE) .
# --build-arg BUILDKIT_MULTI_PLATFORM=1 \
# --platform $(DOCKER_BUILDER_PLATFORM) \


.PHONY: docker/name/agent-ngt
docker/name/agent-ngt:
@echo "$(ORG)/$(AGENT_IMAGE)"

.PHONY: docker/build/agent-ngt
## build agent-ngt image
docker/build/agent-ngt:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/agent/core/ngt/Dockerfile \
-t $(ORG)/$(AGENT_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER)
@make DOCKERFILE="$(ROOTDIR)/dockers/agent/core/ngt/Dockerfile" \
IMAGE=$(AGENT_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/agent-sidecar
docker/name/agent-sidecar:
Expand All @@ -59,14 +75,10 @@ docker/name/agent-sidecar:
.PHONY: docker/build/agent-sidecar
## build agent-sidecar image
docker/build/agent-sidecar:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/agent/sidecar/Dockerfile \
-t $(ORG)/$(AGENT_SIDECAR_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER)
@make DOCKERFILE="$(ROOTDIR)/dockers/agent/sidecar/Dockerfile" \
IMAGE=$(AGENT_SIDECAR_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/discoverer-k8s
docker/name/discoverer-k8s:
Expand All @@ -75,14 +87,10 @@ docker/name/discoverer-k8s:
.PHONY: docker/build/discoverer-k8s
## build discoverer-k8s image
docker/build/discoverer-k8s:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/discoverer/k8s/Dockerfile \
-t $(ORG)/$(DISCOVERER_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER)
@make DOCKERFILE="$(ROOTDIR)/dockers/discoverer/k8s/Dockerfile" \
IMAGE=$(DISCOVERER_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/gateway-lb
docker/name/gateway-lb:
Expand All @@ -91,13 +99,10 @@ docker/name/gateway-lb:
.PHONY: docker/build/gateway-lb
## build gateway-lb image
docker/build/gateway-lb:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/gateway/lb/Dockerfile \
-t $(ORG)/$(LB_GATEWAY_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG)
@make DOCKERFILE="$(ROOTDIR)/dockers/gateway/lb/Dockerfile" \
IMAGE=$(LB_GATEWAY_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/gateway-filter
docker/name/gateway-filter:
Expand All @@ -106,13 +111,10 @@ docker/name/gateway-filter:
.PHONY: docker/build/gateway-filter
## build gateway-filter image
docker/build/gateway-filter:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/gateway/filter/Dockerfile \
-t $(ORG)/$(FILTER_GATEWAY_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG)
@make DOCKERFILE="$(ROOTDIR)/dockers/gateway/filter/Dockerfile" \
IMAGE=$(FILTER_GATEWAY_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/manager-index
docker/name/manager-index:
Expand All @@ -121,14 +123,10 @@ docker/name/manager-index:
.PHONY: docker/build/manager-index
## build manager-index image
docker/build/manager-index:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/manager/index/Dockerfile \
-t $(ORG)/$(MANAGER_INDEX_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER)
@make DOCKERFILE="$(ROOTDIR)/dockers/manager/index/Dockerfile" \
IMAGE=$(MANAGER_INDEX_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/ci-container
docker/name/ci-container:
Expand All @@ -137,12 +135,9 @@ docker/name/ci-container:
.PHONY: docker/build/ci-container
## build ci-container image
docker/build/ci-container:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/ci/base/Dockerfile \
-t $(ORG)/$(CI_CONTAINER_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/ci/base/Dockerfile" \
IMAGE=$(CI_CONTAINER_IMAGE) \
TAG=$(TAG) docker/build/image

.PHONY: docker/name/dev-container
docker/name/dev-container:
Expand All @@ -151,11 +146,10 @@ docker/name/dev-container:
.PHONY: docker/build/dev-container
## build dev-container image
docker/build/dev-container:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/dev/Dockerfile \
-t $(ORG)/$(DEV_CONTAINER_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER)
@make DOCKERFILE="$(ROOTDIR)/dockers/dev/Dockerfile" \
IMAGE=$(DEV_CONTAINER_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/operator/helm
docker/name/operator/helm:
Expand All @@ -164,16 +158,11 @@ docker/name/operator/helm:
.PHONY: docker/build/operator/helm
## build helm-operator image
docker/build/operator/helm:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/operator/helm/Dockerfile \
-t $(ORG)/$(HELM_OPERATOR_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg OPERATOR_SDK_VERSION=$(OPERATOR_SDK_VERSION) \
--build-arg UPX_OPTIONS=$(UPX_OPTIONS)
@make DOCKERFILE="$(ROOTDIR)/dockers/operator/helm/Dockerfile" \
IMAGE=$(HELM_OPERATOR_IMAGE) \
TAG=$(TAG) \
EXTRA_ARGS="--build-arg OPERATOR_SDK_VERSION=$(OPERATOR_SDK_VERSION) --build-arg UPX_OPTIONS=$(UPX_OPTIONS)" \
docker/build/image

.PHONY: docker/name/loadtest
docker/name/loadtest:
Expand All @@ -182,12 +171,10 @@ docker/name/loadtest:
.PHONY: docker/build/loadtest
## build loadtest image
docker/build/loadtest:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/tools/cli/loadtest/Dockerfile \
-t $(ORG)/$(LOADTEST_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/tools/cli/loadtest/Dockerfile" \
IMAGE=$(LOADTEST_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/index-correction
docker/name/index-correction:
Expand All @@ -196,12 +183,10 @@ docker/name/index-correction:
.PHONY: docker/build/index-correction
## build index-correction image
docker/build/index-correction:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/index/job/correction/Dockerfile \
-t $(ORG)/$(INDEX_CORRECTION_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/index/job/correction/Dockerfile" \
IMAGE=$(INDEX_CORRECTION_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/index-creation
docker/name/index-creation:
Expand All @@ -210,12 +195,10 @@ docker/name/index-creation:
.PHONY: docker/build/index-creation
## build index-creation image
docker/build/index-creation:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/index/job/creation/Dockerfile \
-t $(ORG)/$(INDEX_CREATION_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/index/job/creation/Dockerfile" \
IMAGE=$(INDEX_CREATION_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/index-save
docker/name/index-save:
Expand All @@ -224,12 +207,10 @@ docker/name/index-save:
.PHONY: docker/build/index-save
## build index-save image
docker/build/index-save:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/index/job/save/Dockerfile \
-t $(ORG)/$(INDEX_SAVE_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/index/job/save/Dockerfile" \
IMAGE=$(INDEX_SAVE_IMAGE) \
TAG=$(TAG) \
docker/build/image

.PHONY: docker/name/readreplica-rotate
docker/name/readreplica-rotate:
Expand All @@ -238,9 +219,7 @@ docker/name/readreplica-rotate:
.PHONY: docker/build/readreplica-rotate
## build readreplica-rotate image
docker/build/readreplica-rotate:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/index/job/readreplica/rotate/Dockerfile \
-t $(ORG)/$(READREPLICA_ROTATE_IMAGE):$(TAG) . \
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg GO_VERSION=$(GO_VERSION)
@make DOCKERFILE="$(ROOTDIR)/dockers/index/job/readreplica/rotate/Dockerfile" \
IMAGE=$(READREPLICA_ROTATE_IMAGE) \
TAG=$(TAG) \
docker/build/image
7 changes: 4 additions & 3 deletions dockers/agent/core/ngt/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax = docker/dockerfile:latest
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
Expand All @@ -19,9 +20,9 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static
ARG DISTROLESS_IMAGE_TAG=nonroot
ARG MAINTAINER="vdaas.org vald team <[email protected]>"

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

ENV GO111MODULE on
ENV DEBIAN_FRONTEND noninteractive
Expand Down Expand Up @@ -92,7 +93,7 @@ RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${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 ngt
Expand Down
7 changes: 4 additions & 3 deletions dockers/agent/sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax = docker/dockerfile:latest
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
Expand All @@ -19,9 +20,9 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static
ARG DISTROLESS_IMAGE_TAG=nonroot
ARG MAINTAINER="vdaas.org vald team <[email protected]>"

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

ENV GO111MODULE on
ENV GOPATH /go
Expand Down Expand Up @@ -81,7 +82,7 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}
RUN 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 sidecar
Expand Down
5 changes: 3 additions & 2 deletions dockers/ci/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax = docker/dockerfile:latest
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
Expand All @@ -17,9 +18,9 @@
ARG GO_VERSION=latest
ARG MAINTAINER="vdaas.org vald team <[email protected]>"

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
LABEL maintainer="${MAINTAINER}"

ENV GO111MODULE on
Expand Down
3 changes: 2 additions & 1 deletion dockers/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax = docker/dockerfile:latest
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
Expand All @@ -17,7 +18,7 @@
ARG MAINTAINER="vdaas.org vald team <[email protected]>"

# skipcq: DOK-DL3026
FROM mcr.microsoft.com/vscode/devcontainers/go:1 AS base
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/vscode/devcontainers/go:1 AS base
LABEL maintainer="${MAINTAINER}"

# skipcq: DOK-DL3008
Expand Down
7 changes: 4 additions & 3 deletions dockers/discoverer/k8s/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax = docker/dockerfile:latest
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
Expand All @@ -19,9 +20,9 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static
ARG DISTROLESS_IMAGE_TAG=nonroot
ARG MAINTAINER="vdaas.org vald team <[email protected]>"

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

ENV GO111MODULE on
ENV DEBIAN_FRONTEND noninteractive
Expand Down Expand Up @@ -81,7 +82,7 @@ RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${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 discoverer
Expand Down
Loading

0 comments on commit 4448dc3

Please sign in to comment.