-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
156 lines (119 loc) · 4.36 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
BUILD_DIR ?= build
COMMIT = $(shell git rev-parse HEAD)
VERSION ?= $(shell git describe --always --tags --dirty)
ORG := github.com/hyperscale
PROJECT := hypercloud
REPOPATH ?= $(ORG)/$(PROJECT)
VERSION_PACKAGE = $(REPOPATH)/pkg/hypercloud/version
GO_LDFLAGS :="
GO_LDFLAGS += -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitCommit=$(COMMIT)
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitTreeState=$(if $(shell git status --porcelain),dirty,clean)
GO_LDFLAGS +="
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: release
release:
@echo "Release v$(version)"
@git pull
@git checkout master
@git pull
@git checkout develop
@git flow release start $(version)
@echo "$(version)" > .version
@sed -e "s/version: .*/version: \"v$(version)\"/g" docs/swagger.yaml > docs/swagger.yaml.new && rm -rf docs/swagger.yaml && mv docs/swagger.yaml.new docs/swagger.yaml
@git add .version docs/swagger.yaml
@git commit -m "feat(project): update version file" .version docs/swagger.yaml
@git flow release finish $(version)
@git push
@git push --tags
@git checkout master
@git push
@git checkout develop
@echo "Release v$(version) finished."
.PHONY: all
all: deps build test
.PHONY: deps
deps:
@go mod download
.PHONY: clean
clean:
@go clean -i ./...
generate: $(GO_FILES)
@go generate ./...
create-build-dir:
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/coverage.out: create-build-dir $(GO_FILES) go.mod go.sum
@go test -race -cover -coverprofile $(BUILD_DIR)/coverage.out.tmp ./...
@cat $(BUILD_DIR)/coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > $(BUILD_DIR)/coverage.out
@rm $(BUILD_DIR)/coverage.out.tmp
.PHONY: ci-test
ci-test:
@go test -race -cover -coverprofile ./coverage.out.tmp -v ./... | go2xunit -fail -output tests.xml
@cat ./coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > ./coverage.out
@rm ./coverage.out.tmp
@echo ""
@go tool cover -func ./coverage.out
.PHONY: lint
lint:
@CGO_ENABLED=0 golangci-lint run ./...
.PHONY: test
test: $(BUILD_DIR)/coverage.out
.PHONY: coverage
coverage: $(BUILD_DIR)/coverage.out
@echo ""
@go tool cover -func ./$(BUILD_DIR)/coverage.out
.PHONY: coverage-html
coverage-html: $(BUILD_DIR)/coverage.out
@go tool cover -html ./$(BUILD_DIR)/coverage.out
# Build targets
${BUILD_DIR}/hypercloud-starter: $(GO_FILES)
@echo "Building $@..."
@go generate ./cmd/$(subst ${BUILD_DIR}/,,$@)/
@go build -ldflags $(GO_LDFLAGS) -o $@ ./cmd/$(subst ${BUILD_DIR}/,,$@)/
${BUILD_DIR}/hypercloud-installer: $(GO_FILES)
@echo "Building $@..."
@go generate ./cmd/$(subst ${BUILD_DIR}/,,$@)/
@go build -ldflags $(GO_LDFLAGS) -o $@ ./cmd/$(subst ${BUILD_DIR}/,,$@)/
${BUILD_DIR}/hypercloud-server: $(GO_FILES)
@echo "Building $@..."
@go generate ./cmd/$(subst ${BUILD_DIR}/,,$@)/
@go build -ldflags $(GO_LDFLAGS) -o $@ ./cmd/$(subst ${BUILD_DIR}/,,$@)/
.PHONY: build
build: ${BUILD_DIR}/hypercloud-starter ${BUILD_DIR}/hypercloud-installer ${BUILD_DIR}/hypercloud-server
# Docker targets
docker: docker-hypercloud-starter docker-hypercloud-installer docker-hypercloud-server docker-hypercloud-manager
.PHONY: docker-hypercloud-starter
docker-hypercloud-starter: _docker-hypercloud-starter
.PHONY: docker-hypercloud-installer
docker-hypercloud-installer: _docker-hypercloud-installer
.PHONY: docker-hypercloud-server
docker-hypercloud-server: _docker-hypercloud-server
.PHONY: docker-hypercloud-manager
docker-hypercloud-manager: _docker-hypercloud-manager
_docker-%:
@docker build -f cmd/$*/Dockerfile -t 127.0.0.1:5000/$*:latest .
@docker image push 127.0.0.1:5000/$*
# Run targets
run: docker
@sudo docker run -p 8578:8080 \
-e "USERNAME=dacteev" \
-e "PASSWORD=test" \
-v $(shell pwd)/var/lib/hypercloud:/var/lib/hypercloud \
-v /var/run/docker.sock:/var/run/docker.sock \
--rm $(IMAGE)
.PHONY: run-hypercloud-server
run-hypercloud-server: ${BUILD_DIR}/hypercloud-server
@echo "Running $<..."
./$< --config=./cmd/$(subst ${BUILD_DIR}/,,$<)/config.yml
.PHONY: run-hypercloud-starter
run-hypercloud-starter: ${BUILD_DIR}/hypercloud-starter
@echo "Running $<..."
@./$<
# Swarm targets
.PHONY: stack-deploy-dev
stack-deploy-dev:
@docker stack deploy -c dev/docker-compose.yml acme
.PHONY: stack-deploy-installer
stack-deploy-installer:
@docker stack deploy -c cmd/hypercloud-installer/docker-compose.yml hypercloud