Skip to content

Commit cfd2536

Browse files
edvguijmattheis
andauthored
Issue/publish container image (#79)
Co-authored-by: Jannis Mattheis <[email protected]>
1 parent 3f1f590 commit cfd2536

File tree

7 files changed

+136
-74
lines changed

7 files changed

+136
-74
lines changed

.github/workflows/build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Release
2+
3+
on: push
4+
5+
jobs:
6+
binary:
7+
if: startsWith(github.ref, 'refs/tags/v')
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-go@v5
13+
with:
14+
go-version: 1.24.x
15+
stable: true
16+
17+
- run: go get -v -t -d ./...
18+
- run: make VERSION=${GITHUB_REF/refs\/tags\/v/} clean build
19+
20+
- uses: svenstaro/upload-release-action@v2
21+
with:
22+
repo_token: ${{ secrets.GITHUB_TOKEN }}
23+
file: build/*
24+
tag: ${{ github.ref }}
25+
overwrite: true
26+
file_glob: true
27+
28+
image:
29+
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }}
30+
runs-on: ubuntu-latest
31+
32+
permissions:
33+
contents: read
34+
packages: write
35+
attestations: write
36+
id-token: write
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- if: startsWith(github.ref, 'refs/tags/v')
42+
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
43+
- run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV
44+
45+
- uses: docker/setup-buildx-action@v3
46+
- uses: docker/setup-qemu-action@v3
47+
- uses: docker/login-action@v3
48+
with:
49+
registry: docker.io
50+
username: ${{ secrets.DOCKER_USER }}
51+
password: ${{ secrets.DOCKER_PASS }}
52+
- uses: docker/login-action@v3
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ github.token }}
57+
58+
- run: |
59+
make REGISTRY=docker.io build-docker-multiarch
60+
make REGISTRY=ghcr.io build-docker-multiarch

.github/workflows/check.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ on: [push, pull_request]
33
jobs:
44
check:
55
runs-on: ubuntu-latest
6-
strategy:
7-
matrix:
8-
go: [1.20.x, 1.21.x, 1.22.x]
96
steps:
107
- name: Setup Go environment
118
uses: actions/setup-go@v5
129
with:
13-
go-version: ${{ matrix.go }}
10+
go-version: 1.24.x
1411
stable: true
1512

1613
- name: Check out code into the Go module directory
@@ -21,3 +18,10 @@ jobs:
2118

2219
- name: Test
2320
run: go test ./...
21+
image:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: docker/setup-buildx-action@v3
26+
- run: |
27+
make PLATFORM=linux/amd64 build-docker-multiarch

.github/workflows/release.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 28 deletions
This file was deleted.

Makefile

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
BUILD_DIR=./build
1+
SHELL := /bin/bash
2+
3+
# Env var inputs for container image builds
4+
# REGISTRY: The registry to which the build image should be pushed to.
5+
# IMAGE: The name of the image to build and publish in the afore mentioned registry.
6+
# PLATFORM: The platform for which the image should be built
7+
REGISTRY ?= docker.io
8+
IMAGE ?= gotify/cli
9+
PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64
10+
11+
# Env var inputs for all builds
12+
# VERSION: The version for which the container image or the binary is being built.
13+
# When it is not provided, no version will be specified in the built package.
14+
# COMMIT: The commit of this project for which the cli is being built, for reference in the tool's "version" command.
15+
# LD_FLAGS: Build flags, for the tool's "version" command.
16+
COMMIT ?= $(shell git rev-parse --verify HEAD)
17+
LD_FLAGS ?= $(if $(VERSION),-X main.Version=${VERSION}) \
18+
-X main.BuildDate=$(shell date "+%F-%T") \
19+
-X main.Commit=${COMMIT}
20+
21+
ifdef GOTOOLCHAIN
22+
GO_VERSION=$(GOTOOLCHAIN)
23+
else
24+
GO_VERSION=$(shell go mod edit -json | jq -r .Toolchain | sed -e 's/go//')
25+
endif
26+
27+
build-docker-multiarch:
28+
docker buildx build \
29+
$(if $(DOCKER_BUILD_PUSH),--push) \
30+
-t ${REGISTRY}/${IMAGE}:master \
31+
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:latest) \
32+
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:${VERSION}) \
33+
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2)) \
34+
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1)) \
35+
--build-arg GO_VERSION=$(GO_VERSION) \
36+
--build-arg LD_FLAGS="$(LD_FLAGS)" \
37+
--platform $(PLATFORM) \
38+
-f docker/Dockerfile .
239

340
clean:
4-
rm -rf ${BUILD_DIR}
41+
rm -rf build
542

643
build:
7-
if [ '$(shell echo "${GIT_TAG}" | cut -c 1 )' != 'v' ]; then exit 1; fi;
8-
$(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))
944
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go
1045
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-386.exe cli.go
1146
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-linux-amd64 cli.go

docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG BUILDKIT_SBOM_SCAN_CONTEXT=true
2+
ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION
3+
ARG BUILDPLATFORM
4+
5+
FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION}-alpine AS builder
6+
7+
ARG TARGETPLATFORM
8+
ARG TARGETOS
9+
ARG TARGETARCH
10+
ARG LD_FLAGS
11+
12+
WORKDIR /src
13+
COPY . /src
14+
15+
RUN GOOS=${TARGETOS} \
16+
GOARCH=${TARGETARCH} \
17+
GOARM=$(echo $TARGETPLATFORM | sed -En 's|^linux/arm/v(.*)|\1|p') \
18+
go build -mod=readonly -a -installsuffix cgo -ldflags "${LD_FLAGS}" -o /target/app/gotify-cli
19+
20+
FROM docker.io/library/alpine:latest
21+
22+
RUN apk add --no-cache ca-certificates
23+
24+
COPY --from=builder /target/app/gotify-cli /gotify-cli
25+
26+
ENTRYPOINT ["/gotify-cli"]

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/gotify/cli/v2
22

3-
go 1.18
3+
go 1.23
4+
5+
toolchain go1.24.1
46

57
require (
68
github.com/adrg/xdg v0.4.0

0 commit comments

Comments
 (0)