Skip to content

Multi architecture support #946

Open
@Ravikc

Description

@Ravikc

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions