-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
60 lines (47 loc) · 1.55 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
PKGS := $(shell go list ./... | grep -v /vendor)
BINARY := virity
OS ?= linux
ARCH ?= amd64
VERSION ?= latest
.PHONY: dep
dep: ## Get the dependencies
go get -v -d ./...
.PHONY: test
test: dep
go test $(PKGS)
BIN_DIR := $(GOPATH)/bin
GOMETALINTER := $(BIN_DIR)/golangci-lint
$(GOMETALINTER):
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/[email protected]
.PHONY: lint
lint: $(GOMETALINTER)
golangci-lint run ./... --fast --disable-all --enable govet
.PHONY: docker-agent
docker-agent:
ifeq ($(REGISTRY),)
docker build --build-arg VERSION=$(VERSION) -t $(BINARY)-agent:$(VERSION) -f Dockerfile.agent .
else
docker build --build-arg VERSION=$(VERSION) -t $(REGISTRY)/$(BINARY)-agent:$(VERSION) -f Dockerfile.agent .
docker push $(REGISTRY)/$(BINARY)-agent:$(VERSION)
endif
.PHONY: docker-server
docker-server:
ifeq ($(REGISTRY),)
docker build --build-arg VERSION=$(VERSION) -t $(BINARY)-server:$(VERSION) -f Dockerfile.server .
else
docker build --build-arg VERSION=$(VERSION) -t $(REGISTRY)/$(BINARY)-server:$(VERSION) -f Dockerfile.server .
docker push $(REGISTRY)/$(BINARY)-server:$(VERSION)
endif
.PHONY: docker
docker: docker-agent docker-server
CMDs := agent server
CMD = $(word 1, $@)
.PHONY: $(CMDs)
$(CMDs): dep
mkdir -p build
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -v -ldflags "-X main.version=$(VERSION)" -a -installsuffix cgo -o build/$(BINARY)-$(CMD)-$(OS)-$(ARCH)-v$(VERSION) github.com/sharenowTech/$(BINARY)/cmd/$(CMD)
.PHONY: bin
bin: $(CMDs)
.PHONY: all
all: $(CMDs) docker-agent docker-server
.DEFAULT_GOAL := bin