Skip to content

Commit 3b5ab24

Browse files
authored
Merge pull request #89 from hzieba/arm64-docker
Build multiarch Docker image
2 parents 0028550 + eb45d71 commit 3b5ab24

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
FROM golang:latest AS builder
22

3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
36
ENV GO111MODULE=on \
7+
GOOS=${TARGETOS} \
8+
GOARCH=${TARGETARCH} \
49
CGO_ENABLED=0
510

611
WORKDIR /build
@@ -11,16 +16,11 @@ 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

2626
FROM scratch

Makefile

Lines changed: 10 additions & 7 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:
@@ -47,12 +50,12 @@ build-rpm:
4750
--iteration $(RELEASE) \
4851
--force \
4952
--rpm-compression bzip2 \
50-
--rpm-os linux \
53+
--rpm-os $(OS) \
5154
--url $(URL) \
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)