orangesite/Makefile

83 lines
1.9 KiB
Makefile
Raw Permalink Normal View History

# for development, db in cwd
export DATABASE_PATH := ./storage.sqlite
2020-03-24 20:32:35 +00:00
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
BUILDUSER := $(shell whoami)
BUILDHOST := $(shell hostname -s)
BUILDARCH := $(shell uname -m)
FN := server
2020-03-25 16:11:31 +00:00
IMAGENAME := sneak/orangesite
2020-03-24 20:32:35 +00:00
UNAME_S := $(shell uname -s)
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
# 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
debug: build
GOTRACEBACK=all DEBUG=1 ./$(FN)
run: build
./$(FN)
clean:
-rm ./$(FN)
build: ./$(FN)
.lintsetup:
go get -v -u golang.org/x/lint/golint
go get -u github.com/GeertJohan/fgt
touch .lintsetup
lint: fmt .lintsetup
fgt golint ./...
go-get:
cd cmd/$(FN) && go get -v
2020-03-25 00:49:19 +00:00
./$(FN): */*.go cmd/*/*.go go-get
2020-03-24 20:32:35 +00:00
cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) .
fmt:
gofmt -s -w .
test: lint build-docker-image
is_uncommitted:
git diff --exit-code >/dev/null 2>&1
build-docker-image: clean
docker build -t $(IMAGENAME) .
build-docker-image-dist: is_uncommitted clean
docker build -t $(IMAGENAME):$(VERSION) -t $(IMAGENAME):latest -t $(IMAGENAME):$(BUILDTIMETAG) .
dist: lint build-docker-image
-mkdir -p ./output
docker run --rm --entrypoint cat $(IMAGENAME) /bin/$(FN) > output/$(FN)
docker save $(IMAGENAME) | bzip2 > output/$(BUILDTIMEFILENAME).$(FN).tbz2
hub: upload-docker-image
upload-docker-image: build-docker-image
docker push $(IMAGENAME):$(VERSION)
docker push $(IMAGENAME):$(BUILDTIMETAG)
docker push $(IMAGENAME):latest
.PHONY: build fmt test is_uncommitted build-docker-image dist hub upload-docker-image clean run rundebug default build-docker-image-dist