Skip to content

Commit 62db786

Browse files
authored
add option to build multi-platform image (#160)
Signed-off-by: Dmitry Shmulevich <[email protected]>
1 parent 5aa1c00 commit 62db786

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

.github/workflows/docker.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,26 @@ jobs:
4343
type=ref,event=branch
4444
type=sha,priority=100,prefix=,suffix=,format=short
4545
46+
# Set up QEMU for cross-platform builds
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
50+
# Set up Docker Buildx
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
4654
# Build and push Docker image with Buildx (don't push on PR)
4755
# https://github.com/docker/build-push-action
4856
- name: Build and push Docker image
4957
id: build-and-push
50-
uses: docker/build-push-action@v5
58+
uses: docker/build-push-action@v6
5159
with:
5260
context: .
5361
file: ./Dockerfile
54-
build-args: |
55-
TARGETOS=linux
56-
TARGETARCH=amd64
5762
push: ${{ github.event_name != 'pull_request' }}
63+
#build-args: |
64+
# TARGETOS=linux
65+
# TARGETARCH=amd64
66+
platforms: linux/amd64,linux/arm64
5867
tags: ${{ steps.meta.outputs.tags }}
5968
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM golang:1.23.3 AS builder
1+
# syntax=docker/dockerfile:1
2+
3+
FROM --platform=${TARGETOS}/${TARGETARCH} golang:1.23.3 AS builder
24

35
WORKDIR /go/src/github.com/NVIDIA/topograph
46
COPY . .
@@ -8,6 +10,6 @@ ARG TARGETARCH
810

911
RUN make build-${TARGETOS}-${TARGETARCH}
1012

11-
FROM gcr.io/distroless/static-debian11:nonroot
13+
FROM --platform=${TARGETOS}/${TARGETARCH} gcr.io/distroless/static-debian11:nonroot
1214

1315
COPY --from=builder /go/src/github.com/NVIDIA/topograph/bin/* /usr/local/bin/

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LINTER_BIN ?= golangci-lint
1616
DOCKER_BIN ?= docker
1717
GOOS ?= $(shell uname | tr '[:upper:]' '[:lower:]')
1818
GOARCH ?= $(shell arch | sed 's/x86_64/amd64/')
19-
TARGETS := topograph node-observer node-data-broker-initc toposim
19+
TARGETS := topograph node-observer node-data-broker-initc
2020
CMD_DIR := ./cmd
2121
OUTPUT_DIR := ./bin
2222

@@ -83,12 +83,19 @@ proto:
8383

8484
.PHONY: image-build
8585
image-build:
86-
$(DOCKER_BIN) build --build-arg TARGETOS=linux --build-arg TARGETARCH=amd64 -t $(IMAGE_REPO):$(IMAGE_TAG) -f ./Dockerfile .
86+
$(DOCKER_BIN) build --build-arg TARGETOS=$(GOOS) --build-arg TARGETARCH=$(GOARCH) -t $(IMAGE_REPO):$(IMAGE_TAG) -f ./Dockerfile .
8787

8888
.PHONY: image-push
8989
image-push: image-build
9090
$(DOCKER_BIN) push $(IMAGE_REPO):$(IMAGE_TAG)
9191

92+
.PHONY: docker
93+
docker:
94+
docker buildx create --use --name=crossplat --node=crossplat || true
95+
docker buildx build \
96+
--platform linux/amd64,linux/arm64 \
97+
-t $(IMAGE_REPO):$(IMAGE_TAG) -f ./Dockerfile --push .
98+
9299
.PHONY: ssl
93100
ssl:
94101
SSL_DIR=ssl ./scripts/configure-ssl.sh

0 commit comments

Comments
 (0)