merp/Makefile

55 lines
1.3 KiB
Makefile
Raw Normal View History

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-25 16:25:17 +00:00
GOFLAGS = -ldflags "-linkmode external -extldflags -static $(GOLDFLAGS)"
2019-10-03 19:30:04 +00:00
default: run
run: build
2019-10-25 16:17:14 +00:00
DEBUG=1 ./$(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-25 16:17:14 +00:00
./$(APPNAME): *.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