-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
76 lines (55 loc) · 1.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# note: call scripts from /scripts
BINDIR := $(CURDIR)/bin
BINNAME ?= public-binary-file-mirror
# go option
PKG := ./...
TESTS := .
TESTFLAGS :=
LDFLAGS := -w -s
GOFLAGS :=
# VERSION is the version of the binary.
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_TAG_SHA ?= $(shell git describe --tags --dirty 2>/dev/null)
# TAG is the tag of the container image, default to binary version.
TAG?=$(GIT_TAG_SHA)
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),)
TAG = ${GIT_TAG}
endif
# REGISTRY is the container registry to push into.
REGISTRY?=ghcr.io/daocloud
# IMAGE is the image name of the node problem detector container image.
IMAGE:=$(REGISTRY)/public-binary-files-mirror:$(TAG)
# Rebuild the binary if any of these files change
SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
.PHONY: all
all: build
# ------------------------------------------------------------------------------
# build
.PHONY: build
build: $(BINDIR)/$(BINNAME)
$(BINDIR)/$(BINNAME): $(SRC)
GO111MODULE=on CGO_ENABLED=0 go build $(GOFLAGS) -trimpath -tags '$(TAG)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) .
# ------------------------------------------------------------------------------
# test
.PHONY: test
test: test-unit
.PHONY: test-unit
test-unit:
@echo
@echo "==> Running unit tests <=="
GO111MODULE=on go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)
# ------------------------------------------------------------------------------
# clean
.PHONY: clean
clean:
rm -rf bin
# ------------------------------------------------------------------------------
# build-container
build-container:
@echo "Build Image: $(IMAGE)"
@docker build -t "$(IMAGE)" --file ./Dockerfile .
# ------------------------------------------------------------------------------
# release-container
release-container: build-container
@docker push $(IMAGE)