|
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 . |
2 | 39 |
|
3 | 40 | clean: |
4 | | - rm -rf ${BUILD_DIR} |
| 41 | + rm -rf build |
5 | 42 |
|
6 | 43 | 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)) |
9 | 44 | CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go |
10 | 45 | CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-386.exe cli.go |
11 | 46 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-linux-amd64 cli.go |
|
0 commit comments