Forum software. Server rendered, HTML!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.9KB

  1. VERSION := $(shell git rev-parse --short HEAD)
  2. BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
  3. BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
  4. BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
  5. BUILDUSER := $(shell whoami)
  6. BUILDHOST := $(shell hostname -s)
  7. BUILDARCH := $(shell uname -m)
  8. FN := formless
  9. IMAGENAME := sneak/$(FN)
  10. UNAME_S := $(shell uname -s)
  11. GOLDFLAGS += -X main.Version=$(VERSION)
  12. GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
  13. # osx can't statically link apparently?!
  14. ifeq ($(UNAME_S),Darwin)
  15. GOFLAGS := -ldflags "$(GOLDFLAGS)"
  16. endif
  17. ifneq ($(UNAME_S),Darwin)
  18. GOFLAGS = -ldflags "-linkmode external -extldflags -static $(GOLDFLAGS)"
  19. endif
  20. default: fmt
  21. fmt:
  22. go fmt ./...
  23. goimports -l -w .
  24. debug: build
  25. GOTRACEBACK=all FORMLESS_DEBUG=1 ./$(FN) 2>&1 | tee -a debug.log
  26. run: build
  27. ./$(FN)
  28. clean:
  29. -rm ./$(FN)
  30. build: ./$(FN)
  31. .lintsetup:
  32. go get -v -u golang.org/x/lint/golint
  33. go get -u github.com/GeertJohan/fgt
  34. touch .lintsetup
  35. lint: fmt .lintsetup
  36. fgt golint ./...
  37. go-get:
  38. cd cmd/$(FN) && go get -v
  39. ./$(FN): */*.go cmd/*/*.go go-get
  40. cd cmd/$(FN) && go build -o ../../$(FN) $(GOFLAGS) .
  41. test: lint build-docker-image
  42. is_uncommitted:
  43. git diff --exit-code >/dev/null 2>&1
  44. docker:
  45. docker build -t $(IMAGENAME) .
  46. build-docker-image-dist: is_uncommitted clean
  47. docker build -t $(IMAGENAME):$(VERSION) -t $(IMAGENAME):latest -t $(IMAGENAME):$(BUILDTIMETAG) .
  48. dist: lint docker
  49. -mkdir -p ./output
  50. docker run --rm --entrypoint cat $(IMAGENAME) /bin/$(FN) > output/$(FN)
  51. docker save $(IMAGENAME) | bzip2 > output/$(BUILDTIMEFILENAME).$(FN).tbz2
  52. hub: upload-docker-image
  53. upload-docker-image: docker
  54. docker push $(IMAGENAME):$(VERSION)
  55. docker push $(IMAGENAME):$(BUILDTIMETAG)
  56. docker push $(IMAGENAME):latest
  57. vet:
  58. go vet ./...
  59. bash -c 'test -z "$$(gofmt -l .)"'
  60. .PHONY: build fmt test is_uncommitted docker dist hub upload-docker-image clean run rundebug default build-docker-image-dist