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"]
This setup works but building for the arch different from host machine's arch is extremely slow. Examples:
On arm64 M1 mac (without rossetta): Building linux/arm64 executable takes ~30s and linux/amd64 takes ~300seconds.
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 supportlinux/amd64
andlinux/arm64
architectures.Dockerfile:
Build commands:
This setup works but building for the arch different from host machine's arch is extremely slow.
Examples:
linux/arm64
executable takes ~30s andlinux/amd64
takes ~300seconds.linux/arm64
executable takes 10x longer than buildinglinux/amd64
executable.Is there any way to speed up these build times? I suspect this slow times are because
docker
is usingqemu
to build for the different architecture and if I can somehow provide aC
compiler that's able to cross-compile for both the architectures using theCC
env variable then it would help bring down the build times.But I cant seem to find any such compiler toolchain.
Thanks in advance!