Skip to content

Commit 1d599d2

Browse files
committed
feat: Enable multi-arch builds
AMD64 and ARM64 for now. The Tyk plugin depends on the tykio/tyk-plugin-compiler image which does not support any other architecture than AMD64 for now. See TykTechnologies/tyk-build-env#4 ARMv7 was tried but Kong and Tyk do not support it and it may introduce issues due to its 32-bit architecture that we don't want to have to support. Signed-off-by: Felix Kaechele <[email protected]>
1 parent c39a242 commit 1d599d2

File tree

6 files changed

+94
-12
lines changed

6 files changed

+94
-12
lines changed

.github/workflows/ci.yml

+67-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
- name: Check out code
2525
uses: actions/checkout@v2
2626

27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v1
29+
30+
- name: Set up Docker Buildx
31+
id: buildx
32+
uses: docker/setup-buildx-action@v1
33+
2734
- name: Check licenses
2835
env:
2936
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -32,8 +39,66 @@ jobs:
3239
- name: Run verification
3340
run: make check
3441

35-
- name: Build Docker image
36-
run: make docker
42+
- name: Get current timestamp
43+
id: timestamp
44+
run: echo "::set-output name=timestamp::$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
45+
46+
- name: Build APIClarity
47+
uses: docker/build-push-action@v2
48+
with:
49+
context: .
50+
platforms: linux/amd64,linux/arm64
51+
tags: ghcr.io/apiclarity/apiclarity:${{ github.sha }}
52+
file: Dockerfile
53+
cache-from: type=local,src=/tmp/.buildx-cache
54+
cache-to: type=local,dest=/tmp/.buildx-cache
55+
build-args: |
56+
VERSION=${{ github.sha }}
57+
BUILD_TIMESTAMP=${{ steps.timestamp.outputs.timestamp }}
58+
COMMIT_HASH=${{ github.sha }}
59+
60+
- name: Build Kong plugin
61+
uses: docker/build-push-action@v2
62+
with:
63+
context: plugins
64+
platforms: linux/amd64,linux/arm64
65+
tags: ghcr.io/apiclarity/kong-plugin:${{ github.sha }}
66+
file: plugins/Dockerfile.kong
67+
cache-from: type=local,src=/tmp/.buildx-cache
68+
cache-to: type=local,dest=/tmp/.buildx-cache
69+
70+
- name: Fix Tyk Plugin API dep
71+
id: tyk-dep
72+
run: |
73+
cd plugins/gateway/tyk/v3.2.2
74+
go mod edit -replace github.com/apiclarity/apiclarity/plugins/[email protected]=./../api
75+
go mod edit -replace github.com/apiclarity/apiclarity/plugins/[email protected]=./../common
76+
77+
- name: Build Tyk plugin
78+
uses: docker/build-push-action@v2
79+
with:
80+
context: plugins
81+
platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures
82+
tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:${{ github.sha }}
83+
file: plugins/Dockerfile.tyk.v3.2.2
84+
cache-from: type=local,src=/tmp/.buildx-cache
85+
cache-to: type=local,dest=/tmp/.buildx-cache
86+
87+
- name: Undo Tyk Plugin API dep change
88+
id: undo-tyk-dep
89+
run: git checkout -- plugins/gateway/tyk/v3.2.2/go.mod
90+
91+
- name: Build passive taper
92+
uses: docker/build-push-action@v2
93+
with:
94+
context: plugins
95+
platforms: linux/amd64,linux/arm64
96+
tags: ghcr.io/apiclarity/passive-taper:${{ github.sha }}
97+
file: plugins/Dockerfile.taper
98+
cache-from: type=local,src=/tmp/.buildx-cache
99+
cache-to: type=local,dest=/tmp/.buildx-cache
100+
build-args: |
101+
VERSION=${{ github.sha }}
37102
38103
lint_chart:
39104
name: Lint Helm Chart

.github/workflows/docker.yml

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
with:
1515
submodules: true
1616

17+
- name: Set up QEMU
18+
uses: docker/setup-qemu-action@v1
19+
1720
- name: Set up Docker Buildx
1821
uses: docker/setup-buildx-action@v1
1922

@@ -40,6 +43,7 @@ jobs:
4043
uses: docker/build-push-action@v2
4144
with:
4245
context: .
46+
platforms: linux/amd64,linux/arm64
4347
tags: ghcr.io/apiclarity/apiclarity:latest
4448
file: Dockerfile
4549
push: true
@@ -54,6 +58,7 @@ jobs:
5458
uses: docker/build-push-action@v2
5559
with:
5660
context: plugins
61+
platforms: linux/amd64,linux/arm64
5762
tags: ghcr.io/apiclarity/kong-plugin:latest
5863
file: plugins/Dockerfile.kong
5964
push: true
@@ -71,6 +76,7 @@ jobs:
7176
uses: docker/build-push-action@v2
7277
with:
7378
context: plugins
79+
platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures
7480
tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:latest
7581
file: plugins/Dockerfile.tyk.v3.2.2
7682
push: true
@@ -81,6 +87,7 @@ jobs:
8187
uses: docker/build-push-action@v2
8288
with:
8389
context: plugins
90+
platforms: linux/amd64,linux/arm64
8491
tags: ghcr.io/apiclarity/passive-taper:latest
8592
file: plugins/Dockerfile.taper
8693
push: true

