Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi architecture support #946

Open
Ravikc opened this issue Jan 27, 2023 · 0 comments
Open

Multi architecture support #946

Ravikc opened this issue Jan 27, 2023 · 0 comments

Comments

@Ravikc
Copy link

Ravikc commented Jan 27, 2023

I am building a go application that depends on git2go and needs to be packaged as a docker image and will need to support linux/amd64 and linux/arm64 architectures.

Dockerfile:

FROM golang:1.17.6-alpine3.15 as builder

WORKDIR /workspace
COPY go.mod go.mod
COPY go.sum go.sum

RUN apk add --no-cache libgit2 libgit2-dev git gcc g++ pkgconfig

RUN go mod download

COPY main.go main.go

ARG TARGETARCH TARGETOS

RUN CGO_ENABLED=1 GO111MODULE=on GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags static,system_libgit2 -a -o gitoperations main.go

FROM alpine:3.15 as runner

WORKDIR /
COPY --from=builder /workspace/gitoperations .
ENTRYPOINT ["/gitoperations"]

Build commands:

docker buildx create --name gitops --use
docker buildx build --platform=linux/amd64,linux/arm64 --pull .

This setup works but building for the arch different from host machine's arch is extremely slow.
Examples:

  1. On arm64 M1 mac (without rossetta): Building linux/arm64 executable takes ~30s and linux/amd64 takes ~300seconds.
  2. On our amd64 Jenkins CI system: Building linux/arm64 executable takes 10x longer than building linux/amd64 executable.

Is there any way to speed up these build times? I suspect this slow times are because docker is using qemu to build for the different architecture and if I can somehow provide a C compiler that's able to cross-compile for both the architectures using the CC env variable then it would help bring down the build times.

But I cant seem to find any such compiler toolchain.
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant