Multi architecture support #946

Open
opened 2023-01-27 07:40:21 -06:00 by Ravikc · 0 comments
Ravikc commented 2023-01-27 07:40:21 -06:00 (Migrated from github.com)

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!

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 in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: jcarr/git2go#946
No description provided.