-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
121 lines (94 loc) · 3.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
DOCKER_HUB_CLOUDOPS_TAG ?= latest
CLOUDOPS_IMG=$(DOCKER_HUB_REPO)/cloudops:$(DOCKER_HUB_CLOUDOPS_TAG)
ifndef PKGS
PKGS := ./...
endif
ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS += -gcflags "-N -l"
endif
RELEASE_VER := 0.0.1
BASE_DIR := $(shell git rev-parse --show-toplevel)
GIT_SHA := $(shell git rev-parse --short HEAD)
BIN :=$(BASE_DIR)/bin
LDFLAGS += "-s -w -X github.com/libopenstorage/cloudops/pkg/version.Version=$(VERSION)"
BUILD_OPTIONS := -ldflags=$(LDFLAGS)
HAS_GOMODULES := $(shell go help mod why 2> /dev/null)
ifdef HAS_GOMODULES
export GO111MODULE=on
export GOFLAGS = -mod=vendor
else
$(error cloudops can only be built with go 1.11+ which supports go modules)
endif
.DEFAULT_GOAL=all
.PHONY: test clean vendor vendor-update container deploy
all: build vet
vendor-update:
go mod download
vendor-tidy:
go mod tidy
vendor:
go mod vendor
$(GOPATH)/bin/golint:
GO111MODULE=off go get -u golang.org/x/lint/golint
lint: $(GOPATH)/bin/golint
for file in $$(find . -name '*.go' | grep -v vendor | \
grep -v '\.pb\.go' | \
grep -v '\.pb\.gw\.go' | \
grep -v 'vsphere' | \
grep -v 'externalversions' | \
grep -v 'versioned' | \
grep -v 'generated'); do \
golint $${file}; \
if [ -n "$$(golint $${file})" ]; then \
exit 1; \
fi; \
done
vet:
go vet $(PKGS)
$(GOPATH)/bin/staticcheck:
(mkdir -p tools && cd tools && GO111MODULE=off && go get -u honnef.co/go/tools/cmd/staticcheck)
staticcheck: $(GOPATH)/bin/staticcheck
$(GOPATH)/bin/staticcheck $(PKGS)
errcheck:
(mkdir -p tools && cd tools && GO111MODULE=off && go get -v github.com/kisielk/errcheck)
errcheck -verbose -blank $(PKGS)
errcheck -verbose -blank -tags unittest $(PKGS)
pretest: lint vet errcheck staticcheck
build:
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
install:
go install -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
cloudops:
@echo "Building the cloudops binary"
@cd cmd/cloudops && CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/cloudops
generate-mockfiles:
go generate $(PKGS)
container:
@echo "Building container: docker build --tag $(CLOUDOPS_IMG) -f Dockerfile ."
sudo docker build --tag $(CLOUDOPS_IMG) -f Dockerfile .
deploy: container
sudo docker push $(CLOUDOPS_IMG)
docker-build-osd-dev:
# This image is local only and will not be pushed
docker build -t openstorage/osd-dev -f Dockerfile.osd-dev .
docker-build: docker-build-osd-dev
docker run \
--privileged \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make
test:
echo "" > coverage.txt
for pkg in $(PKGS); do \
go test -v -tags unittest -coverprofile=profile.out -covermode=atomic $(BUILD_OPTIONS) $${pkg} || exit 1; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done
clean:
go clean -i $(PKGS)