diff --git a/.github/workflows/publish_latest.yml b/.github/workflows/publish_latest.yml index fd55583b..8f41b9e7 100644 --- a/.github/workflows/publish_latest.yml +++ b/.github/workflows/publish_latest.yml @@ -18,13 +18,17 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - name: create docker images - run: | - make docker-create-all + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: 'arm64' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: push docker images + - name: build and push docker images env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | - make docker-push-latest + make docker-build-push-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 007a478d..39cf188d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: go-version-file: 'go.mod' cache: true check-latest: true - + - name: run goreleaser uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5 with: @@ -45,13 +45,17 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - name: create docker images - run: | - make docker-create-all + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: 'arm64' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: push docker images + - name: build and push docker images env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | - make docker-push + make docker-build-push diff --git a/Makefile b/Makefile index cea919b5..07f57268 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ BUILD_LDFLAGS := -s -w BUILD_LDFLAGS += -X github.com/target/flottbot/version.Version=${VERSION} GOLANGCI_LINT_VERSION := "v1.55.2" PACKAGES := $(shell go list ./... | grep -v /config-example/) +PLATFORM := "linux/amd64,linux/arm64" DOCKER_IMAGE ?= "target/flottbot" DOCKER_FLAVORS ?= golang ruby python @@ -76,29 +77,6 @@ build: clean # ┌┬┐┌─┐┌─┐┬┌─┌─┐┬─┐ # │││ ││ ├┴┐├┤ ├┬┘ # ─┴┘└─┘└─┘┴ ┴└─┘┴└─ -.PHONY: docker-base -docker-base: - @echo "Creating base $@ image" - @docker build \ - --build-arg "VERSION=$(VERSION)" \ - -f "./docker/Dockerfile" \ - -t $(DOCKER_IMAGE):$(VERSION) \ - -t $(DOCKER_IMAGE):latest . - -.PHONY: docker-flavors -docker-flavors: - @for flavor in $(DOCKER_FLAVORS); do \ - echo "Creating image for $$flavor"; \ - docker build \ - --build-arg "VERSION=$(VERSION)" \ - -f "./docker/Dockerfile.$$flavor" \ - -t $(DOCKER_IMAGE):$$flavor \ - -t $(DOCKER_IMAGE):$$flavor-$(VERSION) .; \ - done - -.PHONY: docker-create-all -docker-create-all: docker-base docker-flavors - .PHONY: docker-login docker-login: ifndef DOCKER_USERNAME @@ -109,28 +87,50 @@ docker-login: @echo "Logging into docker hub" @echo "$$DOCKER_PASSWORD" | docker login -u $$DOCKER_USERNAME --password-stdin -.PHONY: docker-push -docker-push: docker-login - @echo "Pushing $(DOCKER_IMAGE):$(VERSION) and :latest to docker hub" - @docker push $(DOCKER_IMAGE):$(VERSION) - @docker push $(DOCKER_IMAGE):latest - +.PHONY: docker-build-push-latest +docker-build-push-latest: docker-login + @echo "Building and pushing latest to docker hub..." + @echo "Building and pushing $(DOCKER_IMAGE):latest" + @docker buildx build \ + --progress=plain \ + --build-arg "VERSION=$(VERSION)" \ + --platform $(PLATFORM) \ + --file "./docker/Dockerfile" \ + --tag $(DOCKER_IMAGE):latest \ + --push . @for flavor in $(DOCKER_FLAVORS); do \ - echo "Pushing $(DOCKER_IMAGE):$$flavor to docker hub"; \ - docker push $(DOCKER_IMAGE):$$flavor; \ - docker push $(DOCKER_IMAGE):$$flavor-$(VERSION); \ + echo "Building and pushing $(DOCKER_IMAGE):$$flavor"; \ + docker buildx build \ + --progress=plain \ + --build-arg "VERSION=$(VERSION)" \ + --platform $(PLATFORM) \ + --file "./docker/Dockerfile.$$flavor" \ + --tag $(DOCKER_IMAGE):$$flavor \ + --push .; done -.PHONY: docker-push-latest -docker-push-latest: docker-login - @echo "Pushing to :latest images to docker hub..." - - @echo "Pushing $(DOCKER_IMAGE):latest" - @docker push $(DOCKER_IMAGE):latest - +.PHONY: docker-build-push +docker-build-push-latest: docker-login + @echo "Building and pushing $(VERSION) to docker hub..." + @echo "Building and pushing $(DOCKER_IMAGE):$(VERSION)" + @docker buildx build \ + --progress=plain \ + --build-arg "VERSION=$(VERSION)" \ + --platform $(PLATFORM) \ + --file "./docker/Dockerfile" \ + --tag $(DOCKER_IMAGE):$(VERSION) \ + --tag $(DOCKER_IMAGE):latest \ + --push . @for flavor in $(DOCKER_FLAVORS); do \ - echo "Pushing $(DOCKER_IMAGE):$$flavor to docker hub"; \ - docker push $(DOCKER_IMAGE):$$flavor; \ + echo "Building and pushing $(DOCKER_IMAGE):$$flavor-$(VERSION)"; \ + docker buildx build \ + --progress=plain \ + --build-arg "VERSION=$(VERSION)" \ + --platform $(PLATFORM) \ + --file "./docker/Dockerfile.$$flavor" \ + --tag $(DOCKER_IMAGE):$$flavor-$(VERSION) \ + --tag $(DOCKER_IMAGE):$$flavor \ + --push .; done # ┬─┐┬ ┬┌┐┌ diff --git a/docker/Dockerfile b/docker/Dockerfile index 54aafe7e..bf38e20c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,7 @@ -FROM docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build + +ARG TARGETOS +ARG TARGETARCH ARG VERSION # needed for vcs feature introduced in go 1.18+ @@ -12,7 +15,7 @@ RUN go mod download COPY / . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \ -o flottbot ./cmd/flottbot diff --git a/docker/Dockerfile.golang b/docker/Dockerfile.golang index 888bdcf4..0ab3519f 100644 --- a/docker/Dockerfile.golang +++ b/docker/Dockerfile.golang @@ -1,4 +1,7 @@ -FROM docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build + +ARG TARGETOS +ARG TARGETARCH ARG VERSION # needed for vcs feature introduced in go 1.18+ @@ -12,7 +15,7 @@ RUN go mod download COPY / . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \ -o flottbot ./cmd/flottbot diff --git a/docker/Dockerfile.python b/docker/Dockerfile.python index 9f562da3..7f251c96 100644 --- a/docker/Dockerfile.python +++ b/docker/Dockerfile.python @@ -1,4 +1,7 @@ -FROM docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build + +ARG TARGETOS +ARG TARGETARCH ARG VERSION # needed for vcs feature introduced in go 1.18+ @@ -12,7 +15,7 @@ RUN go mod download COPY / . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \ -o flottbot ./cmd/flottbot diff --git a/docker/Dockerfile.ruby b/docker/Dockerfile.ruby index 5dea5d8a..0efa92d2 100644 --- a/docker/Dockerfile.ruby +++ b/docker/Dockerfile.ruby @@ -1,4 +1,7 @@ -FROM docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-alpine@sha256:110b07af87238fbdc5f1df52b00927cf58ce3de358eeeb1854f10a8b5e5e1411 AS build + +ARG TARGETOS +ARG TARGETARCH ARG VERSION # needed for vcs feature introduced in go 1.18+ @@ -12,7 +15,7 @@ RUN go mod download COPY / . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \ -o flottbot ./cmd/flottbot