formless/Makefile

85 lines
1.9 KiB
Makefile
Raw Permalink Normal View History

2020-09-20 22:42:39 +00:00
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
BUILDUSER := $(shell whoami)
BUILDHOST := $(shell hostname -s)
BUILDARCH := $(shell uname -m)
FN := formless
IMAGENAME := sneak/$(FN)
UNAME_S := $(shell uname -s)
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
# osx can't statically link apparently?!
ifeq ($(UNAME_S),Darwin)
GOFLAGS := -ldflags "$(GOLDFLAGS)"
endif
ifneq ($(UNAME_S),Darwin)
GOFLAGS = -ldflags "-linkmode external -extldflags -static $(GOLDFLAGS)"
endif
default: fmt
fmt:
go fmt ./...
goimports -l -w .
debug: build
GOTRACEBACK=all FORMLESS_DEBUG=1 ./$(FN) 2>&1 | tee -a debug.log
run: build
./$(FN)
clean:
-rm ./$(FN)
build: ./$(FN)
.lintsetup:
go get -v -u golang.org/x/lint/golint
go get -u github.com/GeertJohan/fgt
touch .lintsetup
lint: fmt .lintsetup
fgt golint ./...
go-get:
cd cmd/$(FN) && go get -v
./$(FN): */*.go cmd/*/*.go go-get
cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) .
test: lint build-docker-image
is_uncommitted:
git diff --exit-code >/dev/null 2>&1
2020-09-20 23:11:00 +00:00
docker:
2020-09-20 22:42:39 +00:00
docker build -t $(IMAGENAME) .
build-docker-image-dist: is_uncommitted clean
docker build -t $(IMAGENAME):$(VERSION) -t $(IMAGENAME):latest -t $(IMAGENAME):$(BUILDTIMETAG) .
2020-09-20 23:11:00 +00:00
dist: lint docker
2020-09-20 22:42:39 +00:00
-mkdir -p ./output
docker run --rm --entrypoint cat $(IMAGENAME) /bin/$(FN) > output/$(FN)
docker save $(IMAGENAME) | bzip2 > output/$(BUILDTIMEFILENAME).$(FN).tbz2
hub: upload-docker-image
2020-09-20 23:11:00 +00:00
upload-docker-image: docker
2020-09-20 22:42:39 +00:00
docker push $(IMAGENAME):$(VERSION)
docker push $(IMAGENAME):$(BUILDTIMETAG)
docker push $(IMAGENAME):latest
2020-09-21 20:00:28 +00:00
vet:
go vet ./...
bash -c 'test -z "$$(gofmt -l .)"'
2020-09-20 23:11:00 +00:00
.PHONY: build fmt test is_uncommitted docker dist hub upload-docker-image clean run rundebug default build-docker-image-dist