Skip to content

Commit b5d98ba

Browse files
committed
Build multiarch Docker image
1 parent 0028550 commit b5d98ba

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,19 @@ jobs:
111111
with:
112112
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
113113

114+
- name: Set up QEMU
115+
uses: docker/setup-qemu-action@v3
116+
117+
- name: Set up Docker Buildx
118+
uses: docker/setup-buildx-action@v3
119+
114120
- name: Build and push Docker image
115121
id: push
116122
uses: docker/build-push-action@v6
117123
with:
118124
context: .
119125
push: true
126+
platforms: linux/amd64,linux/arm64
120127
tags: ${{ steps.meta.outputs.tags }}
121128
labels: ${{ steps.meta.outputs.labels }}
122129

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
FROM golang:latest AS builder
1+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:latest AS builder
2+
3+
ARG BUILDPLATFORM
4+
ARG TARGETPLATFORM
5+
ARG TARGETOS
6+
ARG TARGETARCH
27

38
ENV GO111MODULE=on \
49
CGO_ENABLED=0
@@ -11,19 +16,14 @@ COPY go.sum .
1116
RUN go mod download
1217

1318
COPY . .
14-
RUN make build
19+
RUN OS=${TARGETOS} ARCH=${TARGETARCH} make build
1520

1621
WORKDIR /dist
1722

1823
RUN cp /build/cortex-tenant ./cortex-tenant
19-
20-
RUN ldd cortex-tenant | tr -s '[:blank:]' '\n' | grep '^/' | \
21-
xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;'
22-
RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/
23-
2424
RUN mkdir /data && cp /build/deploy/cortex-tenant.yml /data/cortex-tenant.yml
2525

26-
FROM scratch
26+
FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch
2727

2828
COPY --chown=65534:0 --from=builder /dist /
2929

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ RELEASE := 1
1010
GO ?= go
1111
OUT := .out
1212

13+
OS ?= linux
14+
ARCH ?= amd64
15+
1316
all: rpm deb
1417

1518
build:
16-
go test ./... && \
17-
GOARCH=amd64 \
18-
GOOS=linux \
19-
CGO_ENABLED=0 \
19+
export GOARCH=$(ARCH)
20+
export GOOS=$(OS)
21+
export CGO_ENABLED=0
22+
go test ./...
2023
$(GO) build -ldflags "-s -w -extldflags \"-static\" -X main.Version=$(VERSION)"
2124

2225
prepare:
@@ -52,7 +55,7 @@ build-rpm:
5255
--description "$(DESCRIPTION)" \
5356
-m "$(MAINTAINER)" \
5457
--license "$(LICENSE)" \
55-
-a amd64 \
58+
-a $(ARCH) \
5659
.
5760

5861
build-deb:
@@ -76,5 +79,5 @@ build-deb:
7679
--description "$(DESCRIPTION)" \
7780
-m "$(MAINTAINER)" \
7881
--license "$(LICENSE)" \
79-
-a amd64 \
82+
-a $(ARCH) \
8083
.

0 commit comments

Comments
 (0)