using docker buildx to build cross-platform image#817
using docker buildx to build cross-platform image#817raohuaming wants to merge 6 commits intostreamnative:masterfrom
Conversation
|
@raohuaming:Thanks for your contribution. For this PR, do we need to update docs? |
Nope, it only affects how to publish docker images. |
|
need to check whether the docker on the GitHub Action runner supports buildx |
|
|
||
| FROM alpine:3.16.0 | ||
|
|
||
| RUN apk add --no-cache \ |
There was a problem hiding this comment.
Could we remove this version?
There was a problem hiding this comment.
Basically it's a good practice to pin a version of the base image, in case the "latest" image become incompatible overtime, which also makes it reproducible overtime.
There was a problem hiding this comment.
Good catch, usually we only need to lock the docker image.
nodece
left a comment
There was a problem hiding this comment.
Overall looks good to me, could you add a workflow to check the build?
OK, should be done in a few days |
|
@nodece I have added a workflow(.github/workflows/image.yaml) to run an action to build multi-platform images and push to docker hub. |
| VERSION=latest | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: raohuaming/pulsarctl:latest |
There was a problem hiding this comment.
| tags: raohuaming/pulsarctl:latest | |
| tags: streamnative/pulsarctl:latest |
| @@ -0,0 +1,37 @@ | |||
| name: build multi-platforms image | |||
|
|
|||
| on: | |||
|
|
||
| RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o pulsarctl -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-${VERSION}" . | ||
|
|
||
| FROM alpine:3.16.0 |
There was a problem hiding this comment.
| FROM alpine:3.16.0 | |
| FROM alpine:3.16.2 |
| @@ -0,0 +1,29 @@ | |||
| ARG VERSION=0.5.0 | |||
There was a problem hiding this comment.
| ARG VERSION=0.5.0 |
Co-authored-by: Zixuan Liu <nodeces@gmail.com>
Co-authored-by: Zixuan Liu <nodeces@gmail.com>

Motivation
The official image repo on Dockerhub currently only support linux/amd64, which is limited especially on arm platforms.
Modifications
A new Dockerfile under docker dir was introduced to make it universal for cross building for different platforms.
Thd build script also updated to use buildx to build and push cross-platform images.