From 14ac1ccc2e98c6d9de17b4e3d8866264a9419223 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 17 Aug 2025 16:43:36 +0200 Subject: [PATCH 01/27] publish container to ghcr --- .github/workflows/container-publish.yml | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/container-publish.yml diff --git a/.github/workflows/container-publish.yml b/.github/workflows/container-publish.yml new file mode 100644 index 0000000..128893f --- /dev/null +++ b/.github/workflows/container-publish.yml @@ -0,0 +1,41 @@ +name: Build and Push Image +on: [push] + +jobs: + build: + name: Build and push image + runs-on: ubuntu-24.04 + container: + image: quay.io/podman/stable:latest + options: --privileged + + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build image + id: build + run: | + podman build -t cli . + podman tag cli ghcr.io/${{ github.repository }}:latest + podman tag cli ghcr.io/${{ github.repository }}:${{ github.sha }} + + - name: Push to registry + #if: ${{ startsWith(github.ref, 'refs/heads/master') }} + id: push + uses: redhat-actions/push-to-registry@v2 + with: + image: ghcr.io/${{ github.repository }} + tags: latest ${{ github.sha }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Print image url + run: echo "Image pushed to ${{ steps.push.outputs.registry-paths }}" From ac753a38badc624972b0bb007af2cc6c8e46ca18 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 17 Aug 2025 16:47:04 +0200 Subject: [PATCH 02/27] explicit base image name --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 99c4b4b..b320904 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # build -FROM golang:1.18-stretch AS build-env +FROM docker.io/library/golang:1.18-stretch AS build-env WORKDIR /src From 4ad8c93933e457175a7959a84ca2fe027c593358 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 17 Aug 2025 16:51:14 +0200 Subject: [PATCH 03/27] Use latest go --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b320904..4b24cb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # build -FROM docker.io/library/golang:1.18-stretch AS build-env +FROM docker.io/library/golang:latest AS build-env WORKDIR /src From b85e1f257b49dc08aec35fa1f5cd9515225a2bc6 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:21:19 +0200 Subject: [PATCH 04/27] Update build pipeline --- .github/workflows/build.yml | 66 +++++++++++++++++++++++++ .github/workflows/container-publish.yml | 41 --------------- .github/workflows/release.yml | 37 -------------- Dockerfile | 28 ----------- GO_VERSION | 1 + Makefile | 47 ++++++++++++++++-- docker/Dockerfile | 45 +++++++++++++++++ go.mod | 4 +- 8 files changed, 159 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/container-publish.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 Dockerfile create mode 100644 GO_VERSION create mode 100644 docker/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9933932 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,66 @@ +name: Release + +on: + push: + tags: + - v* + +jobs: + binary: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go environment + uses: actions/setup-go@v5 + with: + go-version: 1.22.x + stable: true + + - name: Get dependencies + run: go get -v -t -d ./... + + - name: Build + run: | + TAG=$(git describe --tags --abbrev=0) + GIT_TAG=$TAG make clean build + + - name: Create release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/* + tag: ${{ github.ref }} + overwrite: true + file_glob: true + + image: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - if: startsWith(github.ref, 'refs/tags/v') + run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + - if: startsWith(github.ref, 'refs/tags/v') + run: | + export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" + echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV + - if: startsWith(github.ref, 'refs/tags/v') + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - if: startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + - if: startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.DOCKER_GHCR_USER }} + password: ${{ secrets.DOCKER_GHCR_PASS }} + - if: startsWith(github.ref, 'refs/tags/v') + run: | + make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker diff --git a/.github/workflows/container-publish.yml b/.github/workflows/container-publish.yml deleted file mode 100644 index 128893f..0000000 --- a/.github/workflows/container-publish.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build and Push Image -on: [push] - -jobs: - build: - name: Build and push image - runs-on: ubuntu-24.04 - container: - image: quay.io/podman/stable:latest - options: --privileged - - permissions: - contents: read - packages: write - attestations: write - id-token: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Build image - id: build - run: | - podman build -t cli . - podman tag cli ghcr.io/${{ github.repository }}:latest - podman tag cli ghcr.io/${{ github.repository }}:${{ github.sha }} - - - name: Push to registry - #if: ${{ startsWith(github.ref, 'refs/heads/master') }} - id: push - uses: redhat-actions/push-to-registry@v2 - with: - image: ghcr.io/${{ github.repository }} - tags: latest ${{ github.sha }} - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ github.token }} - - - name: Print image url - run: echo "Image pushed to ${{ steps.push.outputs.registry-paths }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 3970b83..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release - -on: - push: - tags: - - v* - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Go environment - uses: actions/setup-go@v5 - with: - go-version: 1.22.x - stable: true - - - name: Get dependencies - run: go get -v -t -d ./... - - - name: Build - run: | - TAG=$(git describe --tags --abbrev=0) - GIT_TAG=$TAG make clean build - - - name: Create release - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: build/* - tag: ${{ github.ref }} - overwrite: true - file_glob: true diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4b24cb5..0000000 --- a/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -# build -FROM docker.io/library/golang:latest AS build-env - -WORKDIR /src - -ADD . . - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o app . - -# run -FROM alpine:3.16 - -RUN apk add --no-cache \ - ca-certificates - -RUN addgroup -S app \ - && adduser -S -g app app - -WORKDIR /home/app - -COPY --from=build-env /src/app . - -RUN chown -R app:app ./ - -USER app -ENV USER=app - -ENTRYPOINT ["./app"] diff --git a/GO_VERSION b/GO_VERSION new file mode 100644 index 0000000..3e940eb --- /dev/null +++ b/GO_VERSION @@ -0,0 +1 @@ +1.24.1 \ No newline at end of file diff --git a/Makefile b/Makefile index a6e7bc9..93e9f2a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,48 @@ -BUILD_DIR=./build +SHELL := /bin/bash -clean: - rm -rf ${BUILD_DIR} +# Env var inputs for container builds +# IMAGE: The name of the image to build, regardless of the registry and the tag. Any image +# will be built for docker hub (docker.io) and github (ghcr.io) container registry. +# PLATFORM: The platform for which the image should be built, defaults to all linux platforms. +# DOCKER_TEST_LEVEL: Whether some tests should be executed during the build of the container. +IMAGE ?= gotify/cli +PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 +DOCKER_TEST_LEVEL ?= 0 + +# Resolve go version +ifdef GOTOOLCHAIN + GO_VERSION=$(GOTOOLCHAIN) +else + GO_VERSION=$(shell go mod edit -json | jq -r .Toolchain | sed -e 's/go//') +endif +DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS" + +require-version: + if [ -n ${VERSION} ] && [[ $$VERSION == "v"* ]]; then echo "The version may not start with v" && exit 1; fi + if [ -z ${VERSION} ]; then echo "Need to set VERSION" && exit 1; fi; + +build-docker-multiarch: require-version + docker buildx build --sbom=true \ + $(if $(DOCKER_BUILD_PUSH),--push) \ + -t docker.io/${IMAGE}:latest \ + -t docker.io/${IMAGE}:${VERSION} \ + -t docker.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2) \ + -t docker.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1) \ + -t ghcr.io/${IMAGE}:latest \ + -t ghcr.io/${IMAGE}:${VERSION} \ + -t ghcr.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2) \ + -t ghcr.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1) \ + --build-arg RUN_TESTS=$(DOCKER_TEST_LEVEL) \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg LD_FLAGS="$$LD_FLAGS" \ + --platform $(PLATFORM) \ + -f docker/Dockerfile . + +build-docker: build-docker-multiarch + +_build_within_docker: OUTPUT = gotify-app +_build_within_docker: + ${DOCKER_GO_BUILD} -o ${OUTPUT} build: if [ '$(shell echo "${GIT_TAG}" | cut -c 1 )' != 'v' ]; then exit 1; fi; diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e7b367f --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,45 @@ +ARG BUILDKIT_SBOM_SCAN_CONTEXT=true +# Suppress warning about invalid variable expansion +ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION +ARG DEBIAN=sid-slim +ARG BUILDPLATFORM +ARG TARGETPLATFORM + +# Hack to normalize platform to match the chosed build image +# Get the gotify/build image tag +ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-} +ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} + +# --- Go Builder --- + +FROM --platform=${BUILDPLATFORM} docker.io/gotify/build:${GO_VERSION}-${__TARGETPLATFORM_GO_NOTATION} AS builder + +ARG RUN_TESTS=0 # 0=never, 1=native only +ARG LD_FLAGS="" +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -yq --no-install-recommends \ + ca-certificates \ + git + +COPY . /src/gotify + +RUN cd /src/gotify && \ + if [ "$RUN_TESTS" = "1" ] && [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then \ + go test -v ./...; \ + fi && \ + LD_FLAGS=${LD_FLAGS} make OUTPUT=/target/app/gotify-cli _build_within_docker + +FROM debian:${DEBIAN} + +WORKDIR /app + +RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -yq --no-install-recommends \ + tzdata \ + curl \ + ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=builder /target / + +ENTRYPOINT ["./gotify-cli"] diff --git a/go.mod b/go.mod index ea7acc4..cf9532f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/gotify/cli/v2 -go 1.18 +go 1.23.0 + +toolchain go1.24.1 require ( github.com/adrg/xdg v0.4.0 From b2f0e3bd779c1742c209fecbea9d0d07bea2984a Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:35:02 +0200 Subject: [PATCH 05/27] Add dev branch build --- .github/workflows/build.yml | 52 ++++++++++++++++++++++++++----------- Makefile | 16 ++++++++++++ 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9933932..f8b0495 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,28 +39,50 @@ jobs: image: runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: - - uses: actions/checkout@v4 - - if: startsWith(github.ref, 'refs/tags/v') + - name: Checkout repository + uses: actions/checkout@v4 + - name: Store version in environment variable + if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV - - if: startsWith(github.ref, 'refs/tags/v') + - name: Store commit in environment variable + if: startsWith(github.ref, 'refs/tags/v') + run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV + - name: Setup build flags + if: startsWith(github.ref, 'refs/tags/v') run: | export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV - - if: startsWith(github.ref, 'refs/tags/v') - name: Set up Docker Buildx + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - if: startsWith(github.ref, 'refs/tags/v') - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASS }} - - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/v') + # - name: Authenticate to Docker Hub registry + # uses: docker/login-action@v3 + # with: + # registry: docker.io + # username: ${{ secrets.DOCKER_USER }} + # password: ${{ secrets.DOCKER_PASS }} + - name: Authenticate to Github Container registry uses: docker/login-action@v3 with: registry: ghcr.io - username: ${{ secrets.DOCKER_GHCR_USER }} - password: ${{ secrets.DOCKER_GHCR_PASS }} - - if: startsWith(github.ref, 'refs/tags/v') + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Build and push the release images + if: startsWith(github.ref, 'refs/tags/v') + run: | + make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch + - name: Build and push the development images + if: startsWith(github.ref, 'refs/heads/master') + run: | + make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev + - name: Build the development images + if: startsWith(github.ref, 'refs/heads/master') run: | - make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker + make IMAGE=${{ github.repository }} build-docker-multiarch-dev diff --git a/Makefile b/Makefile index 93e9f2a..5a0ffa4 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ require-version: if [ -n ${VERSION} ] && [[ $$VERSION == "v"* ]]; then echo "The version may not start with v" && exit 1; fi if [ -z ${VERSION} ]; then echo "Need to set VERSION" && exit 1; fi; +require-commit: + if [ -z ${COMMIT} ]; then echo "Need to set COMMIT" && exit 1; fi; + build-docker-multiarch: require-version docker buildx build --sbom=true \ $(if $(DOCKER_BUILD_PUSH),--push) \ @@ -38,6 +41,19 @@ build-docker-multiarch: require-version --platform $(PLATFORM) \ -f docker/Dockerfile . +build-docker-multiarch-dev: require-commit + docker buildx build --sbom=true \ + $(if $(DOCKER_BUILD_PUSH),--push) \ + -t docker.io/${IMAGE}:dev \ + -t docker.io/${IMAGE}:${COMMIT} \ + -t ghcr.io/${IMAGE}:dev \ + -t ghcr.io/${IMAGE}:${COMMIT} \ + --build-arg RUN_TESTS=$(DOCKER_TEST_LEVEL) \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg LD_FLAGS="$$LD_FLAGS" \ + --platform $(PLATFORM) \ + -f docker/Dockerfile . + build-docker: build-docker-multiarch _build_within_docker: OUTPUT = gotify-app From 0e2620afb79403a2458f06834f608e868f75846c Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:37:59 +0200 Subject: [PATCH 06/27] Build on push --- .github/workflows/build.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8b0495..37759eb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,6 @@ name: Release -on: - push: - tags: - - v* +on: push jobs: binary: @@ -28,6 +25,7 @@ jobs: GIT_TAG=$TAG make clean build - name: Create release + if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} @@ -60,8 +58,8 @@ jobs: export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 if: startsWith(github.ref, 'refs/tags/v') + uses: docker/setup-buildx-action@v3 # - name: Authenticate to Docker Hub registry # uses: docker/login-action@v3 # with: From d7eec7c590e6ff5f3960d28535924c511cce539a Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:38:28 +0200 Subject: [PATCH 07/27] 1.23 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cf9532f..0ce0a12 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gotify/cli/v2 -go 1.23.0 +go 1.23 toolchain go1.24.1 From 639288916cc5048e63eaebd2278a63a245f61286 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:39:16 +0200 Subject: [PATCH 08/27] Build on dev branch --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 37759eb..eda2bb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,6 @@ jobs: run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev - name: Build the development images - if: startsWith(github.ref, 'refs/heads/master') + if: not startsWith(github.ref, 'refs/heads/master') run: | make IMAGE=${{ github.repository }} build-docker-multiarch-dev From 565b937fabe412a5530db0ffa271f477cc42d17a Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:41:15 +0200 Subject: [PATCH 09/27] Build binary on release only --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eda2bb0..900a0e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: push jobs: binary: + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: @@ -25,7 +26,6 @@ jobs: GIT_TAG=$TAG make clean build - name: Create release - if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} From ded5e8ee2a383fe54319758a6ac71605ca571500 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:42:48 +0200 Subject: [PATCH 10/27] Fix syntax --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 900a0e1..be4a334 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,6 @@ jobs: run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev - name: Build the development images - if: not startsWith(github.ref, 'refs/heads/master') + if: ${{ !startsWith(github.ref, 'refs/heads/master') }} run: | make IMAGE=${{ github.repository }} build-docker-multiarch-dev From 9e0d2e167e0adce6ab282ed15b39306bcd80a5a0 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:44:01 +0200 Subject: [PATCH 11/27] No matrix --- .github/workflows/check.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index b8f6932..43b4019 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -3,14 +3,11 @@ on: [push, pull_request] jobs: check: runs-on: ubuntu-latest - strategy: - matrix: - go: [1.20.x, 1.21.x, 1.22.x] steps: - name: Setup Go environment uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go }} + go-version: 1.24.x stable: true - name: Check out code into the Go module directory From edc472cc5397967c62e4632dc366aebbaeec4cb7 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:44:48 +0200 Subject: [PATCH 12/27] Always add commit --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index be4a334..380d8b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,6 @@ jobs: if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV - name: Store commit in environment variable - if: startsWith(github.ref, 'refs/tags/v') run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV - name: Setup build flags if: startsWith(github.ref, 'refs/tags/v') From 69234857302fe087cf9e6947765d81a5b32fb796 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:47:48 +0200 Subject: [PATCH 13/27] QEMU? --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 380d8b9..1053081 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Go environment uses: actions/setup-go@v5 with: - go-version: 1.22.x + go-version: 1.24.x stable: true - name: Get dependencies @@ -59,6 +59,8 @@ jobs: - name: Set up Docker Buildx if: startsWith(github.ref, 'refs/tags/v') uses: docker/setup-buildx-action@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 # - name: Authenticate to Docker Hub registry # uses: docker/login-action@v3 # with: From b2321aba7a9b919dca2be43b411c24280cf15cb6 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Tue, 19 Aug 2025 23:54:09 +0200 Subject: [PATCH 14/27] Add --provenance --- .github/workflows/build.yml | 1 - Makefile | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1053081..d1c687c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,7 +57,6 @@ jobs: export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV - name: Set up Docker Buildx - if: startsWith(github.ref, 'refs/tags/v') uses: docker/setup-buildx-action@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/Makefile b/Makefile index 5a0ffa4..0b1ba43 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ require-commit: if [ -z ${COMMIT} ]; then echo "Need to set COMMIT" && exit 1; fi; build-docker-multiarch: require-version - docker buildx build --sbom=true \ + docker buildx build --sbom=true --provenance=true \ $(if $(DOCKER_BUILD_PUSH),--push) \ -t docker.io/${IMAGE}:latest \ -t docker.io/${IMAGE}:${VERSION} \ @@ -42,7 +42,7 @@ build-docker-multiarch: require-version -f docker/Dockerfile . build-docker-multiarch-dev: require-commit - docker buildx build --sbom=true \ + docker buildx build --sbom=true --provenance=true \ $(if $(DOCKER_BUILD_PUSH),--push) \ -t docker.io/${IMAGE}:dev \ -t docker.io/${IMAGE}:${COMMIT} \ @@ -54,8 +54,6 @@ build-docker-multiarch-dev: require-commit --platform $(PLATFORM) \ -f docker/Dockerfile . -build-docker: build-docker-multiarch - _build_within_docker: OUTPUT = gotify-app _build_within_docker: ${DOCKER_GO_BUILD} -o ${OUTPUT} From 6fc33878009d2dcea8db981c2493f736ca8e4922 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Wed, 20 Aug 2025 00:05:28 +0200 Subject: [PATCH 15/27] Login to docker hub --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1c687c..dc2eb6c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,12 +60,12 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # - name: Authenticate to Docker Hub registry - # uses: docker/login-action@v3 - # with: - # registry: docker.io - # username: ${{ secrets.DOCKER_USER }} - # password: ${{ secrets.DOCKER_PASS }} + - name: Authenticate to Docker Hub registry + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} - name: Authenticate to Github Container registry uses: docker/login-action@v3 with: From 2eac4bd9dbd39c23fdf0ddc1cd31211d5b53a685 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Wed, 20 Aug 2025 00:06:40 +0200 Subject: [PATCH 16/27] push! --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc2eb6c..8482d52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,7 @@ jobs: run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch - name: Build and push the development images - if: startsWith(github.ref, 'refs/heads/master') + #if: startsWith(github.ref, 'refs/heads/master') run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev - name: Build the development images From 96f1f9c213c2d5192fecdfb452b83639fed8cb73 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Wed, 20 Aug 2025 20:31:00 +0200 Subject: [PATCH 17/27] Space up the steps --- .github/workflows/build.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8482d52..107df6d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,40 +46,50 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Store version in environment variable if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + - name: Store commit in environment variable run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV + - name: Setup build flags if: startsWith(github.ref, 'refs/tags/v') run: | export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Authenticate to Docker Hub registry uses: docker/login-action@v3 with: registry: docker.io username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASS }} + - name: Authenticate to Github Container registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} + - name: Build and push the release images if: startsWith(github.ref, 'refs/tags/v') run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch + - name: Build and push the development images - #if: startsWith(github.ref, 'refs/heads/master') + if: startsWith(github.ref, 'refs/heads/master') run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev + - name: Build the development images if: ${{ !startsWith(github.ref, 'refs/heads/master') }} run: | From d0385922deb91d7d734e5f9d1ef68030182a2d67 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Thu, 21 Aug 2025 18:29:20 +0200 Subject: [PATCH 18/27] Setup build flag for any build --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 107df6d..00b4349 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,6 @@ jobs: run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV - name: Setup build flags - if: startsWith(github.ref, 'refs/tags/v') run: | export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV From b6c45caa38066335d0283d365bab16f21304e776 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 16:25:43 +0200 Subject: [PATCH 19/27] Drop tests from build --- docker/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e7b367f..b4fcc9e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,7 +14,6 @@ ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} FROM --platform=${BUILDPLATFORM} docker.io/gotify/build:${GO_VERSION}-${__TARGETPLATFORM_GO_NOTATION} AS builder -ARG RUN_TESTS=0 # 0=never, 1=native only ARG LD_FLAGS="" ENV DEBIAN_FRONTEND=noninteractive @@ -25,9 +24,6 @@ RUN apt-get update && apt-get install -yq --no-install-recommends \ COPY . /src/gotify RUN cd /src/gotify && \ - if [ "$RUN_TESTS" = "1" ] && [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then \ - go test -v ./...; \ - fi && \ LD_FLAGS=${LD_FLAGS} make OUTPUT=/target/app/gotify-cli _build_within_docker FROM debian:${DEBIAN} From a729bb9035492be7632af2b0e0d4f34a324af701 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 16:29:12 +0200 Subject: [PATCH 20/27] Remove spaces from build file --- .github/workflows/build.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00b4349..cfb768b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,49 +46,49 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - + - name: Store version in environment variable if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV - + - name: Store commit in environment variable run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV - + - name: Setup build flags run: | export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - + - name: Authenticate to Docker Hub registry uses: docker/login-action@v3 with: registry: docker.io username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASS }} - + - name: Authenticate to Github Container registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - + - name: Build and push the release images if: startsWith(github.ref, 'refs/tags/v') run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch - + - name: Build and push the development images if: startsWith(github.ref, 'refs/heads/master') run: | make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev - + - name: Build the development images if: ${{ !startsWith(github.ref, 'refs/heads/master') }} run: | From 06298838b57ddf8ed8b7b10131539cc5fdc2bb49 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 16:45:20 +0200 Subject: [PATCH 21/27] Drop -dev logic --- .github/workflows/build.yml | 22 ++++++++------------- Makefile | 38 ++++++++++--------------------------- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfb768b..0a0ea05 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,10 +47,14 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Store version in environment variable + - name: Store version in environment variable if this is a release tag if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + - name: Enable images push + if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }} + run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV + - name: Store commit in environment variable run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV @@ -79,17 +83,7 @@ jobs: username: ${{ github.actor }} password: ${{ github.token }} - - name: Build and push the release images - if: startsWith(github.ref, 'refs/tags/v') - run: | - make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch - - - name: Build and push the development images - if: startsWith(github.ref, 'refs/heads/master') - run: | - make IMAGE=${{ github.repository }} DOCKER_BUILD_PUSH=true build-docker-multiarch-dev - - - name: Build the development images - if: ${{ !startsWith(github.ref, 'refs/heads/master') }} + - name: Build and push the images run: | - make IMAGE=${{ github.repository }} build-docker-multiarch-dev + make REGISTRY=docker.io IMAGE=${{ github.repository }} build-docker-multiarch + make REGISTRY=ghcr.io IMAGE=${{ github.repository }} build-docker-multiarch diff --git a/Makefile b/Makefile index 0b1ba43..ea6a83e 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ SHELL := /bin/bash # PLATFORM: The platform for which the image should be built, defaults to all linux platforms. # DOCKER_TEST_LEVEL: Whether some tests should be executed during the build of the container. IMAGE ?= gotify/cli +REGISTRY ?= docker.io PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 DOCKER_TEST_LEVEL ?= 0 @@ -17,38 +18,19 @@ else endif DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS" -require-version: - if [ -n ${VERSION} ] && [[ $$VERSION == "v"* ]]; then echo "The version may not start with v" && exit 1; fi - if [ -z ${VERSION} ]; then echo "Need to set VERSION" && exit 1; fi; - require-commit: if [ -z ${COMMIT} ]; then echo "Need to set COMMIT" && exit 1; fi; -build-docker-multiarch: require-version - docker buildx build --sbom=true --provenance=true \ - $(if $(DOCKER_BUILD_PUSH),--push) \ - -t docker.io/${IMAGE}:latest \ - -t docker.io/${IMAGE}:${VERSION} \ - -t docker.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2) \ - -t docker.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1) \ - -t ghcr.io/${IMAGE}:latest \ - -t ghcr.io/${IMAGE}:${VERSION} \ - -t ghcr.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2) \ - -t ghcr.io/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1) \ - --build-arg RUN_TESTS=$(DOCKER_TEST_LEVEL) \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg LD_FLAGS="$$LD_FLAGS" \ - --platform $(PLATFORM) \ - -f docker/Dockerfile . - -build-docker-multiarch-dev: require-commit - docker buildx build --sbom=true --provenance=true \ +build-docker-multiarch: require-commit + docker buildx build \ + --sbom=true \ + --provenance=true \ $(if $(DOCKER_BUILD_PUSH),--push) \ - -t docker.io/${IMAGE}:dev \ - -t docker.io/${IMAGE}:${COMMIT} \ - -t ghcr.io/${IMAGE}:dev \ - -t ghcr.io/${IMAGE}:${COMMIT} \ - --build-arg RUN_TESTS=$(DOCKER_TEST_LEVEL) \ + -t ${REGISTRY}/${IMAGE}:${COMMIT} \ + $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:latest) \ + $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:${VERSION}) \ + $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2)) \ + $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1)) \ --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg LD_FLAGS="$$LD_FLAGS" \ --platform $(PLATFORM) \ From 82d3379db8efc3ac28cf2051044a2470bb0f3e70 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 21:01:20 +0200 Subject: [PATCH 22/27] Update makefile comments --- Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ea6a83e..250efb8 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,12 @@ SHELL := /bin/bash # Env var inputs for container builds -# IMAGE: The name of the image to build, regardless of the registry and the tag. Any image -# will be built for docker hub (docker.io) and github (ghcr.io) container registry. -# PLATFORM: The platform for which the image should be built, defaults to all linux platforms. -# DOCKER_TEST_LEVEL: Whether some tests should be executed during the build of the container. -IMAGE ?= gotify/cli +# REGISTRY: The registry to which the build image should be pushed to. Defaults to "docker.io" (Docker Hub) +# IMAGE: The name of the image to build and publish in the afore mentioned registry. Defaults to "gotify/cli" +# PLATFORM: The platform for which the image should be built, defaults to amd64, arm64, i386, arm/v7 and riscv64 REGISTRY ?= docker.io +IMAGE ?= gotify/cli PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 -DOCKER_TEST_LEVEL ?= 0 # Resolve go version ifdef GOTOOLCHAIN From 1618d10e44e64070a9783279ee2d5eafaf25121e Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 21:03:40 +0200 Subject: [PATCH 23/27] Remove unused GO_VERSION file --- GO_VERSION | 1 - 1 file changed, 1 deletion(-) delete mode 100644 GO_VERSION diff --git a/GO_VERSION b/GO_VERSION deleted file mode 100644 index 3e940eb..0000000 --- a/GO_VERSION +++ /dev/null @@ -1 +0,0 @@ -1.24.1 \ No newline at end of file From cba03ddf914ce9664bdb9b7639f9942046428765 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 21:03:59 +0200 Subject: [PATCH 24/27] Use golang image instead of gotify/build --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index b4fcc9e..239e298 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -12,7 +12,7 @@ ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} # --- Go Builder --- -FROM --platform=${BUILDPLATFORM} docker.io/gotify/build:${GO_VERSION}-${__TARGETPLATFORM_GO_NOTATION} AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.24 AS builder ARG LD_FLAGS="" ENV DEBIAN_FRONTEND=noninteractive From a452bc3593d8118e83214b331f55fc869052b1c4 Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 24 Aug 2025 21:41:02 +0200 Subject: [PATCH 25/27] Set build flags in makefile --- .github/workflows/build.yml | 8 -------- Makefile | 26 +++++++++++++++----------- docker/Dockerfile | 3 +-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a0ea05..cbe7b65 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,14 +55,6 @@ jobs: if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }} run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV - - name: Store commit in environment variable - run: echo "COMMIT=${{ github.sha }}" >> $GITHUB_ENV - - - name: Setup build flags - run: | - export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod" - echo "LD_FLAGS=$LD_FLAGS" >> $GITHUB_ENV - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/Makefile b/Makefile index 250efb8..9f77e3b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL := /bin/bash -# Env var inputs for container builds +# Env var inputs for container image builds # REGISTRY: The registry to which the build image should be pushed to. Defaults to "docker.io" (Docker Hub) # IMAGE: The name of the image to build and publish in the afore mentioned registry. Defaults to "gotify/cli" # PLATFORM: The platform for which the image should be built, defaults to amd64, arm64, i386, arm/v7 and riscv64 @@ -8,6 +8,17 @@ REGISTRY ?= docker.io IMAGE ?= gotify/cli PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 +# Env var inputs for all builds +# VERSION: The version for which the container image or the binary is being built. This variable has not default. +# When it is not provided, no version will be specified in the built package. +# COMMIT: The commit of this project for which the cli is being built, for reference in the tool's "version" command. +# Default to git's HEAD +# LD_FLAGS: Build flags, for the tool's "version" command. Defaults to current date, commit and version (if any). +COMMIT ?= $(shell git rev-parse --verify HEAD) +LD_FLAGS ?= $(if $(VERSION),-X main.Version=${VERSION}) \ + -X main.BuildDate=$(shell date "+%F-%T") \ + -X main.Commit=${COMMIT} + # Resolve go version ifdef GOTOOLCHAIN GO_VERSION=$(GOTOOLCHAIN) @@ -16,13 +27,8 @@ else endif DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS" -require-commit: - if [ -z ${COMMIT} ]; then echo "Need to set COMMIT" && exit 1; fi; - -build-docker-multiarch: require-commit +build-docker-multiarch: docker buildx build \ - --sbom=true \ - --provenance=true \ $(if $(DOCKER_BUILD_PUSH),--push) \ -t ${REGISTRY}/${IMAGE}:${COMMIT} \ $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:latest) \ @@ -30,17 +36,15 @@ build-docker-multiarch: require-commit $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2)) \ $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1)) \ --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg LD_FLAGS="$$LD_FLAGS" \ + --build-arg LD_FLAGS="$(LD_FLAGS)" \ --platform $(PLATFORM) \ -f docker/Dockerfile . -_build_within_docker: OUTPUT = gotify-app +_build_within_docker: OUTPUT = gotify-cli _build_within_docker: ${DOCKER_GO_BUILD} -o ${OUTPUT} build: - if [ '$(shell echo "${GIT_TAG}" | cut -c 1 )' != 'v' ]; then exit 1; fi; - $(eval LD_FLAGS := -X main.Version=$(shell echo ${GIT_TAG} | cut -c 2-) -X main.BuildDate=$(shell date "+%F-%T") -X main.Commit=$(shell git rev-parse --verify HEAD)) CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-386.exe cli.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-linux-amd64 cli.go diff --git a/docker/Dockerfile b/docker/Dockerfile index 239e298..462fb8b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,8 +11,7 @@ ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-} ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} # --- Go Builder --- - -FROM --platform=${BUILDPLATFORM} docker.io/golang:1.24 AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION} AS builder ARG LD_FLAGS="" ENV DEBIAN_FRONTEND=noninteractive From 7a8e8ca957be547d90d0cbcdf954b7980260106a Mon Sep 17 00:00:00 2001 From: Guillaume Everarts de Velp Date: Sun, 31 Aug 2025 17:42:47 +0200 Subject: [PATCH 26/27] Build with alpine --- docker/Dockerfile | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 462fb8b..e362cbf 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,30 +11,21 @@ ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-} ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} # --- Go Builder --- -FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION} AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION}-alpine AS builder ARG LD_FLAGS="" -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -yq --no-install-recommends \ - ca-certificates \ - git +RUN apk add --no-cache ca-certificates git make bash COPY . /src/gotify RUN cd /src/gotify && \ LD_FLAGS=${LD_FLAGS} make OUTPUT=/target/app/gotify-cli _build_within_docker -FROM debian:${DEBIAN} +FROM docker.io/library/alpine:latest -WORKDIR /app +RUN apk add --no-cache ca-certificates -RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -yq --no-install-recommends \ - tzdata \ - curl \ - ca-certificates && \ - rm -rf /var/lib/apt/lists/* +COPY --from=builder /target/app/gotify-cli /gotify-cli -COPY --from=builder /target / - -ENTRYPOINT ["./gotify-cli"] +ENTRYPOINT ["/gotify-cli"] From b22c811310758cc01fa348f39c22d9857d480acd Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sun, 31 Aug 2025 21:20:13 +0200 Subject: [PATCH 27/27] wip --- .github/workflows/build.yml | 53 +++++++++++-------------------------- .github/workflows/check.yml | 7 +++++ Makefile | 20 ++++++-------- docker/Dockerfile | 25 +++++++---------- 4 files changed, 41 insertions(+), 64 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cbe7b65..45977f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,25 +8,16 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Go environment - uses: actions/setup-go@v5 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: 1.24.x stable: true - - name: Get dependencies - run: go get -v -t -d ./... - - - name: Build - run: | - TAG=$(git describe --tags --abbrev=0) - GIT_TAG=$TAG make clean build + - run: go get -v -t -d ./... + - run: make VERSION=${GITHUB_REF/refs\/tags\/v/} clean build - - name: Create release - uses: svenstaro/upload-release-action@v2 + - uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: build/* @@ -35,6 +26,7 @@ jobs: file_glob: true image: + if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }} runs-on: ubuntu-latest permissions: @@ -44,38 +36,25 @@ jobs: id-token: write steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Store version in environment variable if this is a release tag - if: startsWith(github.ref, 'refs/tags/v') + - if: startsWith(github.ref, 'refs/tags/v') run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + - run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV - - name: Enable images push - if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }} - run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Authenticate to Docker Hub registry - uses: docker/login-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/setup-qemu-action@v3 + - uses: docker/login-action@v3 with: registry: docker.io username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASS }} - - - name: Authenticate to Github Container registry - uses: docker/login-action@v3 + - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - - name: Build and push the images - run: | - make REGISTRY=docker.io IMAGE=${{ github.repository }} build-docker-multiarch - make REGISTRY=ghcr.io IMAGE=${{ github.repository }} build-docker-multiarch + - run: | + make REGISTRY=docker.io build-docker-multiarch + make REGISTRY=ghcr.io build-docker-multiarch diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 43b4019..2e9327f 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -18,3 +18,10 @@ jobs: - name: Test run: go test ./... + image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - run: | + make PLATFORM=linux/amd64 build-docker-multiarch diff --git a/Makefile b/Makefile index 9f77e3b..fc75d05 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,33 @@ SHELL := /bin/bash # Env var inputs for container image builds -# REGISTRY: The registry to which the build image should be pushed to. Defaults to "docker.io" (Docker Hub) -# IMAGE: The name of the image to build and publish in the afore mentioned registry. Defaults to "gotify/cli" -# PLATFORM: The platform for which the image should be built, defaults to amd64, arm64, i386, arm/v7 and riscv64 +# REGISTRY: The registry to which the build image should be pushed to. +# IMAGE: The name of the image to build and publish in the afore mentioned registry. +# PLATFORM: The platform for which the image should be built REGISTRY ?= docker.io IMAGE ?= gotify/cli PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 # Env var inputs for all builds -# VERSION: The version for which the container image or the binary is being built. This variable has not default. +# VERSION: The version for which the container image or the binary is being built. # When it is not provided, no version will be specified in the built package. # COMMIT: The commit of this project for which the cli is being built, for reference in the tool's "version" command. -# Default to git's HEAD -# LD_FLAGS: Build flags, for the tool's "version" command. Defaults to current date, commit and version (if any). +# LD_FLAGS: Build flags, for the tool's "version" command. COMMIT ?= $(shell git rev-parse --verify HEAD) LD_FLAGS ?= $(if $(VERSION),-X main.Version=${VERSION}) \ -X main.BuildDate=$(shell date "+%F-%T") \ -X main.Commit=${COMMIT} -# Resolve go version ifdef GOTOOLCHAIN GO_VERSION=$(GOTOOLCHAIN) else GO_VERSION=$(shell go mod edit -json | jq -r .Toolchain | sed -e 's/go//') endif -DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS" build-docker-multiarch: docker buildx build \ $(if $(DOCKER_BUILD_PUSH),--push) \ - -t ${REGISTRY}/${IMAGE}:${COMMIT} \ + -t ${REGISTRY}/${IMAGE}:master \ $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:latest) \ $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:${VERSION}) \ $(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2)) \ @@ -40,9 +37,8 @@ build-docker-multiarch: --platform $(PLATFORM) \ -f docker/Dockerfile . -_build_within_docker: OUTPUT = gotify-cli -_build_within_docker: - ${DOCKER_GO_BUILD} -o ${OUTPUT} +clean: + rm -rf build build: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go diff --git a/docker/Dockerfile b/docker/Dockerfile index e362cbf..ddd303b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,26 +1,21 @@ ARG BUILDKIT_SBOM_SCAN_CONTEXT=true -# Suppress warning about invalid variable expansion ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION -ARG DEBIAN=sid-slim ARG BUILDPLATFORM -ARG TARGETPLATFORM - -# Hack to normalize platform to match the chosed build image -# Get the gotify/build image tag -ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-} -ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7} -# --- Go Builder --- FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION}-alpine AS builder -ARG LD_FLAGS="" - -RUN apk add --no-cache ca-certificates git make bash +ARG TARGETPLATFORM +ARG TARGETOS +ARG TARGETARCH +ARG LD_FLAGS -COPY . /src/gotify +WORKDIR /src +COPY . /src -RUN cd /src/gotify && \ - LD_FLAGS=${LD_FLAGS} make OUTPUT=/target/app/gotify-cli _build_within_docker +RUN GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=$(echo $TARGETPLATFORM | sed -En 's|^linux/arm/v(.*)|\1|p') \ + go build -mod=readonly -a -installsuffix cgo -ldflags "${LD_FLAGS}" -o /target/app/gotify-cli FROM docker.io/library/alpine:latest