Skip to content

using docker buildx to build cross-platform image#817

Open
raohuaming wants to merge 6 commits intostreamnative:masterfrom
raohuaming:master
Open

using docker buildx to build cross-platform image#817
raohuaming wants to merge 6 commits intostreamnative:masterfrom
raohuaming:master

Conversation

@raohuaming
Copy link
Copy Markdown
Contributor

Motivation

The official image repo on Dockerhub currently only support linux/amd64, which is limited especially on arm platforms.

WeChatWorkScreenshot_5b85e4bf-ebd5-4169-97be-3052f1cdc455

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.

@github-actions
Copy link
Copy Markdown

@raohuaming:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@github-actions github-actions Bot added the doc-info-missing This pr needs to mark a document option in description label Aug 18, 2022
@raohuaming
Copy link
Copy Markdown
Contributor Author

@raohuaming:Thanks for your contribution. For this PR, do we need to update docs? (The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

Nope, it only affects how to publish docker images.

@jiangpengcheng
Copy link
Copy Markdown
Member

jiangpengcheng commented Aug 19, 2022

need to check whether the docker on the GitHub Action runner supports buildx

Comment thread docker/Dockerfile

FROM alpine:3.16.0

RUN apk add --no-cache \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, usually we only need to lock the docker image.

Copy link
Copy Markdown
Contributor

@nodece nodece left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, could you add a workflow to check the build?

@raohuaming
Copy link
Copy Markdown
Contributor Author

Overall looks good to me, could you add a workflow to check the build?

OK, should be done in a few days

@raohuaming
Copy link
Copy Markdown
Contributor Author

@nodece I have added a workflow(.github/workflows/image.yaml) to run an action to build multi-platform images and push to docker hub.

image

Comment thread .github/workflows/image.yml Outdated
VERSION=latest
platforms: linux/amd64,linux/arm64
push: true
tags: raohuaming/pulsarctl:latest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags: raohuaming/pulsarctl:latest
tags: streamnative/pulsarctl:latest

@@ -0,0 +1,37 @@
name: build multi-platforms image

on:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using pull_request.

Comment thread docker/Dockerfile

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FROM alpine:3.16.0
FROM alpine:3.16.2

Comment thread docker/Dockerfile
@@ -0,0 +1,29 @@
ARG VERSION=0.5.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ARG VERSION=0.5.0

Comment thread scripts/build.sh Outdated
raohuaming and others added 2 commits August 4, 2023 14:16
Co-authored-by: Zixuan Liu <nodeces@gmail.com>
Co-authored-by: Zixuan Liu <nodeces@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-info-missing This pr needs to mark a document option in description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants