Skip to content

Commit c45832d

Browse files
committed
Build multi-platform eden-sdn image
Refactored the sdn Makefile to support building eden-sdn images for multiple platforms using Docker Buildx and LinuxKit. Each target architecture now produces a distinct sdn-<arch>-bios.img and is handled via dedicated Makefile targets (e.g., build-vm-img-linux-arm64). Dockerfile.vm has been updated to use the correct image based on the target architecture at build time using the standard TARGETARCH argument. Signed-off-by: Milan Lenco <milan@zededa.com>
1 parent b26e5fa commit c45832d

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

sdn/Makefile

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
DOCKER_TARGET ?= build
22
DOCKER_PLATFORM ?= $(shell uname -s | tr '[A-Z]' '[a-z]')/$(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
3-
DOCKER_ARCH := $(word 2,$(subst /, ,$(DOCKER_PLATFORM)))
4-
LINUXKIT ?= linuxkit
53

4+
# Split comma-separated DOCKER_PLATFORM list into space-separated
5+
COMMA := ,
6+
EMPTY :=
7+
SPACE := $(EMPTY) $(EMPTY)
8+
DOCKER_PLATFORM_LIST := $(subst $(COMMA),$(SPACE),$(DOCKER_PLATFORM))
9+
10+
# Generate target names like build-vm-img-linux-arm64 from DOCKER_PLATFORM_LIST
11+
DOCKER_PLATFORM_TARGETS := $(foreach platform,$(DOCKER_PLATFORM_LIST),build-vm-img-$(subst /,-,$(platform)))
12+
13+
LINUXKIT ?= linuxkit
614
SDN_REPO ?= "lfedge/eden-sdn"
7-
SDN_DIR=$(CURDIR)
8-
SDN_VM_DIR=$(SDN_DIR)/vm
9-
SDN_SERVICE_CONTAINER := $(shell $(LINUXKIT) pkg show-tag $(SDN_VM_DIR))-$(DOCKER_ARCH)
15+
SDN_DIR := $(CURDIR)
16+
SDN_VM_DIR := $(SDN_DIR)/vm
1017
SDN_VERSION := $(shell grep -v '^#' VERSION | head -n1)
1118

12-
build:
13-
@$(LINUXKIT) pkg build --platforms $(DOCKER_PLATFORM) --build-yml build.yml $(SDN_VM_DIR)
14-
@sed 's|SDN_SERVICE_CONTAINER|$(SDN_SERVICE_CONTAINER)|g' $(SDN_VM_DIR)/sdn-vm.yml.in | \
15-
$(LINUXKIT) build --docker --arch $(DOCKER_ARCH) --name sdn --format raw-bios --dir $(SDN_VM_DIR) -
16-
@docker buildx build --$(DOCKER_TARGET) --platform $(DOCKER_PLATFORM) \
17-
-f $(SDN_VM_DIR)/Dockerfile.vm --build-arg SDN_VERSION=$(SDN_VERSION) \
18-
--tag $(SDN_REPO):$(SDN_VERSION) $(SDN_VM_DIR)
19+
build-vm-img-%:
20+
PLATFORM=$(subst -,/,$*); \
21+
ARCH=$$(echo $$PLATFORM | cut -d/ -f2); \
22+
SDN_SVC_CONT_TAG=`$(LINUXKIT) pkg show-tag $(SDN_VM_DIR)`-$$ARCH; \
23+
$(LINUXKIT) pkg build --platforms $$PLATFORM --build-yml build.yml $(SDN_VM_DIR); \
24+
sed 's|SDN_SERVICE_CONTAINER|'"$$SDN_SVC_CONT_TAG"'|g' $(SDN_VM_DIR)/sdn-vm.yml.in | \
25+
$(LINUXKIT) build --docker --arch $$ARCH --name sdn-$$ARCH --format raw-bios --dir $(SDN_VM_DIR) -
26+
27+
build: $(DOCKER_PLATFORM_TARGETS)
28+
docker buildx build --$(DOCKER_TARGET) --platform $(DOCKER_PLATFORM) \
29+
-f $(SDN_VM_DIR)/Dockerfile.vm \
30+
--build-arg SDN_VERSION=$(SDN_VERSION) \
31+
--tag $(SDN_REPO):$(SDN_VERSION) \
32+
$(SDN_VM_DIR)

sdn/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ You can build this container using the following Makefile target:
106106
make DOCKER_TARGET=build DOCKER_PLATFORM=<os>/<arch> push-multi-arch-sdn
107107
```
108108

109+
It is also possible to build a multi-platform image by specifying multiple platforms
110+
in the `DOCKER_PLATFORM` variable:
111+
112+
```shell
113+
make DOCKER_TARGET=build DOCKER_PLATFORM=<os1>/<arch1>,<os2>/<arch2>,... push-multi-arch-sdn
114+
```
115+
116+
Replace `<os>/<arch>` entries with the desired target platforms (e.g., `linux/amd64,linux/arm64`).
117+
109118
To additionally push the image to the `lfedge/eden-sdn` repository,
110119
run with `DOCKER_TARGET=push`.
111120

sdn/vm/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
sdn-bios.img
1+
sdn-arm64-bios.img
2+
sdn-amd64-bios.img

sdn/vm/Dockerfile.vm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ FROM lfedge/eve-alpine:12.1.0
77

88
COPY --from=tools /out/ /
99
COPY entrypoint.sh /
10-
COPY sdn-bios.img /bits/
10+
11+
ARG TARGETARCH
12+
COPY sdn-${TARGETARCH}-bios.img /bits/sdn-bios.img
1113

1214
ARG SDN_VERSION
1315
RUN echo "$SDN_VERSION" > /bits/sdn-version

0 commit comments

Comments
 (0)