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')
|
2019-10-24 15:33:57 +00:00
|
|
|
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.Buildtime=$(BUILDTIME)
|
|
|
|
GOLDFLAGS += -X main.Builduser=$(BUILDUSER)@$(BUILDHOST)
|
|
|
|
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
|
|
|
|
|
|
|
default: rundebug
|
|
|
|
|
|
|
|
rundebug: build
|
2019-11-02 06:56:17 +00:00
|
|
|
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-10-24 15:23:29 +00:00
|
|
|
build: ./$(FN)
|
2019-10-24 10:38:16 +00:00
|
|
|
|
2019-10-24 15:23:29 +00:00
|
|
|
./$(FN): *.go
|
2019-10-24 10:38:16 +00:00
|
|
|
go build -o $@ $(GOFLAGS) .
|
|
|
|
|
|
|
|
fmt:
|
|
|
|
go fmt *.go
|
|
|
|
|
2019-10-24 15:23:29 +00:00
|
|
|
test: build-docker-image
|
|
|
|
|
|
|
|
build-docker-image:
|
2019-10-24 15:33:57 +00:00
|
|
|
docker build -t $(IMAGENAME):$(VERSION) -t $(IMAGENAME):latest -t $(IMAGENAME):$(BUILDTIMETAG) .
|
2019-10-24 15:23:29 +00:00
|
|
|
|
|
|
|
dist: build-docker-image
|
|
|
|
-mkdir -p ./output
|
|
|
|
docker run --rm --entrypoint cat $(IMAGENAME) /bin/$(FN) > output/$(FN)
|
|
|
|
docker save $(IMAGENAME) | bzip2 > output/$(BUILDTIMEFILENAME).$(FN).tbz2
|
2019-10-24 15:33:57 +00:00
|
|
|
|
|
|
|
hub: upload-docker-image
|
|
|
|
|
|
|
|
upload-docker-image: build-docker-image
|
|
|
|
docker push $(IMAGENAME):$(VERSION)
|
|
|
|
docker push $(IMAGENAME):$(BUILDTIMETAG)
|
|
|
|
docker push $(IMAGENAME):latest
|