Created
February 14, 2024 14:57
-
-
Save jahands/470b89be6400844af3e72a19374669d3 to your computer and use it in GitHub Desktop.
Go multiplatform docker 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
VERSION 0.8 | |
PROJECT jahands/docker | |
# Local targets: | |
tidy: | |
LOCALLY | |
RUN go mod tidy | |
build-local: | |
LOCALLY | |
RUN go build -o dist/mycli | |
# Normal targets: | |
setup-project: | |
FROM golang:1.22 | |
WORKDIR /work | |
COPY go.mod go.sum . | |
RUN go mod download | |
COPY --dir commands lib . | |
COPY .earthlyignore main.go . | |
build: | |
FROM +setup-project | |
ARG --required GOOS | |
ARG --required GOARCH | |
CACHE $(go env GOCACHE) | |
RUN GOOS=$GOOS GOARCH=$GOARCH go build -o dist/$GOOS/$GOARCH/mycli | |
SAVE ARTIFACT dist | |
build-docker: | |
ARG --required DOCKER_TAG | |
ARG --required PLATFORM | |
ARG --required GOOS | |
ARG --required GOARCH | |
BUILD +build --GOOS=$GOOS --GOARCH=$GOARCH | |
FROM --platform=$PLATFORM debian:12-slim | |
WORKDIR /work | |
COPY --chmod=700 +build/dist/$GOOS/$GOARCH/mycli . | |
ENTRYPOINT ["./mycli"] | |
SAVE IMAGE --push github.com/jahands/mycli:$DOCKER_TAG | |
IF [ "$DOCKER_TAG" = "main" ] | |
SAVE IMAGE --push github.com/jahands/mycli:latest | |
END | |
docker: | |
ARG --required DOCKER_TAG | |
BUILD +build-docker --PLATFORM=linux/amd64 --GOOS=linux --GOARCH=amd64 --DOCKER_TAG=$DOCKER_TAG | |
BUILD +build-docker --PLATFORM=linux/arm/v7 --GOOS=linux --GOARCH=arm --DOCKER_TAG=$DOCKER_TAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment