gitee.com/h79/goutils@v1.22.10/Makefile (about) 1 default: all 2 3 # Do a parallel build with multiple jobs, based on the number of CPUs online 4 # in this system: 'make -j8' on a 8-CPU system, etc. 5 ifeq ($(JOBS),) 6 JOBS := $(shell grep -c ^processor /proc/cpuinfo 2>/dev/null) 7 ifeq ($(JOBS),) 8 JOBS := $(shell sysctl -n hw.logicalcpu 2>/dev/null) 9 ifeq ($(JOBS),) 10 JOBS := 1 11 endif 12 endif 13 endif 14 15 use_all_cores: 16 make -j$(JOBS) all 17 18 # git information 19 GIT_COMMIT ?= $(shell git rev-parse --short HEAD) 20 GIT_DIRTY ?= $(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) 21 GIT_DESCRIBE ?= $(shell git describe --tags --always) 22 23 COMMIT := $(GIT_COMMIT)$(GIT_DIRTY) 24 VERSION := $(GIT_DESCRIBE) 25 SHIP_VERSION := $(shell docker image inspect -f "{{ .Config.Labels.version }}" $(IMAGE):latest 2>/dev/null) 26 27 MODULE := github.com/dayun 28 BUILDER := dayun/dayun-go-builder 29 IMAGE := dayun/dayun-go 30 IMAGE_TAR := $(subst /,_,$(IMAGE)).$(SHIP_VERSION).tar 31 IMAGE_TAR_GZ := $(IMAGE_TAR).gz 32 33 branch := $(shell git rev-parse --abbrev-ref HEAD) 34 buildDate := $(shell date +%Y%m%d%H%M%S) 35 36 Uname := $(shell uname) 37 38 ifeq ($(Uname),Linux) 39 platform := linux 40 else 41 ifeq ($(Uname),Darwin) 42 platform := darwin 43 endif 44 endif 45 46 ifdef APPVERSION 47 version := $(APPVERSION)-$(buildDate) 48 else 49 version := $(branch)-$(GIT_COMMIT)-$(buildDate) 50 endif 51 52 tags := $(platform) release 53 54 55 GO_BUILD := CGO_ENABLED=1 go build -tags "$(tags)" 56 57 status: 58 @echo "Commit: $(COMMIT) Version: $(VERSION) Ship Version: $(SHIP_VERSION)" 59 60 builder: status 61 docker build \ 62 --tag $(BUILDER):$(VERSION) \ 63 --tag $(BUILDER):latest \ 64 --build-arg BUILD_ARG=release \ 65 -f docker/builder.Dockerfile \ 66 . 67 68 # 生成镜像文件 69 docker: builder 70 docker build \ 71 --tag $(IMAGE):$(VERSION) \ 72 --tag $(IMAGE):latest \ 73 --build-arg COMMIT=$(COMMIT) \ 74 --build-arg VERSION=$(VERSION) \ 75 -f docker/Dockerfile \ 76 . 77 78 docker_clean: status 79 docker rmi -f $(BUILDER):latest 80 docker rmi -f $(IMAGE):latest 81 docker rmi -f $(BUILDER):$(VERSION) 82 docker rmi -f $(IMAGE):$(VERSION) 83 84 save: status 85 ifeq ($(SHIP_VERSION),) 86 $(error No version to ship, please build first) 87 endif 88 docker save $(IMAGE):$(SHIP_VERSION) > $(IMAGE_TAR) 89 tar zcf $(IMAGE_TAR_GZ) $(IMAGE_TAR) 90 91 start: 92 docker-compose down 93 docker-compose up --no-start 94 docker-compose start 95 96 stop: 97 docker-compose down 98 99 logs: 100 docker-compose logs -f --tail=10 101 102 push_testnet: 103 docker tag $(IMAGE):$(VERSION) $(IMAGE):testnet 104 docker push $(IMAGE):testnet 105 106 push_bench: 107 docker tag $(IMAGE):$(VERSION) $(IMAGE):bench 108 docker push $(IMAGE):bench 109 110 push_staging: 111 docker tag $(IMAGE):$(VERSION) $(IMAGE):staging 112 docker push $(IMAGE):staging 113 114 push: 115 docker push $(IMAGE):$(VERSION) 116 docker push $(IMAGE):latest 117 118 bin/utils: 119 $(GO_BUILD) 120 121 all: bin/utils 122 123 release: 124 ifeq ($(Uname),Linux) 125 make alpine_release; 126 else 127 make -j$(JOBS) build_release; 128 tar czvf dayun-bin.tgz bin/*; 129 endif 130 131 build_release: all 132 133 alpine_release: build_release 134 temp_container = $$(docker create $(BUILDER):$(VERSION)) ; \ 135 docker cp $${temp_container}:/go/src/github.com/dayun/bin - | gzip > dayun-bin.tgz 136 137 clean: 138 rm -rf bin/dy-* 139 rm -f *.cover.out 140 rm -f coverage.txt 141 142 .PHONY: vendor 143 144 vendor: 145 go mod tidy 146 go mod vendor