From 02b98dc4d867bf247573db7815cfdf91ecbff704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=84=E6=BD=AD?= Date: Fri, 18 Aug 2023 11:58:35 +0800 Subject: [PATCH] optimize makefile for buildx (#489) --- Makefile.core.mk | 8 ++++---- docker/docker.mk | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.core.mk b/Makefile.core.mk index 825adb6c02..1b16de623a 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -53,6 +53,7 @@ $(OUT): submodule: git submodule update --init +.PHONY: prebuild prebuild: submodule ./tools/hack/prebuild.sh @@ -71,13 +72,12 @@ build: prebuild $(OUT) build-linux: prebuild $(OUT) GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh $(OUT_LINUX)/ $(HIGRESS_BINARIES) -$(AMD64_OUT_LINUX)/higress: prebuild $(OUT) +$(AMD64_OUT_LINUX)/higress: GOPROXY=$(GOPROXY) GOOS=linux GOARCH=amd64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/linux_amd64/ $(HIGRESS_BINARIES) -$(ARM64_OUT_LINUX)/higress: prebuild $(OUT) +$(ARM64_OUT_LINUX)/higress: GOPROXY=$(GOPROXY) GOOS=linux GOARCH=arm64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/linux_arm64/ $(HIGRESS_BINARIES) - .PHONY: build-hgctl build-hgctl: $(OUT) GOPROXY=$(GOPROXY) GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh $(OUT)/ $(HGCTL_BINARIES) @@ -125,7 +125,7 @@ include docker/docker.mk docker-build: docker.higress ## Build and push docker images to registry defined by $HUB and $TAG -docker-buildx-push: docker.higress-buildx +docker-buildx-push: clean-env docker.higress-buildx docker-build-base: docker buildx build --no-cache --platform linux/amd64,linux/arm64 -t ${HUB}/base:${BASE_VERSION} -f docker/Dockerfile.base . --push diff --git a/docker/docker.mk b/docker/docker.mk index ff608d3f53..aa01abdfc0 100644 --- a/docker/docker.mk +++ b/docker/docker.mk @@ -35,6 +35,6 @@ DOCKER_ALL_VARIANTS ?= debug distroless INCLUDE_UNTAGGED_DEFAULT ?= false DEFAULT_DISTRIBUTION=debug -HIGRESS_DOCKER_BUILDX_RULE ?= $(foreach VARIANT,$(DOCKER_BUILD_VARIANTS), time (mkdir -p $(HIGRESS_DOCKER_BUILD_TOP)/$@ && TARGET_ARCH=$(TARGET_ARCH) ./docker/docker-copy.sh $^ $(HIGRESS_DOCKER_BUILD_TOP)/$@ && cd $(HIGRESS_DOCKER_BUILD_TOP)/$@ $(BUILD_PRE) && docker buildx create --name higress --platform linux/amd64,linux/arm64 --use && docker buildx build --no-cache --platform linux/amd64,linux/arm64 $(BUILD_ARGS) --build-arg BASE_DISTRIBUTION=$(call normalize-tag,$(VARIANT)) -t $(HUB)/higress:$(TAG)$(call variant-tag,$(VARIANT)) -f Dockerfile.higress . --push ); ) +HIGRESS_DOCKER_BUILDX_RULE ?= $(foreach VARIANT,$(DOCKER_BUILD_VARIANTS), time (mkdir -p $(HIGRESS_DOCKER_BUILD_TOP)/$@ && TARGET_ARCH=$(TARGET_ARCH) ./docker/docker-copy.sh $^ $(HIGRESS_DOCKER_BUILD_TOP)/$@ && cd $(HIGRESS_DOCKER_BUILD_TOP)/$@ $(BUILD_PRE) && docker buildx create --name higress --node higress0 --platform linux/amd64,linux/arm64 --use && docker buildx build --no-cache --platform linux/amd64,linux/arm64 $(BUILD_ARGS) --build-arg BASE_DISTRIBUTION=$(call normalize-tag,$(VARIANT)) -t $(HUB)/higress:$(TAG)$(call variant-tag,$(VARIANT)) -f Dockerfile.higress . --push ); ) HIGRESS_DOCKER_RULE ?= $(foreach VARIANT,$(DOCKER_BUILD_VARIANTS), time (mkdir -p $(HIGRESS_DOCKER_BUILD_TOP)/$@ && TARGET_ARCH=$(TARGET_ARCH) ./docker/docker-copy.sh $^ $(HIGRESS_DOCKER_BUILD_TOP)/$@ && cd $(HIGRESS_DOCKER_BUILD_TOP)/$@ $(BUILD_PRE) && docker build $(BUILD_ARGS) --build-arg BASE_DISTRIBUTION=$(call normalize-tag,$(VARIANT)) -t $(HUB)/higress:$(TAG)$(call variant-tag,$(VARIANT)) -f Dockerfile.higress . ); )