merp/Makefile

71 lines
1.8 KiB
Makefile
Raw Permalink Normal View History

2019-10-25 16:25:17 +00:00
APPNAME := merp
VERSION := $(shell git rev-parse HEAD)
2019-10-03 19:30:04 +00:00
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)
2019-10-27 13:26:07 +00:00
GOFLAGS = -ldflags "-linkmode external -extldflags -static $(GOLDFLAGS)"
2019-10-27 12:38:03 +00:00
endif
2019-10-03 19:30:04 +00:00
default: run
run: build
2019-11-11 23:11:38 +00:00
DEBUG=1 PORT=1111 ./$(APPNAME)
2019-10-03 19:30:04 +00:00
2019-11-11 23:11:38 +00:00
build: ./$(APPNAME)
2019-10-03 19:30:04 +00:00
2019-11-11 23:11:38 +00:00
./$(APPNAME): *.go models/*.go cmd/*/*.go
cd ./cmd/$(APPNAME) && go build -o ./$(APPNAME) $(GOFLAGS) . && mv ./$(APPNAME) ../..
2019-10-03 19:30:04 +00:00
2019-10-03 19:35:33 +00:00
clean:
2019-11-11 23:11:38 +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-11-07 20:49:35 +00:00
lint:
2019-11-07 21:04:57 +00:00
which revive || go get -u github.com/mgechev/revive
revive -formatter friendly -config .revive.toml -exclude=./vendor/... ./... || exit 1
2019-11-07 20:49:35 +00:00
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:
docker build -t $(IMAGENAME) .
2019-10-25 16:25:17 +00:00
upload-docker-image: build-docker-image
docker tag $(IMAGENAME) $(IMAGENAME):$(BUILDTIMETAG)
2019-10-25 16:25:17 +00:00
docker push $(IMAGENAME):$(BUILDTIMETAG)
2019-10-27 13:31:06 +00:00
ci-upload-images:
docker tag $(IMAGENAME) $(IMAGENAME):$(CIRCLE_SHA1)
docker tag $(IMAGENAME) $(IMAGENAME):$(CIRCLE_BRANCH)
docker push $(IMAGENAME):$(CIRCLE_SHA1)
docker push $(IMAGENAME):$(CIRCLE_BRANCH)