-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
235 lines (194 loc) · 6.43 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
TAG = `git describe --tags`
SSH_PORT = 69
VPS_VERSION = latest
VPS_OS = ubuntu
RELEASE = test
CLI_VERSION_VAR = main.Version
PROJECTNAME=inertia
DAEMON_IMAGE=ubclaunchpad/inertiad
.PHONY: help
help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":\n"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
## all: install production dependencies and build the Inertia CLI to project directory
all: prod-deps cli
## deps: install all dependencies
.PHONY: deps
deps: prod-deps dev-deps docker-deps
## lint: run static analysis for entire project
.PHONY: lint
lint: SHELL:=/bin/bash
lint:
go vet ./...
go test -run xxxx ./...
diff -u <(echo -n) <(gofmt -d -s `find . -type f -name '*.go' -not -path "./vendor/*"`)
diff -u <(echo -n) <(go run golang.org/x/lint/golint `go list ./... | grep -v /vendor/`)
## clean: remove testenv, binaries, build directories, caches, and more
.PHONY: clean
clean: testenv-clean
go clean -testcache
rm -f ./inertia
rm -f ./inertiad
rm -f ./inertia-*
rm -rf ./docs_build
find . \
-type f \
-name inertia.\* \
-not -path "*.static*" \
-not -path "*docs*" \
-exec rm {} \;
## ____________
## * CLI / DAEMON
## ‾‾‾‾‾‾‾‾‾‾‾‾
## cli: build the inertia CLI binary into project directory
.PHONY: cli
cli:
go build -ldflags "-X $(CLI_VERSION_VAR)=$(RELEASE)"
## install: install inertia CLI to $GOPATH
.PHONY: install
install:
go install -ldflags "-X $(CLI_VERSION_VAR)=$(RELEASE)"
## daemon: build the daemon image and save it to ./images
.PHONY: daemon
daemon:
mkdir -p ./images
rm -f ./images/inertia-daemon-image
# TODO - replace ubclaunchpad/inertia with DAEMON_IMAGE
docker build --build-arg INERTIA_VERSION=$(TAG) \
-t ghcr.io/${DAEMON_IMAGE}:test .
docker save -o ./images/inertia-daemon-image ghcr.io/${DAEMON_IMAGE}:test
docker rmi ghcr.io/${DAEMON_IMAGE}:test
## gen: rewrite all generated code (mocks, scripts, etc.)
.PHONY: gen
gen: scripts mocks
## _______
## * TESTING
## ‾‾‾‾‾‾‾
## testenv: set up full test environment
.PHONY: testenv
testenv: docker-deps testenv-clean
# run nginx container for testing
docker run --name testcontainer -d nginx
# start vps container
docker build -f ./test/vps/$(VPS_OS).dockerfile \
-t $(VPS_OS)vps \
--build-arg VERSION=$(VPS_VERSION) \
./test
bash ./test/start_vps.sh $(SSH_PORT) $(VPS_OS)vps
## testdaemon: create test daemon and scp the image to the test VPS for use as version "test"
.PHONY: testdaemon
testdaemon: daemon testdaemon-scp
## test: run unit test suite
.PHONY: test
test:
go test ./... -short -ldflags "-X $(CLI_VERSION_VAR)=test" --cover
## test-all: build test daemon, set up testenv, and run unit and integration tests
.PHONY: test-all
test-all:
make testenv VPS_OS=$(VPS_OS) VPS_VERSION=$(VPS_VERSION)
make testdaemon
go test ./... -ldflags "-X $(CLI_VERSION_VAR)=test" --cover
## test-integration: build test daemon, set up testenv, and run integration tests only
.PHONY: test-integration
test-integration:
make testenv VPS_OS=$(VPS_OS) VPS_VERSION=$(VPS_VERSION)
make testdaemon
go test ./... -v -run 'Integration' -ldflags "-X $(CLI_VERSION_VAR)=test" --cover
## test-integration-fast: run integration tests only, but without setting up testenv
.PHONY: test-integration-fast
test-integration-fast:
make testdaemon
go test ./... -v -run 'Integration' -ldflags "-X $(CLI_VERSION_VAR)=test" --cover
## _____________
## * DOCUMENTATION
## ‾‾‾‾‾‾‾‾‾‾‾‾‾
DOCS_DIR=docs
## docs: build all documentation, used for latest release documentation
.PHONY: docs
docs: docs-usage docs-cli docs-api
## docs-tip: build tip documentation (docs/tip), used for the bleeding edge documentation
.PHONY: docs-tip
docs-tip:
make docs DOCS_DIR=docs/tip
## docs-usage: set up doc builder and build usage guide website
.PHONY: docs
docs-usage:
sh .scripts/build_docs.sh $(DOCS_DIR)
## docs-cli: build CLI reference pages
.PHONY: docs-cli
docs-cli: docgen
@echo [INFO] Generating CLI documentation
@./inertia-docgen -o $(DOCS_DIR)/cli
## docs-api: build API reference from Swagger definitions in /docs_src/api
.PHONY: docs-api
docs-api:
@echo [INFO] Generating API documentation
@redoc-cli bundle ./docs_src/api/swagger.yml -o $(DOCS_DIR)/api/index.html
## run-docs-usage: run doc server from ./docs_src for the usage guide website only
.PHONY: run-docs-usage
run-docs-usage:
( cd docs_build/slate ; bundle exec middleman server --verbose )
## run-docs-api: run doc server from ./docs_src for the API reference website only
.PHONY: run-docs-api
run-docs-api:
redoc-cli serve ./docs_src/api/swagger.yml -w
## _______
## * HELPERS
## ‾‾‾‾‾‾‾
## prod-deps: install only production dependencies
.PHONY: prod-deps
prod-deps:
go mod download
## dev-deps: install only development dependencies and tools
.PHONY: dev-deps
dev-deps:
npm install -g redoc-cli
## docker-deps: download required docker containers
.PHONY: docker-deps
docker-deps:
bash test/docker_deps.sh
## mocks: generate Go code and assets
.PHONY: generate
generate:
go generate ./...
## testdaemon-scp: copy test daemon image from ./images to test VPS
.PHONY: testdaemon-scp
testdaemon-scp:
chmod 400 ./test/keys/id_rsa
scp -i ./test/keys/id_rsa \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-P $(SSH_PORT) \
./images/inertia-daemon-image \
root@0.0.0.0:/daemon-image
## testenv-clean: stop and shut down the test environment
.PHONY: testenv-clean
testenv-clean:
docker stop testvps testcontainer || true && docker rm testvps testcontainer || true
## _______________
## * RELEASE SCRIPTS
## ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
## install-tagged: install Inertia with git tag as release version
.PHONY: install-tagged
install-tagged:
go install -ldflags "-X $(CLI_VERSION_VAR)=$(TAG)"
## daemon-release: build the daemon as ubclaunchpad/inertiad:RELEASE
.PHONY: daemon-release
daemon-release:
docker build --build-arg INERTIA_VERSION=$(RELEASE) \
-t $(DAEMON_IMAGE):$(RELEASE) .
## ____________
## * EXPERIMENTAL
## ‾‾‾‾‾‾‾‾‾‾‾‾
## contrib: install everything in 'contrib'
.PHONY: contrib
contrib:
go install -ldflags "-X $(CLI_VERSION_VAR)=$(TAG)" ./contrib/...
## docgen: build the docgen tool into project directory
.PHONY: docgen
docgen:
go build -ldflags "-X $(CLI_VERSION_VAR)=$(TAG)" ./contrib/inertia-docgen
## localdaemon: run a test daemon locally, without testenv
.PHONY: localdaemon
localdaemon:
bash ./test/start_local_daemon.sh