myip/Makefile

44 lines
1.2 KiB
Makefile

VERSION=$(shell git describe --tags)
BUILD=$(shell git rev-parse --short HEAD)
PROJ := $(shell basename "$(PWD)")
HUB=hub.kumoly.io
HUB_PROJECT=tools
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"
PLATFORMS=darwin linux windows
ARCHITECTURES=amd64
default: build
install:
go mod tidy
go mod download
clean:
rm -rf dist
build:
go build ${LDFLAGS} -o dist/myip
build-bins:
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_$(GOOS)_$(GOARCH))))
build-m1:
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64)
docker:
docker build --target builder -t $(HUB)/$(HUB_PROJECT)/$(PROJ):builder .
docker build \
-t $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) \
.
release: build-bins build-m1 docker
docker tag $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) $(HUB)/$(HUB_PROJECT)/$(PROJ):latest
docker push $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION)
docker push $(HUB)/$(HUB_PROJECT)/$(PROJ):latest
save:
docker save -o dist/$(PROJ)-$(VERSION)-${BUILD}.tar $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION)
.PHONY: build docker release clean all