github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docker/docker.mk (about) 1 # 2 #Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 # 4 #This file is part of KubeBlocks project 5 # 6 #This program is free software: you can redistribute it and/or modify 7 #it under the terms of the GNU Affero General Public License as published by 8 #the Free Software Foundation, either version 3 of the License, or 9 #(at your option) any later version. 10 # 11 #This program is distributed in the hope that it will be useful 12 #but WITHOUT ANY WARRANTY; without even the implied warranty of 13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 #GNU Affero General Public License for more details. 15 # 16 #You should have received a copy of the GNU Affero General Public License 17 #along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # 19 20 # To use buildx: https://github.com/docker/buildx#docker-ce 21 export DOCKER_CLI_EXPERIMENTAL=enabled 22 23 # Debian APT mirror repository 24 DEBIAN_MIRROR ?= 25 26 # Docker image build and push setting 27 DOCKER:=DOCKER_BUILDKIT=1 docker 28 DOCKERFILE_DIR?=./docker 29 30 # BUILDX_PLATFORMS ?= $(subst -,/,$(ARCH)) 31 BUILDX_PLATFORMS ?= linux/amd64,linux/arm64 32 33 # Image URL to use all building/pushing image targets 34 IMG ?= docker.io/apecloud/$(APP_NAME) 35 TOOL_IMG ?= docker.io/apecloud/$(APP_NAME)-tools 36 CLI_IMG ?= docker.io/apecloud/kbcli 37 CHARTS_IMG ?= docker.io/apecloud/$(APP_NAME)-charts 38 CLI_TAG ?= v$(CLI_VERSION) 39 DATASCRIPT_IMG ?= docker.io/apecloud/$(APP_NAME)-datascript 40 DATAPROTECTION_IMG ?= docker.io/apecloud/$(APP_NAME)-dataprotection 41 42 # Update whenever you upgrade dev container image 43 DEV_CONTAINER_VERSION_TAG ?= latest 44 DEV_CONTAINER_IMAGE_NAME = docker.io/apecloud/$(APP_NAME)-dev 45 46 DEV_CONTAINER_DOCKERFILE = Dockerfile-dev 47 DOCKERFILE_DIR = ./docker 48 GO_BUILD_ARGS ?= --build-arg GITHUB_PROXY=$(GITHUB_PROXY) --build-arg GOPROXY=$(GOPROXY) 49 BUILD_ARGS ?= 50 DOCKER_BUILD_ARGS ?= 51 DOCKER_BUILD_ARGS += $(GO_BUILD_ARGS) $(BUILD_ARGS) 52 53 ##@ Docker containers 54 55 .PHONY: build-dev-container-image 56 build-dev-container-image: DOCKER_BUILD_ARGS += --build-arg DEBIAN_MIRROR=$(DEBIAN_MIRROR) 57 build-dev-container-image: install-docker-buildx ## Build dev container image. 58 ifneq ($(BUILDX_ENABLED), true) 59 $(DOCKER) build $(DOCKERFILE_DIR)/. $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/${DEV_CONTAINER_DOCKERFILE} --tag $(DEV_CONTAINER_IMAGE_NAME):$(DEV_CONTAINER_VERSION_TAG) 60 else 61 $(DOCKER) buildx build $(DOCKERFILE_DIR)/. $(DOCKER_BUILD_ARGS) --platform $(BUILDX_PLATFORMS) --file $(DOCKERFILE_DIR)/$(DEV_CONTAINER_DOCKERFILE) --tag $(DEV_CONTAINER_IMAGE_NAME):$(DEV_CONTAINER_VERSION_TAG) 62 endif 63 64 65 .PHONY: push-dev-container-image 66 push-dev-container-image: DOCKER_BUILD_ARGS += --build-arg DEBIAN_MIRROR=$(DEBIAN_MIRROR) 67 push-dev-container-image: install-docker-buildx ## Push dev container image. 68 ifneq ($(BUILDX_ENABLED), true) 69 $(DOCKER) push $(DEV_CONTAINER_IMAGE_NAME):$(DEV_CONTAINER_VERSION_TAG) 70 else 71 $(DOCKER) buildx build $(DOCKERFILE_DIR)/. $(DOCKER_BUILD_ARGS) --platform $(BUILDX_PLATFORMS) --file $(DOCKERFILE_DIR)/$(DEV_CONTAINER_DOCKERFILE) --tag $(DEV_CONTAINER_IMAGE_NAME):$(DEV_CONTAINER_VERSION_TAG) --push 72 endif 73 74 75 .PHONY: build-manager-image 76 build-manager-image: install-docker-buildx generate ## Build Operator manager container image. 77 ifneq ($(BUILDX_ENABLED), true) 78 $(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --tag ${IMG}:${VERSION} --tag ${IMG}:latest 79 else 80 ifeq ($(TAG_LATEST), true) 81 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag ${IMG}:latest 82 else 83 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag ${IMG}:${VERSION} 84 endif 85 endif 86 87 88 .PHONY: push-manager-image 89 push-manager-image: install-docker-buildx generate ## Push Operator manager container image. 90 ifneq ($(BUILDX_ENABLED), true) 91 ifeq ($(TAG_LATEST), true) 92 $(DOCKER) push ${IMG}:latest 93 else 94 $(DOCKER) push ${IMG}:${VERSION} 95 endif 96 else 97 ifeq ($(TAG_LATEST), true) 98 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag ${IMG}:latest --push 99 else 100 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag ${IMG}:${VERSION} --push 101 endif 102 endif 103 104 105 .PHONY: build-tools-image 106 build-tools-image: install-docker-buildx generate test-go-generate ## Build tools container image. 107 ifneq ($(BUILDX_ENABLED), true) 108 $(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-tools --tag ${TOOL_IMG}:${VERSION} --tag ${TOOL_IMG}:latest 109 else 110 ifeq ($(TAG_LATEST), true) 111 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-tools --platform $(BUILDX_PLATFORMS) --tag ${TOOL_IMG}:latest 112 else 113 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-tools --platform $(BUILDX_PLATFORMS) --tag ${TOOL_IMG}:${VERSION} 114 endif 115 endif 116 117 .PHONY: push-tools-image 118 push-tools-image: install-docker-buildx generate test-go-generate ## Push tools container image. 119 ifneq ($(BUILDX_ENABLED), true) 120 ifeq ($(TAG_LATEST), true) 121 $(DOCKER) push ${TOOL_IMG}:latest 122 else 123 $(DOCKER) push ${TOOL_IMG}:${VERSION} 124 endif 125 else 126 ifeq ($(TAG_LATEST), true) 127 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-tools --platform $(BUILDX_PLATFORMS) --tag ${TOOL_IMG}:latest --push 128 else 129 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-tools --platform $(BUILDX_PLATFORMS) --tag ${TOOL_IMG}:${VERSION} --push 130 endif 131 endif 132 133 .PHONY: build-charts-image 134 build-charts-image: install-docker-buildx helm-package ## Build helm charts container image. 135 ifneq ($(BUILDX_ENABLED), true) 136 $(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-charts --tag ${CHARTS_IMG}:${VERSION} --tag ${CHARTS_IMG}:latest 137 else 138 ifeq ($(TAG_LATEST), true) 139 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-charts --platform $(BUILDX_PLATFORMS) --tag ${CHARTS_IMG}:latest 140 else 141 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-charts --platform $(BUILDX_PLATFORMS) --tag ${CHARTS_IMG}:${VERSION} 142 endif 143 endif 144 145 146 .PHONY: push-charts-image 147 push-charts-image: install-docker-buildx helm-package ## Push helm charts container image. 148 ifneq ($(BUILDX_ENABLED), true) 149 ifeq ($(TAG_LATEST), true) 150 $(DOCKER) push ${CHARTS_IMG}:latest 151 else 152 $(DOCKER) push ${CHARTS_IMG}:${VERSION} 153 endif 154 else 155 ifeq ($(TAG_LATEST), true) 156 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-charts --platform $(BUILDX_PLATFORMS) --tag ${CHARTS_IMG}:latest --push 157 else 158 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-charts --platform $(BUILDX_PLATFORMS) --tag ${CHARTS_IMG}:${VERSION} --push 159 endif 160 endif 161 162 .PHONY: build-datascript-image 163 build-datascript-image: install-docker-buildx ## Build datascript container image. 164 ifneq ($(BUILDX_ENABLED), true) 165 $(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-datascript --tag ${DATASCRIPT_IMG}:${VERSION} --tag ${DATASCRIPT_IMG}:latest 166 else 167 ifeq ($(TAG_LATEST), true) 168 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-datascript --platform $(BUILDX_PLATFORMS) --tag ${DATASCRIPT_IMG}:latest 169 else 170 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-datascript --platform $(BUILDX_PLATFORMS) --tag ${DATASCRIPT_IMG}:${VERSION} 171 endif 172 endif 173 174 .PHONY: push-datascript-image 175 push-datascript-image: install-docker-buildx ## Push datascript container image. 176 ifneq ($(BUILDX_ENABLED), true) 177 ifeq ($(TAG_LATEST), true) 178 $(DOCKER) push ${DATASCRIPT_IMG}:latest 179 else 180 $(DOCKER) push ${DATASCRIPT_IMG}:${VERSION} 181 endif 182 else 183 ifeq ($(TAG_LATEST), true) 184 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-datascript --platform $(BUILDX_PLATFORMS) --tag ${DATASCRIPT_IMG}:latest --push 185 else 186 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-datascript --platform $(BUILDX_PLATFORMS) --tag ${DATASCRIPT_IMG}:${VERSION} --push 187 endif 188 endif 189 190 .PHONY: build-dataprotection-image 191 build-dataprotection-image: install-docker-buildx generate ## Build Operator dataprotection container image. 192 ifneq ($(BUILDX_ENABLED), true) 193 $(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-dataprotection --tag ${DATAPROTECTION_IMG}:${VERSION} --tag ${DATAPROTECTION_IMG}:latest 194 else 195 ifeq ($(TAG_LATEST), true) 196 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-dataprotection --platform $(BUILDX_PLATFORMS) --tag ${DATAPROTECTION_IMG}:latest 197 else 198 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-dataprotection --platform $(BUILDX_PLATFORMS) --tag ${DATAPROTECTION_IMG}:${VERSION} 199 endif 200 endif 201 202 .PHONY: push-dataprotection-image 203 push-dataprotection-image: install-docker-buildx generate ## Push Operator dataprotection container image. 204 ifneq ($(BUILDX_ENABLED), true) 205 ifeq ($(TAG_LATEST), true) 206 $(DOCKER) push ${DATAPROTECTION_IMG}:latest 207 else 208 $(DOCKER) push ${DATAPROTECTION_IMG}:${VERSION} 209 endif 210 else 211 ifeq ($(TAG_LATEST), true) 212 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-dataprotection --platform $(BUILDX_PLATFORMS) --tag ${DATAPROTECTION_IMG}:latest --push 213 else 214 $(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile-dataprotection --platform $(BUILDX_PLATFORMS) --tag ${DATAPROTECTION_IMG}:${VERSION} --push 215 endif 216 endif