-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
264 lines (220 loc) · 8.64 KB
/
Makefile
File metadata and controls
264 lines (220 loc) · 8.64 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
export GO111MODULE=on
os = $(shell uname | tr '[A-Z]' '[a-z]')
pwd = $(shell pwd)
current_date = $(shell date +"%Y-%m-%d")
sdk = $(shell dirname $(shell readlink $(shell which gcloud)))
cloud_sdk = $(gcloud --format='value(installation.sdk_root)' info)
gopath = $(shell go env GOPATH)
goroot = $(shell go env GOROOT)
go = go
gpm = gpm
gover = $(gopath)/bin/gover
goveralls = $(gopath)/bin/goveralls
ginkgo = $(gopath)/bin/ginkgo
gae_development = $(pwd)/config/development $(pwd)/api/app.development.yaml
gae_production = config/production api/app.production.yaml analytics/app.production.yaml
gae_sandbox = config/sandbox api/app.sandbox.yaml analytics/app.sandbox.yaml
gae_staging = config/staging api/app.staging.yaml analytics/app.staging.yaml
tools = github.com/nsf/gocode \
github.com/fatih/motion \
github.com/josharian/impl \
github.com/jstemmer/gotags \
github.com/kisielk/errcheck \
github.com/klauspost/asmfmt/cmd/asmfmt \
github.com/rogpeppe/godef \
github.com/zmb3/gogetdoc \
github.com/onsi/ginkgo/v2/ginkgo \
golang.org/x/tools/cmd/goimports \
golang.org/x/tools/cmd/gorename \
golang.org/x/tools/cmd/guru
# Various patches for SDK
mtime_file_watcher = https://gist.githubusercontent.com/zeekay/5eba991c39426ca42cbb/raw/8db2e910b89e3927adc9b7c183387186facee17b/mtime_file_watcher.py
dev_appserver = python3 /lib/google-cloud-sdk/bin/dev_appserver.py \
--skip_sdk_update_check \
--datastore_path=$(pwd)/.datastore.bin \
--enable_task_running=true \
--dev_appserver_log_level=info \
--log_level=info \
--admin_port=8000 \
--port=8080
# find command differs between bsd/linux thus the two versions
ifeq ($(os), linux)
packages = $(shell find . -maxdepth 4 -mindepth 2 -name '*.go' \
-not -path "./sdk/*" \
-not -path "./test*" \
-not -path "./assets/*" \
-not -path "./replace/*" \
-not -path "./static/*" \
-not -path "./node_modules/*" \
-printf '%h\n' | sort -u | sed -e 's/.\//hanzo.ai\//')
sed = @sed -i -e
else
packages = $(shell find . -maxdepth 4 -mindepth 2 -name '*.go' \
-not -path "./sdk/*" \
-not -path "./test*" \
-not -path "./assets/*" \
-not -path "./replace/*" \
-not -path "./static/*" \
-not -path "./node_modules/*" \
-print0 | xargs -0 -n1 dirname | sort --unique | sed -e 's/.\//hanzo.ai\//')
sdk_install_extra := $(sdk_install_extra) && \
curl $(mtime_file_watcher) > $(pwd)/google/appengine/tools/devappserver2/mtime_file_watcher.py && \
pip2 install macfsevents --upgrade
sed = @sed -i .bak -e
endif
# set v=1 to enable verbose mode
ifeq ($(v), 1)
test_verbose = --v --progress -- -test.v=true
else
test_verbose =
endif
project_env = development
project_id = None
# set production=1 to set datastore export/import target to use production
ifeq ($(production), 1)
project_env = production
project_id = hanzo-production
gae_config = $(gae_production)
else ifeq ($(sandbox), 1)
project_env = sandbox
project_id = hanzo-sandbox
gae_config = $(gae_sandbox)
else
project_env = staging
project_id = hanzo-staging
gae_config = $(gae_staging)
endif
# force a single module to deploy
ifneq ($(strip $(module)),)
gae_config = $(module)
endif
datastore_admin_url = https://datastore-admin-dot-$(project_id).appspot.com/_ah/remote_api
test_target = -r=true test/*
test_focus := $(focus)
ifdef test_focus
test_target=$(focus)
endif
test_batch := $(batch)
ifdef test_batch
test_target=$(batch)
endif
all: deps test install
build: deps update-env
$(go) build $(packages)
clean:
$(go) clean -modcache
deps:
$(go) list ./...
$(go) get ./...
# INSTALL
install:
$(go) install $(packages)
# DEV SERVER
serve: update-env
$(dev_appserver) $(gae_development)
serve-clear-datastore: update-env
$(dev_appserver) --clear_datastore=true $(gae_development)
serve-public: update-env
$(dev_appserver) --host=0.0.0.0 $(gae_development)
serve-no-reload: assets update-env
$(dev_appserver) $(gae_development)
# GOLANG TOOLS
tools:
$(go) get $(tools)
$(go) install $(tools)
$(gopath)/bin/gocode set propose-builtins true
$(gopath)/bin/gocode set lib-path "$(gopath)/pkg:$(goroot)/pkg"
# TEST/ BENCH
test: update-env-test
$(ginkgo) $(test_target) --compilers=2 --randomize-all --fail-fast --trace --skip-package=test-integration/* $(test_verbose)
test-watch: update-env-test
$(ginkgo) watch -r=true --compilers=2 --fail-fast --trace $(test_verbose)
bench: update-env-test
$(ginkgo) test --randomize-all --fail-fast --trace --skip-package=integration $(test_verbose)
test-ci: update-env-test
cd $(pwd); $(ginkgo) $(test_target) --randomize-all --randomize-suites --fail-fast --fail-on-pending --trace $(test_verbose)
coverage:
# $(gover) test/ coverage.out
# $(goveralls) -coverprofile=coverage.out -service=circle-ci -repotoken=$(COVERALLS_REPO_TOKEN)
# DEPLOY
auth:
@echo If you have issues authenticating try:
@echo " gcloud components reinstall"
gcloud auth login
deploy: build
@cd $(gopath)/src/hanzo.ai
gcloud app deploy $(gae_config) --project $(project_id) --version v1
gcloud app deploy config/$(project_env)/dispatch.yaml --project $(project_id) --version v1
deploy-dispatch:
@cd $(gopath)/src/hanzo.ai
gcloud app deploy config/$(project_env)/dispatch.yaml --project $(project_id) --version v1
update-env:
@printf 'package config\n\nvar Env = "$(project_env)"' > config/env.go
update-env-test:
@printf 'package config\n\nvar Env = "test"' > config/env.go
rollback:
for module in $(gae_config); do \
$(appcfg.py) rollback $$module; \
done
# EXPORT / Usage: make datastore-export kind=user namespace=bellabeat
datastore-export:
@mkdir -p _export/
$(appcfg.py) download_data \
--bandwidth_limit 1000000000 \
--rps_limit 10000 \
--batch_size 250 \
--http_limit 200 \
--url $(datastore_admin_url) \
--config_file util/bulkloader/bulkloader.yaml \
--db_filename /tmp/bulkloader-$$kind.db \
--log_file /tmp/bulkloader-$$kind.log \
--result_db_filename /tmp/bulkloader-result-$$kind.db \
--namespace $$namespace \
--kind $$kind \
--filename _export/$$namespace-$$kind-$(project_id)-$(current_date).csv
rm -rf /tmp/bulkloader-$$kind.db \
/tmp/bulkloader-$$kind.log \
/tmp/bulkloader-result-$$kind.db
# IMPORT / Usage: make datastore-import kind=user file=user.csv
datastore-import:
@$(appcfg.py) upload_data --bandwidth_limit 1000000000 \
--rps_limit 10000 \
--batch_size 250 \
--http_limit 200 \
--url $(datastore_admin_url) \
--config_file util/bulkloader/bulkloader.yaml \
--namespace $$namespace \
--kind $$kind \
--filename $$file \
--log_file /tmp/bulkloader-upload-$$kind.log
rm -rf /tmp/bulkloader-upload-$$kind.log
# Generate config for use with datastore-export target
datastore-config:
$(appcfg.py) create_bulkloader_config \
--url=$(datastore_admin_url) \
--filename=bulkloader.yaml
# Replicate production data to localhost
datastore-replicate:
$(appcfg.py) download_data --application=s~$(project_id) --url=http://datastore-admin-dot-$(project_id).appspot.com/_ah/remote_api/ --filename=datastore.bin
$(appcfg.py) --url=http://localhost:8080/_ah/remote_api --filename=datastore.bin upload_data
# Helpers to store and retrieve build artifacts
artifact-download:
buildkite-agent artifact download sdk-$(BUILDKITE_BRANCH).tar . && tar -xf sdk-$(BUILDKITE_BRANCH).tar || echo no sdk artifact found
artifact-download-prev : build_id = $(shell curl -H "Authorization: Bearer 08a7fd928cc9062dd7522f92f9781fb0d7ea822f" https://api.buildkite.com/v2/organizations/hanzo/pipelines/platform/builds/$$(( $$BUILDKITE_BUILD_NUMBER - 1 )) | jq -r .id) # gitleaks:allow
artifact-download-prev:
buildkite-agent artifact download sdk-$(BUILDKITE_BRANCH).tar . --build $(build_id) && tar -xf sdk-$(BUILDKITE_BRANCH).tar || echo no sdk artifact found
artifact-upload:
tar -cf sdk-$(BUILDKITE_BRANCH).tar sdk
buildkite-agent artifact upload '*.tar'
.PHONY: all auth bench build buildkite-artifact-download \
buildkite-artifact-upload compile-js compile-js-min compile-css \
compile-css-min datastore-import datastore-export datastore-config \
deploy deploy-staging deploy-production deps deps-assets deps-go \
live-reload serve serve-clear-datastore serve-public test \
test-integration test-watch tools
.sdk:
wget https://storage.googleapis.com/appengine-sdks/featured/$(sdk).zip
unzip $(sdk).zip
mv go_appengine $(sdk_path)
rm $(sdk).zip
$(sdk_install_extra)