Skip to content

Commit 1ae578a

Browse files
committed
wip
1 parent 7a8e8ca commit 1ae578a

File tree

3 files changed

+32
-60
lines changed

3 files changed

+32
-60
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,16 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- name: Checkout code
12-
uses: actions/checkout@v4
13-
14-
- name: Setup Go environment
15-
uses: actions/setup-go@v5
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-go@v5
1613
with:
1714
go-version: 1.24.x
1815
stable: true
1916

20-
- name: Get dependencies
21-
run: go get -v -t -d ./...
22-
23-
- name: Build
24-
run: |
25-
TAG=$(git describe --tags --abbrev=0)
26-
GIT_TAG=$TAG make clean build
17+
- run: go get -v -t -d ./...
18+
- run: make VERSION=${GITHUB_REF/refs\/tags\/v/} clean build
2719

28-
- name: Create release
29-
uses: svenstaro/upload-release-action@v2
20+
- uses: svenstaro/upload-release-action@v2
3021
with:
3122
repo_token: ${{ secrets.GITHUB_TOKEN }}
3223
file: build/*
@@ -44,38 +35,26 @@ jobs:
4435
id-token: write
4536

4637
steps:
47-
- name: Checkout repository
48-
uses: actions/checkout@v4
38+
- uses: actions/checkout@v4
4939

50-
- name: Store version in environment variable if this is a release tag
51-
if: startsWith(github.ref, 'refs/tags/v')
40+
- if: startsWith(github.ref, 'refs/tags/v')
5241
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
53-
54-
- name: Enable images push
55-
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }}
42+
- if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }}
5643
run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV
5744

58-
- name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v3
60-
61-
- name: Set up QEMU
62-
uses: docker/setup-qemu-action@v3
63-
64-
- name: Authenticate to Docker Hub registry
65-
uses: docker/login-action@v3
45+
- uses: docker/setup-buildx-action@v3
46+
- uses: docker/setup-qemu-action@v3
47+
- uses: docker/login-action@v3
6648
with:
6749
registry: docker.io
6850
username: ${{ secrets.DOCKER_USER }}
6951
password: ${{ secrets.DOCKER_PASS }}
70-
71-
- name: Authenticate to Github Container registry
72-
uses: docker/login-action@v3
52+
- uses: docker/login-action@v3
7353
with:
7454
registry: ghcr.io
7555
username: ${{ github.actor }}
7656
password: ${{ github.token }}
7757

78-
- name: Build and push the images
79-
run: |
80-
make REGISTRY=docker.io IMAGE=${{ github.repository }} build-docker-multiarch
81-
make REGISTRY=ghcr.io IMAGE=${{ github.repository }} build-docker-multiarch
58+
- run: |
59+
make REGISTRY=docker.io build-docker-multiarch
60+
make REGISTRY=ghcr.io build-docker-multiarch

Makefile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
SHELL := /bin/bash
22

33
# Env var inputs for container image builds
4-
# REGISTRY: The registry to which the build image should be pushed to. Defaults to "docker.io" (Docker Hub)
5-
# IMAGE: The name of the image to build and publish in the afore mentioned registry. Defaults to "gotify/cli"
6-
# PLATFORM: The platform for which the image should be built, defaults to amd64, arm64, i386, arm/v7 and riscv64
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
77
REGISTRY ?= docker.io
88
IMAGE ?= gotify/cli
99
PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64
1010

1111
# Env var inputs for all builds
12-
# VERSION: The version for which the container image or the binary is being built. This variable has not default.
12+
# VERSION: The version for which the container image or the binary is being built.
1313
# When it is not provided, no version will be specified in the built package.
1414
# COMMIT: The commit of this project for which the cli is being built, for reference in the tool's "version" command.
15-
# Default to git's HEAD
16-
# LD_FLAGS: Build flags, for the tool's "version" command. Defaults to current date, commit and version (if any).
15+
# LD_FLAGS: Build flags, for the tool's "version" command.
1716
COMMIT ?= $(shell git rev-parse --verify HEAD)
1817
LD_FLAGS ?= $(if $(VERSION),-X main.Version=${VERSION}) \
1918
-X main.BuildDate=$(shell date "+%F-%T") \
2019
-X main.Commit=${COMMIT}
2120

22-
# Resolve go version
2321
ifdef GOTOOLCHAIN
2422
GO_VERSION=$(GOTOOLCHAIN)
2523
else
2624
GO_VERSION=$(shell go mod edit -json | jq -r .Toolchain | sed -e 's/go//')
2725
endif
28-
DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS"
2926

3027
build-docker-multiarch:
3128
docker buildx build \
@@ -40,9 +37,8 @@ build-docker-multiarch:
4037
--platform $(PLATFORM) \
4138
-f docker/Dockerfile .
4239

43-
_build_within_docker: OUTPUT = gotify-cli
44-
_build_within_docker:
45-
${DOCKER_GO_BUILD} -o ${OUTPUT}
40+
clean:
41+
rm -rf build
4642

4743
build:
4844
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go

docker/Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
ARG BUILDKIT_SBOM_SCAN_CONTEXT=true
2-
# Suppress warning about invalid variable expansion
32
ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION
4-
ARG DEBIAN=sid-slim
53
ARG BUILDPLATFORM
6-
ARG TARGETPLATFORM
7-
8-
# Hack to normalize platform to match the chosed build image
9-
# Get the gotify/build image tag
10-
ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-}
11-
ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7}
124

13-
# --- Go Builder ---
145
FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION}-alpine AS builder
156

16-
ARG LD_FLAGS=""
7+
ARG TARGETPLATFORM
8+
ARG TARGETOS
9+
ARG TARGETARCH
10+
ARG LD_FLAGS
1711

12+
WORKDIR /src
1813
RUN apk add --no-cache ca-certificates git make bash
1914

20-
COPY . /src/gotify
15+
COPY . /src
2116

22-
RUN cd /src/gotify && \
23-
LD_FLAGS=${LD_FLAGS} make OUTPUT=/target/app/gotify-cli _build_within_docker
17+
RUN GOOS=${TARGETOS} \
18+
GOARCH=${TARGETARCH} \
19+
GOARM=$(echo $TARGETPLATFORM | sed -En 's|^linux/arm/v(.*)|\1|p') \
20+
go build -mod=readonly -a -installsuffix cgo -ldflags "${LD_FLAGS}" -o /target/app/gotify-cli
2421

2522
FROM docker.io/library/alpine:latest
2623

0 commit comments

Comments
 (0)