From 6ad30915eb456d0dec58607780b459a17641a05c Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:44:06 +0300 Subject: [PATCH 01/10] Add PLATFORM make variable; calculate it if undefined Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- scripts/common-envs.mk | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/common-envs.mk b/scripts/common-envs.mk index 99bc29eb..ff2ece4a 100644 --- a/scripts/common-envs.mk +++ b/scripts/common-envs.mk @@ -14,3 +14,16 @@ ifeq ($(COZYSTACK_VERSION),) $(shell git fetch upstream --tags) COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags)) endif + +# Calculate PLATFORM based on current docker daemon arch +ifndef PLATFORM + DOCKER_DAEMON_ARCH := $(shell docker info --format='{{.Architecture}}') + ifeq ($(DOCKER_DAEMON_ARCH),x86_64) + PLATFORM := linux/amd64 + else ifeq ($(DOCKER_DAEMON_ARCH),aarch64) + PLATFORM := linux/arm64 + else + $(error Unsupported architecture: "$(DOCKER_DAEMON_ARCH)") + endif + undefine DOCKER_DAEMON_ARCH +endif From 1e63b5e8ce150fbcdf5d16999d73203bbd78e4bc Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:46:12 +0300 Subject: [PATCH 02/10] system/cozystack-controller: add PLATFORM variable to Makefile Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- packages/system/cozystack-controller/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/system/cozystack-controller/Makefile b/packages/system/cozystack-controller/Makefile index a1db9b0a..aafaf036 100644 --- a/packages/system/cozystack-controller/Makefile +++ b/packages/system/cozystack-controller/Makefile @@ -9,6 +9,7 @@ image: image-cozystack-controller update-version image-cozystack-controller: docker buildx build -f images/cozystack-controller/Dockerfile ../../.. \ --provenance false \ + --platform=$(PLATFORM) --tag $(REGISTRY)/cozystack-controller:$(call settag,$(TAG)) \ --cache-from type=registry,ref=$(REGISTRY)/cozystack-controller:latest \ --cache-to type=inline \ From b4a04df6f3d9174efea1fb455b4e09cd66ff0dfc Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:54:45 +0300 Subject: [PATCH 03/10] system/cozystack-controller: add PLATFORM variable to Makefile: syntax Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- packages/system/cozystack-controller/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/system/cozystack-controller/Makefile b/packages/system/cozystack-controller/Makefile index aafaf036..17aa2f9b 100644 --- a/packages/system/cozystack-controller/Makefile +++ b/packages/system/cozystack-controller/Makefile @@ -9,7 +9,7 @@ image: image-cozystack-controller update-version image-cozystack-controller: docker buildx build -f images/cozystack-controller/Dockerfile ../../.. \ --provenance false \ - --platform=$(PLATFORM) + --platform=$(PLATFORM) \ --tag $(REGISTRY)/cozystack-controller:$(call settag,$(TAG)) \ --cache-from type=registry,ref=$(REGISTRY)/cozystack-controller:latest \ --cache-to type=inline \ From 57fefde732c21b3c5e6aea8c9e8f3fb307e2473a Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Fri, 2 May 2025 21:43:17 +0300 Subject: [PATCH 04/10] scrips/common-envs.mk: add BUILDER and PLATFORM calculation Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- scripts/common-envs.mk | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/scripts/common-envs.mk b/scripts/common-envs.mk index ff2ece4a..b1f7e77e 100644 --- a/scripts/common-envs.mk +++ b/scripts/common-envs.mk @@ -15,15 +15,7 @@ ifeq ($(COZYSTACK_VERSION),) COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags)) endif -# Calculate PLATFORM based on current docker daemon arch -ifndef PLATFORM - DOCKER_DAEMON_ARCH := $(shell docker info --format='{{.Architecture}}') - ifeq ($(DOCKER_DAEMON_ARCH),x86_64) - PLATFORM := linux/amd64 - else ifeq ($(DOCKER_DAEMON_ARCH),aarch64) - PLATFORM := linux/arm64 - else - $(error Unsupported architecture: "$(DOCKER_DAEMON_ARCH)") - endif - undefine DOCKER_DAEMON_ARCH -endif +# Get the name of the default docker buildx builder +BUILDER ?= $(shell docker buildx inspect | head -n2 | awk '/^Name:/{print $$NF}') +# Get platforms supported by the builder +PLATFORM ?= $(shell docker buildx inspect $(BUILDER) | egrep '^Platforms:' | egrep -o 'linux/amd64|linux/arm64' | sort -u | xargs | sed 's/ /,/g') From 15c9c4a0689021f0626e40528bb5004ba5fc8cda Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Fri, 2 May 2025 21:43:55 +0300 Subject: [PATCH 05/10] system/cozystack-controller: add PLATFORM and BUILDER variables to Makefile Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- packages/system/cozystack-controller/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/system/cozystack-controller/Makefile b/packages/system/cozystack-controller/Makefile index 17aa2f9b..a75faea9 100644 --- a/packages/system/cozystack-controller/Makefile +++ b/packages/system/cozystack-controller/Makefile @@ -9,6 +9,7 @@ image: image-cozystack-controller update-version image-cozystack-controller: docker buildx build -f images/cozystack-controller/Dockerfile ../../.. \ --provenance false \ + --builder=$(BUILDER) \ --platform=$(PLATFORM) \ --tag $(REGISTRY)/cozystack-controller:$(call settag,$(TAG)) \ --cache-from type=registry,ref=$(REGISTRY)/cozystack-controller:latest \ From 951ba75d938e5df5b65ca20b34b97bdc4d15ba4f Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Fri, 2 May 2025 23:51:37 +0300 Subject: [PATCH 06/10] scripts/common-envs.mk: add --bootsrap flag to inspects Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- scripts/common-envs.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/common-envs.mk b/scripts/common-envs.mk index b1f7e77e..79b08799 100644 --- a/scripts/common-envs.mk +++ b/scripts/common-envs.mk @@ -16,6 +16,6 @@ ifeq ($(COZYSTACK_VERSION),) endif # Get the name of the default docker buildx builder -BUILDER ?= $(shell docker buildx inspect | head -n2 | awk '/^Name:/{print $$NF}') +BUILDER ?= $(shell docker buildx inspect --bootstrap | head -n2 | awk '/^Name:/{print $$NF}') # Get platforms supported by the builder -PLATFORM ?= $(shell docker buildx inspect $(BUILDER) | egrep '^Platforms:' | egrep -o 'linux/amd64|linux/arm64' | sort -u | xargs | sed 's/ /,/g') +PLATFORM ?= $(shell docker buildx inspect --bootstrap $(BUILDER) | egrep '^Platforms:' | egrep -o 'linux/amd64|linux/arm64' | sort -u | xargs | sed 's/ /,/g') From bbb93c647d8cd23a3af3571aadc4aada7ea18ed8 Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Tue, 6 May 2025 16:24:26 +0300 Subject: [PATCH 07/10] scripts/common-envs.mk: commit suggestions after a review Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- scripts/common-envs.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/common-envs.mk b/scripts/common-envs.mk index 79b08799..a2a4c103 100644 --- a/scripts/common-envs.mk +++ b/scripts/common-envs.mk @@ -16,6 +16,9 @@ ifeq ($(COZYSTACK_VERSION),) endif # Get the name of the default docker buildx builder -BUILDER ?= $(shell docker buildx inspect --bootstrap | head -n2 | awk '/^Name:/{print $$NF}') +BUILDER ?= $(shell jq -r '.Name' ~/.docker/buildx/current) # Get platforms supported by the builder +# TODO: figure out how to get runners status dynamically, in json +# PLATFORM ?= $(shell jq -r '.Nodes[] | .Platforms | map(.os + "/" + .architecture) | join(",")' ~/.docker/buildx/instances/$(BUILDER)) PLATFORM ?= $(shell docker buildx inspect --bootstrap $(BUILDER) | egrep '^Platforms:' | egrep -o 'linux/amd64|linux/arm64' | sort -u | xargs | sed 's/ /,/g') + From 57ac6148655ec7648f02f8c414a3985afdcb47b0 Mon Sep 17 00:00:00 2001 From: nbykov0 <166552198+nbykov0@users.noreply.github.com> Date: Tue, 6 May 2025 19:31:22 +0300 Subject: [PATCH 08/10] Makefile: add buildx version requirement Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 99309f4e..66efb02c 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ build-deps: @tar --version | grep -q GNU || (echo "GNU tar is required" && exit 1) @sed --version | grep -q GNU || (echo "GNU sed is required" && exit 1) @awk --version | grep -q GNU || (echo "GNU awk is required" && exit 1) + @docker info --format=json | jq -r '"v0.13.0\n\(.ClientInfo.Plugins[] | select(.Name == "buildx") | .Version)"' | sort -CV || (echo "docker buildx plugin version >=0.13.0 is required" && exit 1) build: build-deps make -C packages/apps/http-cache image From 13139dd71d4202c41c439d505d07f4e74c6dbf94 Mon Sep 17 00:00:00 2001 From: Ubuntu <166552198+nbykov0@users.noreply.github.com> Date: Wed, 7 May 2025 22:56:07 +0300 Subject: [PATCH 09/10] Revert "Makefile: add buildx version requirement" This reverts commit 8d367533550236fc587bd5f236046c15f6b7609a. The check it introduced is not needed. Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 66efb02c..99309f4e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ build-deps: @tar --version | grep -q GNU || (echo "GNU tar is required" && exit 1) @sed --version | grep -q GNU || (echo "GNU sed is required" && exit 1) @awk --version | grep -q GNU || (echo "GNU awk is required" && exit 1) - @docker info --format=json | jq -r '"v0.13.0\n\(.ClientInfo.Plugins[] | select(.Name == "buildx") | .Version)"' | sort -CV || (echo "docker buildx plugin version >=0.13.0 is required" && exit 1) build: build-deps make -C packages/apps/http-cache image From 2349ff61c12ae9d04ce611c990fdfec5aee371e5 Mon Sep 17 00:00:00 2001 From: Ubuntu <166552198+nbykov0@users.noreply.github.com> Date: Wed, 7 May 2025 23:25:51 +0300 Subject: [PATCH 10/10] scripts/common-envs.mk: add PLATFORM calculation with json parsing Signed-off-by: nbykov0 <166552198+nbykov0@users.noreply.github.com> --- scripts/common-envs.mk | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/common-envs.mk b/scripts/common-envs.mk index a2a4c103..98f4652a 100644 --- a/scripts/common-envs.mk +++ b/scripts/common-envs.mk @@ -15,10 +15,8 @@ ifeq ($(COZYSTACK_VERSION),) COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags)) endif -# Get the name of the default docker buildx builder -BUILDER ?= $(shell jq -r '.Name' ~/.docker/buildx/current) +# Get the name of the selected docker buildx builder +BUILDER ?= $(shell docker buildx inspect --bootstrap | head -n2 | awk '/^Name:/{print $$NF}') # Get platforms supported by the builder -# TODO: figure out how to get runners status dynamically, in json -# PLATFORM ?= $(shell jq -r '.Nodes[] | .Platforms | map(.os + "/" + .architecture) | join(",")' ~/.docker/buildx/instances/$(BUILDER)) -PLATFORM ?= $(shell docker buildx inspect --bootstrap $(BUILDER) | egrep '^Platforms:' | egrep -o 'linux/amd64|linux/arm64' | sort -u | xargs | sed 's/ /,/g') +PLATFORM ?= $(shell docker buildx ls --format=json | jq -r 'select(.Name == "$(BUILDER)") | [.Nodes[].Platforms // []] | flatten | unique | map(select(test("^linux/amd64$$|^linux/arm64$$"))) | join(",")')