feta/Makefile

80 lines
1.8 KiB
Makefile
Raw Permalink Normal View History

2019-10-24 10:38:16 +00:00
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
2019-10-24 15:23:29 +00:00
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
2019-10-24 10:38:16 +00:00
BUILDUSER := $(shell whoami)
BUILDHOST := $(shell hostname -s)
BUILDARCH := $(shell uname -m)
2019-11-03 10:56:50 +00:00
FN := feta
2019-10-24 15:23:29 +00:00
IMAGENAME := sneak/$(FN)
2019-11-02 06:56:17 +00:00
UNAME_S := $(shell uname -s)
2019-10-24 10:38:16 +00:00
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
2019-11-02 06:56:17 +00:00
# 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
2019-10-24 10:38:16 +00:00
2020-03-27 23:02:36 +00:00
default: build
2019-10-24 10:38:16 +00:00
2020-03-27 23:02:36 +00:00
debug: build
GOTRACEBACK=all FETA_DEBUG=1 ./$(FN)
2019-10-24 10:38:16 +00:00
run: build
2019-10-24 15:23:29 +00:00
./$(FN)
2019-10-24 10:38:16 +00:00
2019-11-03 11:09:49 +00:00
clean:
2019-11-05 03:15:25 +00:00
-rm ./$(FN)
2019-11-03 11:09:49 +00:00
2019-10-24 15:23:29 +00:00
build: ./$(FN)
2019-10-24 10:38:16 +00:00
.lintsetup:
go get -v -u golang.org/x/lint/golint
2019-11-05 23:32:09 +00:00
go get -u github.com/GeertJohan/fgt
touch .lintsetup
2019-12-14 15:50:23 +00:00
lint: fmt .lintsetup
2019-12-19 13:20:23 +00:00
fgt golint ./...
2019-11-05 23:32:09 +00:00
2019-11-05 03:15:25 +00:00
go-get:
2019-12-19 14:24:26 +00:00
cd cmd/$(FN) && go get -v
2019-11-05 03:15:25 +00:00
2019-12-19 14:24:26 +00:00
./$(FN): */*.go cmd/*/*.go go-get
2019-11-05 02:57:48 +00:00
cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) .
2019-10-24 10:38:16 +00:00
fmt:
gofmt -s -w .
2019-10-24 10:38:16 +00:00
test: lint build-docker-image
2019-10-24 15:23:29 +00:00
is_uncommitted:
git diff --exit-code >/dev/null 2>&1
2019-11-05 03:15:25 +00:00
build-docker-image: clean
docker build -t $(IMAGENAME) .
build-docker-image-dist: is_uncommitted clean
docker build -t $(IMAGENAME):$(VERSION) -t $(IMAGENAME):latest -t $(IMAGENAME):$(BUILDTIMETAG) .
2019-10-24 15:23:29 +00:00
2019-11-05 23:32:09 +00:00
dist: lint build-docker-image
2019-10-24 15:23:29 +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
upload-docker-image: build-docker-image
docker push $(IMAGENAME):$(VERSION)
docker push $(IMAGENAME):$(BUILDTIMETAG)
docker push $(IMAGENAME):latest
2019-11-05 02:57:48 +00:00
2019-11-05 03:15:25 +00:00
.PHONY: build fmt test is_uncommitted build-docker-image dist hub upload-docker-image clean run rundebug default build-docker-image-dist