Last active
January 11, 2023 06:16
-
-
Save bamnet/b13d0f32d3128d0ceda8bb868e82ae9e to your computer and use it in GitHub Desktop.
Multiarch Go Builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:latest | |
services: | |
- docker:dind | |
stages: | |
- build | |
variables: | |
IMAGE: registry.gitlab.com/bamnet/njtdata | |
DOCKER_CLI_EXPERIMENTAL: enabled | |
before_script: | |
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY | |
build: | |
stage: build | |
script: | |
- docker build --build-arg opts="CGO_ENABLED=0 GOARCH=amd64" --pull -t $IMAGE:amd64 . | |
- docker push $IMAGE:amd64 | |
- docker build --build-arg opts="GOARCH=arm GOARM=6" --pull -t $IMAGE:arm32v6 . | |
- docker push $IMAGE:arm32v6 | |
- docker manifest create $IMAGE $IMAGE:amd64 $IMAGE:arm32v6 | |
- docker manifest annotate $IMAGE $IMAGE:arm32v6 --os linux --arch arm | |
- docker manifest push $IMAGE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:alpine as builder | |
RUN apk update && apk add git && apk add tzdata && apk add ca-certificates | |
COPY . $GOPATH/src/gitlab.com/bamnet/njtdata | |
WORKDIR $GOPATH/src/gitlab.com/bamnet/njtdata | |
RUN go get -d -v | |
ARG opts | |
RUN env ${opts} go build -o /go/bin/import | |
FROM scratch | |
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip /usr/local/go/lib/time/ | |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
COPY --from=builder /go/bin/import /go/bin/import | |
ENTRYPOINT ["/go/bin/import"] | |
CMD [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice thanks for creating that gist!