2019-10-25 16:25:17 +00:00
|
|
|
APPNAME := merp
|
|
|
|
|
2019-10-03 19:30:04 +00:00
|
|
|
VERSION := $(shell git rev-parse --short HEAD)
|
|
|
|
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
BUILDUSER := $(shell whoami)
|
|
|
|
BUILDHOST := $(shell hostname -s)
|
|
|
|
BUILDARCH := $(shell uname -m)
|
2019-10-25 16:25:17 +00:00
|
|
|
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
|
|
|
|
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
|
|
|
|
IMAGENAME := sneak/$(APPNAME)
|
2019-10-03 19:30:04 +00:00
|
|
|
|
|
|
|
GOLDFLAGS += -X main.Version=$(VERSION)
|
|
|
|
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
|
|
|
|
GOLDFLAGS += -X main.Builduser=$(BUILDUSER)@$(BUILDHOST)
|
|
|
|
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
|
2019-10-25 16:17:14 +00:00
|
|
|
GOLDFLAGS += -X main.Appname=$(APPNAME)
|
2019-10-27 12:38:03 +00:00
|
|
|
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
|
|
|
|
# osx can't statically link apparently?!
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(UNAME_S),Darwin)
|
|
|
|
GOFLAGS := -ldflags "-static -linkmode external -extldflags $(GOLDFLAGS)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2019-10-03 19:30:04 +00:00
|
|
|
|
|
|
|
default: run
|
|
|
|
|
|
|
|
run: build
|
2019-10-27 12:38:03 +00:00
|
|
|
DEBUG=1 PORT=1111 ./$(APPNAME)
|
2019-10-03 19:30:04 +00:00
|
|
|
|
2019-10-25 16:17:14 +00:00
|
|
|
build: ./$(APPNAME)
|
2019-10-03 19:30:04 +00:00
|
|
|
|
2019-10-27 12:38:03 +00:00
|
|
|
./$(APPNAME): *.go models/*.go
|
2019-10-03 19:30:04 +00:00
|
|
|
go build -o $@ $(GOFLAGS) .
|
|
|
|
|
2019-10-03 19:35:33 +00:00
|
|
|
clean:
|
2019-10-25 16:17:14 +00:00
|
|
|
rm $(APPNAME)
|
2019-10-03 19:35:33 +00:00
|
|
|
|
2019-10-03 19:30:04 +00:00
|
|
|
fmt:
|
|
|
|
go fmt *.go
|
|
|
|
|
2019-10-25 16:25:17 +00:00
|
|
|
test: build-docker-image
|
2019-10-25 16:17:14 +00:00
|
|
|
|
2019-10-25 16:25:17 +00:00
|
|
|
dist: build-docker-image
|
|
|
|
-mkdir -p ./output
|
|
|
|
docker run --rm --entrypoint cat $(IMAGENAME) /bin/$(APPNAME) > output/$(APPNAME)
|
|
|
|
docker save $(IMAGENAME) | bzip2 > output/$(BUILDTIMEFILENAME).$(APPNAME).tbz2
|
2019-10-25 16:17:14 +00:00
|
|
|
|
2019-10-25 16:25:17 +00:00
|
|
|
hub: upload-docker-image
|
2019-10-25 16:17:14 +00:00
|
|
|
|
2019-10-25 16:25:17 +00:00
|
|
|
build-docker-image:
|
2019-10-25 16:17:14 +00:00
|
|
|
docker build \
|
2019-10-25 16:25:17 +00:00
|
|
|
-t $(IMAGENAME):$(VERSION) \
|
|
|
|
-t $(IMAGENAME):latest \
|
|
|
|
-t $(IMAGENAME):$(BUILDTIMETAG) \
|
2019-10-25 16:17:14 +00:00
|
|
|
.
|
2019-10-25 16:25:17 +00:00
|
|
|
|
|
|
|
upload-docker-image: build-docker-image
|
|
|
|
docker push $(IMAGENAME):$(VERSION)
|
|
|
|
docker push $(IMAGENAME):$(BUILDTIMETAG)
|
|
|
|
docker push $(IMAGENAME):latest
|