Skip to content

Commit 521ddd8

Browse files
mtardykkourt
authored andcommitted
Makefile & Dockerfile: add multi arch build for arm64
Add multi arch cross compilation in the Dockerfile and multi arch capabilities in the Makefile. Signed-off-by: Mahe Tardy <[email protected]>
1 parent 9b638ac commit 521ddd8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
FROM golang:1.22.0@sha256:7b297d9abee021bab9046e492506b3c2da8a3722cbf301653186545ecc1e00bb as gobuilder
1+
FROM --platform=$BUILDPLATFORM golang:1.22.0@sha256:7b297d9abee021bab9046e492506b3c2da8a3722cbf301653186545ecc1e00bb as gobuilder
22
WORKDIR /src/little-vm-helper
33
COPY . .
4-
RUN make little-vm-helper
4+
ARG TARGETARCH
5+
RUN TARGET_ARCH=$TARGETARCH make little-vm-helper
56

67
FROM busybox@sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74
78
COPY --from=gobuilder /src/little-vm-helper/lvh /usr/bin/lvh

Makefile

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ GO_BUILD_LDFLAGS =
88
GO_BUILD_LDFLAGS += -X 'github.com/cilium/little-vm-helper/pkg/version.Version=$(VERSION)'
99
GO_BUILD_FLAGS += -ldflags "$(GO_BUILD_LDFLAGS)"
1010

11+
UNAME_M := $(shell uname -m)
12+
ifeq ($(UNAME_M),x86_64)
13+
TARGET_ARCH ?= amd64
14+
else ifeq ($(UNAME_M),aarch64)
15+
TARGET_ARCH ?= arm64
16+
else
17+
TARGET_ARCH ?= amd64
18+
endif
1119

1220
all: tests little-vm-helper
1321

@@ -16,15 +24,15 @@ tests:
1624
$(GO) test -cover ./...
1725

1826
little-vm-helper: FORCE
19-
CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) ./cmd/lvh
27+
GOARCH=${TARGET_ARCH} CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) ./cmd/lvh
2028

2129
.PHONY: image
2230
image:
23-
$(DOCKER) build -f Dockerfile -t $(OCIREPO) .
31+
$(DOCKER) build -f Dockerfile --platform=linux/${TARGET_ARCH} -t $(OCIREPO) .
2432

2533
.PHONY: install
2634
install:
27-
CGO_ENABLED=0 $(GO) install ./cmd/lvh
35+
GOARCH=${TARGET_ARCH} CGO_ENABLED=0 $(GO) install ./cmd/lvh
2836

2937
clean:
3038
rm -f lvh

0 commit comments

Comments
 (0)