Skip to content

Commit

Permalink
Add support for arm64 builds
Browse files Browse the repository at this point in the history
Rather than forcing nitriding to build against the amd64 architecture,
support arm64 builds by allowing the `ARCH` environment variable to
override the build architecture.

Also, update the example to automatically choose the build architecture
based on the architecture of the machine where the example is built and
run.
  • Loading branch information
jalaziz committed Dec 27, 2023
1 parent 69dce5c commit 3fc0ee9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ godeps = *.go go.mod go.sum
cover_out = cover.out
cover_html = cover.html

ARCH ?= amd64

all: lint test $(binary)

.PHONY: lint
Expand All @@ -24,7 +26,7 @@ $(cover_html): $(cover_out)
go tool cover -html=$(cover_out) -o $(cover_html)

$(binary): $(godeps)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -buildvcs=false -o $(binary)
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -ldflags="-s -w" -buildvcs=false -o $(binary)

.PHONY: clean
clean:
Expand Down
3 changes: 2 additions & 1 deletion example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WORKDIR /

# Clone the repository and build the stand-alone nitriding executable.
RUN git clone https://github.com/brave/nitriding-daemon.git
RUN make -C nitriding-daemon/ nitriding
ARG TARGETARCH
RUN ARCH=${TARGETARCH} make -C nitriding-daemon/ nitriding

# Use the intermediate builder image to add our files. This is necessary to
# avoid intermediate layers that contain inconsistent file permissions.
Expand Down
15 changes: 13 additions & 2 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ image_tag := $(prog):$(version)
image_tar := $(prog)-$(version)-kaniko.tar
image_eif := $(image_tar:%.tar=%.eif)

ARCH ?= $(shell uname -m)
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif

.PHONY: all
all: run

Expand All @@ -13,12 +21,15 @@ image: $(image_tar)
$(image_tar): Dockerfile service.py start.sh
docker run \
-v $(PWD):/workspace \
gcr.io/kaniko-project/executor:v1.9.2 \
gcr.io/kaniko-project/executor:v1.19.2 \
--reproducible \
--no-push \
--tarPath $(image_tar) \
--destination $(image_tag) \
--custom-platform linux/amd64
--build-arg TARGETPLATFORM=linux/$(ARCH) \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(ARCH) \
--custom-platform linux/$(ARCH)

$(image_eif): $(image_tar)
docker load -i $<
Expand Down

0 comments on commit 3fc0ee9

Please sign in to comment.