.github/workflows/release.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ jobs:
8181
git tag --annotate --message "Tag for release $tag" "$tag"
8282
git push origin "refs/tags/$tag"
8383
84+
- name: Set up QEMU
85+
uses: docker/setup-qemu-action@v1
86+
8487
- name: Set up Docker Buildx
8588
uses: docker/setup-buildx-action@v1
8689

@@ -107,6 +110,7 @@ jobs:
107110
uses: docker/build-push-action@v2
108111
with:
109112
context: .
113+
platforms: linux/amd64,linux/arm64
110114
tags: ghcr.io/apiclarity/apiclarity:${{ github.event.inputs.version }}
111115
file: Dockerfile
112116
push: true
@@ -121,6 +125,7 @@ jobs:
121125
uses: docker/build-push-action@v2
122126
with:
123127
context: plugins
128+
platforms: linux/amd64,linux/arm64
124129
tags: ghcr.io/apiclarity/kong-plugin:${{ github.event.inputs.version }}
125130
file: plugins/Dockerfile.kong
126131
push: true
@@ -138,6 +143,7 @@ jobs:
138143
uses: docker/build-push-action@v2
139144
with:
140145
context: plugins
146+
platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures
141147
tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:${{ github.event.inputs.version }}
142148
file: plugins/Dockerfile.tyk.v3.2.2
143149
push: true
@@ -152,6 +158,7 @@ jobs:
152158
uses: docker/build-push-action@v2
153159
with:
154160
context: plugins
161+
platforms: linux/amd64,linux/arm64
155162
tags: ghcr.io/apiclarity/passive-taper:${{ github.event.inputs.version }}
156163
file: plugins/Dockerfile.taper
157164
push: true

Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ RUN npm i
77
RUN npm run build
88

99

10-
FROM golang:1.16.6-alpine AS builder
10+
FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder
1111

12-
RUN apk add --update --no-cache gcc g++
12+
RUN apk add --no-cache build-base
1313

1414
WORKDIR /build
1515
COPY api ./api
@@ -25,7 +25,8 @@ ARG COMMIT_HASH
2525

2626
# Copy and build backend code
2727
COPY backend .
28-
RUN go build -ldflags="-s -w \
28+
ARG TARGETOS TARGETARCH
29+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w \
2930
-X 'github.com/apiclarity/apiclarity/backend/pkg/version.Version=${VERSION}' \
3031
-X 'github.com/apiclarity/apiclarity/backend/pkg/version.CommitHash=${COMMIT_HASH}' \
3132
-X 'github.com/apiclarity/apiclarity/backend/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o backend ./cmd/backend/main.go

plugins/Dockerfile.kong

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM golang:1.16.6-alpine AS builder
1+
FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder
22

33
## Note: this Dockerfile will only be built from the plugins context
44

5-
RUN apk add --update --no-cache gcc g++
5+
RUN apk add --no-cache build-base
66

77
WORKDIR /plugins
88
COPY api ./api
@@ -22,7 +22,8 @@ RUN go mod download
2222
COPY gateway/kong .
2323

2424
# Build the plugin.
25-
RUN go build -o bin/kong-plugin plugin.go
25+
ARG TARGETOS TARGETARCH
26+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o bin/kong-plugin plugin.go
2627

2728
FROM busybox
2829
COPY --from=builder ["/plugins/gateway/kong/bin/kong-plugin", "/kong-plugin"]

plugins/Dockerfile.taper

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
FROM golang:1.16.6-alpine AS builder
1+
FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder
22

33
# Set necessary environment variables needed for our image.
4-
ENV CGO_ENABLED=1 GOOS=linux GOARCH=amd64
4+
ARG TARGETOS TARGETARCH
5+
ENV CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH
56

6-
RUN apk add libpcap-dev gcc g++ make bash
7+
RUN apk add --no-cache build-base binutils-gold libpcap-dev
78

89
WORKDIR /plugins
910

@@ -27,7 +28,7 @@ RUN go build -buildmode=plugin -o ../http.so .
2728

2829
FROM alpine:3.14
2930

30-
RUN apk add bash libpcap-dev tcpdump
31+
RUN apk add --no-cache bash libpcap tcpdump
3132
WORKDIR /app
3233

3334
# Copy binary and config files from /build to root folder of scratch container.

0 commit comments

Comments
 (0)