merp/Makefile

69 lines
1.6 KiB
Makefile

APPNAME := merp
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)
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
IMAGENAME := sneak/$(APPNAME)
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
GOLDFLAGS += -X main.Builduser=$(BUILDUSER)@$(BUILDHOST)
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
GOLDFLAGS += -X main.Appname=$(APPNAME)
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 "-linkmode external -extldflags -static $(GOLDFLAGS)"
endif
default: run
run: build
DEBUG=1 PORT=1111 ./$(APPNAME)
build: ./$(APPNAME)
./$(APPNAME): *.go models/*.go
go build -o $@ $(GOFLAGS) .
clean:
rm $(APPNAME)
fmt:
go fmt *.go
test: build-docker-image
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
hub: upload-docker-image
build-docker-image:
docker build \
-t $(IMAGENAME):$(VERSION) \
-t $(IMAGENAME):latest \
-t $(IMAGENAME):$(BUILDTIMETAG) \
.
upload-docker-image: build-docker-image
docker push $(IMAGENAME):$(VERSION)
docker push $(IMAGENAME):$(BUILDTIMETAG)
docker push $(IMAGENAME):latest
ci-upload-images:
docker push $(IMAGENAME):$(VERSION)
docker push $(IMAGENAME):$(BUILDTIMETAG)