|
|
|
@ -21,30 +21,12 @@
|
|
|
|
|
# https://docs.docker.com/build/building/multi-platform/
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
|
|
|
|
|
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
|
|
|
|
|
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
|
|
|
|
|
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
|
|
|
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
|
|
|
|
|
# To properly provided solutions that supports more than one platform you should use this option.
|
|
|
|
|
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
|
|
|
|
|
|
|
|
|
|
## Build and push docker image for the manager for cross-platform support
|
|
|
|
|
.PHONY: docker-buildx
|
|
|
|
|
docker-buildx:
|
|
|
|
|
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
|
|
|
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
|
|
|
|
- docker buildx create --name project-v3-builder
|
|
|
|
|
docker buildx use project-v3-builder
|
|
|
|
|
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
|
|
|
|
|
- docker buildx rm project-v3-builder
|
|
|
|
|
rm Dockerfile.cross
|
|
|
|
|
|
|
|
|
|
DOCKER := docker
|
|
|
|
|
DOCKER_SUPPORTED_API_VERSION ?= 1.32|1.40|1.41
|
|
|
|
|
|
|
|
|
|
REGISTRY_PREFIX ?= cubxxw
|
|
|
|
|
BASE_IMAGE = centos:centos8
|
|
|
|
|
REGISTRY_PREFIX ?= ghcr.io/OpenIMSDK
|
|
|
|
|
IMAGES ?= lvscare
|
|
|
|
|
IMAGE_PLAT ?= $(subst $(SPACE),$(COMMA),$(subst _,/,$(PLATFORMS)))
|
|
|
|
|
|
|
|
|
|
EXTRA_ARGS ?= --no-cache
|
|
|
|
|
_DOCKER_BUILD_EXTRA_ARGS :=
|
|
|
|
@ -62,14 +44,32 @@ IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/docker/*)
|
|
|
|
|
# Determine images names by stripping out the dir names
|
|
|
|
|
IMAGES ?= $(filter-out tools,$(foreach image,${IMAGES_DIR},$(notdir ${image})))
|
|
|
|
|
|
|
|
|
|
# ifeq (${IMAGES},)
|
|
|
|
|
# $(error Could not determine IMAGES, set ROOT_DIR or run in source dir)
|
|
|
|
|
# endif
|
|
|
|
|
ifeq (${IMAGES},)
|
|
|
|
|
$(error Could not determine IMAGES, set ROOT_DIR or run in source dir)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
# Image targets
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
|
|
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
|
|
|
|
|
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
|
|
|
|
|
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
|
|
|
|
|
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
|
|
|
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
|
|
|
|
|
# To properly provided solutions that supports more than one platform you should use this option.
|
|
|
|
|
## Build and push docker image for the manager for cross-platform support
|
|
|
|
|
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
|
|
|
|
|
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
|
|
|
|
.PHONY: docker-buildx
|
|
|
|
|
docker-buildx:
|
|
|
|
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
|
|
|
|
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
|
|
|
|
|
$(CONTAINER_TOOL) buildx use project-v3-builder
|
|
|
|
|
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMAGES} -f Dockerfile.cross .
|
|
|
|
|
- $(CONTAINER_TOOL) buildx rm project-v3-builder
|
|
|
|
|
rm Dockerfile.cross
|
|
|
|
|
|
|
|
|
|
## image.verify: Verify docker version
|
|
|
|
|
.PHONY: image.verify
|
|
|
|
|
image.verify:
|
|
|
|
@ -95,31 +95,32 @@ image.daemon.verify:
|
|
|
|
|
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
|
|
|
## image.build: Build docker images
|
|
|
|
|
.PHONY: image.build
|
|
|
|
|
image.build: image.verify go.build.verify $(addprefix image.build., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
|
|
|
|
|
image.build: image.verify $(addprefix image.build., $(addprefix $(PLATFORM)., $(IMAGES)))
|
|
|
|
|
|
|
|
|
|
## image.build.multiarch: Build docker images for all platforms
|
|
|
|
|
.PHONY: image.build.multiarch
|
|
|
|
|
image.build.multiarch: image.verify go.build.verify $(foreach p,$(PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(IMAGES))))
|
|
|
|
|
image.build.multiarch: image.verify $(foreach p,$(PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(IMAGES))))
|
|
|
|
|
|
|
|
|
|
## image.build.%: Build docker image for a specific platform
|
|
|
|
|
.PHONY: image.build.%
|
|
|
|
|
image.build.%: go.build.%
|
|
|
|
|
image.build.%: go.bin.%
|
|
|
|
|
$(eval IMAGE := $(COMMAND))
|
|
|
|
|
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
|
|
|
|
|
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
|
|
|
|
|
@mkdir -p $(TMP_DIR)/$(IMAGE)
|
|
|
|
|
@cat $(ROOT_DIR)/build/docker/$(IMAGE)/Dockerfile\
|
|
|
|
|
| sed "s#BASE_IMAGE#$(BASE_IMAGE)#g" >$(TMP_DIR)/$(IMAGE)/Dockerfile
|
|
|
|
|
@cp $(OUTPUT_DIR)/platforms/$(IMAGE_PLAT)/$(IMAGE) $(TMP_DIR)/$(IMAGE)/
|
|
|
|
|
@DST_DIR=$(TMP_DIR)/$(IMAGE) $(ROOT_DIR)/build/docker/$(IMAGE)/build.sh 2>/dev/null || true
|
|
|
|
|
$(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
|
|
|
|
@if [ $(shell $(GO) env GOARCH) != $(ARCH) ] ; then \
|
|
|
|
|
$(MAKE) image.daemon.verify ;\
|
|
|
|
|
$(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX) ; \
|
|
|
|
|
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
|
|
|
|
|
@echo "===========> Building LOCAL docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
|
|
|
|
|
@mkdir -p $(TMP_DIR)/$(IMAGE)/$(PLATFORM)
|
|
|
|
|
@cat $(ROOT_DIR)/docker/$(IMAGE)/Dockerfile\
|
|
|
|
|
>$(TMP_DIR)/$(IMAGE)/Dockerfile
|
|
|
|
|
@cp $(BIN_DIR)/$(PLATFORM)/$(IMAGE) $(TMP_DIR)/$(IMAGE)/$(PLATFORM)
|
|
|
|
|
|
|
|
|
|
$(eval BUILD_SUFFIX := --load --pull -t $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
|
|
|
|
$(eval BUILD_SUFFIX_ARM := --load --pull -t $(REGISTRY_PREFIX)/$(IMAGE).$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
|
|
|
|
@if [ "$(ARCH)" == "amd64" ]; then \
|
|
|
|
|
echo "===========> Creating LOCAL docker image tag $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) for $(ARCH)"; \
|
|
|
|
|
$(DOCKER) buildx build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX); \
|
|
|
|
|
else \
|
|
|
|
|
$(DOCKER) build $(BUILD_SUFFIX) ; \
|
|
|
|
|
echo "===========> Creating LOCAL docker image tag $(REGISTRY_PREFIX)/$(IMAGE).$(ARCH):$(VERSION) for $(ARCH)"; \
|
|
|
|
|
$(DOCKER) buildx build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX_ARM); \
|
|
|
|
|
fi
|
|
|
|
|
@rm -rf $(TMP_DIR)/$(IMAGE)
|
|
|
|
|
|
|
|
|
|
# https://docs.docker.com/build/building/multi-platform/
|
|
|
|
|
# busybox image supports amd64, arm32v5, arm32v6, arm32v7, arm64v8, i386, ppc64le, and s390x
|
|
|
|
|