Skip to content

Commit

Permalink
Build system: more robust container-image builds
Browse files Browse the repository at this point in the history
A container image usually consists of a image name and a tag.
The tag consists usually consists only of the version number. Sometimes,
information like a "pre-release" or a "build-number" are added to the
tag. Example given:

  mtr-exporter-0.3.0-rc1

The build system tries to build a binary named

  mtr-exporter-0.3.0-rc1.linux.amd64

and fails because the rule to build such a binary does not exist.

This commit fixes the issue by relaxing the wildcard pattern.
  • Loading branch information
mgumz committed Oct 31, 2024
1 parent 3372848 commit 6bfbc52
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT=mtr-exporter
VERSION=$(shell cat VERSION)
VERSION?=$(shell cat VERSION)
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_HASH=$(shell git rev-parse HEAD)
CONTAINER_PLATFORM?=linux/amd64
Expand All @@ -16,7 +16,7 @@ TARGETS=linux.amd64 \
BINARIES=$(addprefix bin/$(PROJECT)-$(VERSION)., $(TARGETS))
RELEASES=$(subst windows.amd64.tar.gz,windows.amd64.zip,$(foreach r,$(subst .exe,,$(TARGETS)),releases/$(PROJECT)-$(VERSION).$(r).tar.gz))

LDFLAGS=$(LDFLAGS) -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE) -X main.GitHash=$(GIT_HASH)"
LDFLAGS:=$(LDFLAGS) -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE) -X main.GitHash=$(GIT_HASH)"

$(PROJECT):
go build -v -o $@ ./cmd/$(PROJECT)
Expand All @@ -36,9 +36,9 @@ $(PROJECT): bin/$(PROJECT)
bin/$(PROJECT): cmd/$(PROJECT) bin
go build -v -o $@ ./$<

bin/$(PROJECT)-$(VERSION).%:
bin/$(PROJECT)-$(VERSION)%:
env GOARCH=$(subst .,,$(suffix $(subst .exe,,$@))) \
GOOS=$(subst .,,$(suffix $(basename $(subst .exe,,$@)))) \
GOOS=$(subst .,,$(suffix $(basename $(subst .exe,,$@)))) \
CGO_ENABLED=0 \
go build $(LDFLAGS) -o $@ ./cmd/$(PROJECT)

Expand Down

0 comments on commit 6bfbc52

Please sign in to comment.