blob: f94295e521298fcc17c7df2320ed46cabfd62d6e [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6# Makefile to simplify some common AppEngine actions.
7# Use 'make help' for a list of commands.
8
9DEVID = monorail-dev
10STAGEID= monorail-staging
11PRODID= monorail-prod
12
13GAE_PY?= python gae.py
14DEV_APPSERVER_FLAGS?= --watcher_ignore_re="(.*/lib|.*/node_modules|.*/third_party|.*/venv)"
15
16WEBPACK_PATH := ./node_modules/webpack-cli/bin/cli.js
17
18TARDIR ?= "/workspace"
19
20FRONTEND_MODULES?= default
21BACKEND_MODULES?= besearch latency-insensitive api
22
23BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
24
25PY_DIRS = api,businesslogic,features,framework,project,proto,search,services,sitewide,testing,tracker
26
27_VERSION ?= $(shell ../../../infra/luci/appengine/components/tools/calculate_version.py)
28
29SPIN = $(shell command -v spin 2> /dev/null)
30
31default: help
32
33check:
34ifndef NPM_VERSION
35 $(error npm not found. Install from nodejs.org or see README)
36endif
37
38help:
39 @echo "Available commands:"
40 @sed -n '/^[a-zA-Z0-9_.]*:/s/:.*//p' <Makefile
41
42# Run "eval `../../go/env.py`" before running the following prpc_proto commands
43prpc_proto_v0:
44 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
45 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
46 PATH=../../luci/appengine/components/tools:$(PATH) \
47 ../../cipd/protoc \
48 --python_out=. --prpc-python_out=. api/api_proto/*.proto
49 cd ../../go/src/infra/monorailv2 && \
50 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/api_proto/
51prpc_proto_v3:
52 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
53 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
54 PATH=../../luci/appengine/components/tools:$(PATH) \
55 ../../cipd/protoc \
56 --python_out=. --prpc-python_out=. api/v3/api_proto/*.proto
57 cd ../../go/src/infra/monorailv2 && \
58 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/v3/api_proto/
59
60business_proto:
61 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
62 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
63 PATH=../../luci/appengine/components/tools:$(PATH) \
64 ../../cipd/protoc \
65 --python_out=. --prpc-python_out=. proto/*.proto
66
67test:
68 ../../test.py test appengine/monorail
69
70test_no_coverage:
71 ../../test.py test appengine/monorail --no-coverage
72
73coverage:
74 @echo "Running tests + HTML coverage report in ~/monorail-coverage:"
75 ../../test.py test appengine/monorail --html-report ~/monorail-coverage --coveragerc appengine/monorail/.coveragerc
76
77# Shows coverage on the tests themselves, helps illuminate when we have test
78# methods that aren't used.
79test_coverage:
80 @echo "Running tests + HTML coverage report (for tests) in ~/monorail-test-coverage:"
81 ../../test.py test appengine/monorail --html-report ~/monorail-test-coverage --coveragerc appengine/monorail/.testcoveragerc
82
83# Commands for running locally using dev_appserver.
84# devserver requires an application ID (-A) to be specified.
85# We are using `-A monorail-staging` because ml spam code is set up
86# to impersonate monorail-staging in the local environment.
87serve: config_local
88 @echo "---[Starting SDK AppEngine Server]---"
89 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS)& $(WEBPACK_PATH) --watch
90
91serve_email: config_local
92 @echo "---[Starting SDK AppEngine Server]---"
93 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True& $(WEBPACK_PATH) --watch
94
95# The _remote commands expose the app on 0.0.0.0, so that it is externally
96# accessible by hostname:port, rather than just localhost:port.
97serve_remote: config_local
98 @echo "---[Starting SDK AppEngine Server]---"
99 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS)& $(WEBPACK_PATH) --watch
100
101serve_remote_email: config_local
102 @echo "---[Starting SDK AppEngine Server]---"
103 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True& $(WEBPACK_PATH) --watch
104
105run: serve
106
107deps: node_deps
108 rm -f static/dist/*
109
110build_js:
111 $(WEBPACK_PATH) --mode=production
112
113clean_deps:
114 rm -rf node_modules
115
116node_deps:
117 npm ci --no-save
118
119dev_deps:
120 python -m pip install --no-deps -r requirements.dev.txt
121
122karma:
123 npx karma start --debug --coverage
124
125karma_debug:
126 npx karma start --debug
127
128pylint:
129 pylint -f parseable *py {$(PY_DIRS)}{/,/test/}*py
130
131py3lint:
132 pylint --py3k *py {$(PY_DIRS)}{/,/test/}*py
133
134config: config_prod_cloud config_staging_cloud config_dev_cloud
135
136# Service yaml files used by gae.py are expected to be named module-<service-name>.yaml
137config_prod:
138 m4 -DPROD < app.yaml.m4 > app.yaml
139 m4 -DPROD < module-besearch.yaml.m4 > module-besearch.yaml
140 m4 -DPROD < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml
141 m4 -DPROD < module-api.yaml.m4 > module-api.yaml
142
143# Generate yaml files used by spinnaker.
144config_prod_cloud:
145 m4 -DPROD < app.yaml.m4 > app.prod.yaml
146 m4 -DPROD < module-besearch.yaml.m4 > besearch.prod.yaml
147 m4 -DPROD < module-latency-insensitive.yaml.m4 > latency-insensitive.prod.yaml
148 m4 -DPROD < module-api.yaml.m4 > api.prod.yaml
149
150config_staging:
151 m4 -DSTAGING < app.yaml.m4 > app.yaml
152 m4 -DSTAGING < module-besearch.yaml.m4 > module-besearch.yaml
153 m4 -DSTAGING < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml
154 m4 -DSTAGING < module-api.yaml.m4 > module-api.yaml
155
156config_staging_cloud:
157 m4 -DSTAGING < app.yaml.m4 > app.staging.yaml
158 m4 -DSTAGING < module-besearch.yaml.m4 > besearch.staging.yaml
159 m4 -DSTAGING < module-latency-insensitive.yaml.m4 > latency-insensitive.staging.yaml
160 m4 -DSTAGING < module-api.yaml.m4 > api.staging.yaml
161
162config_dev:
163 m4 -DDEV < app.yaml.m4 > app.yaml
164 m4 -DDEV < module-besearch.yaml.m4 > module-besearch.yaml
165 m4 -DDEV < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml
166 m4 -DDEV < module-api.yaml.m4 > module-api.yaml
167
168config_dev_cloud:
169 m4 -DDEV < app.yaml.m4 > app.yaml
170 m4 -DDEV < module-besearch.yaml.m4 > besearch.yaml
171 m4 -DDEV < module-latency-insensitive.yaml.m4 > latency-insensitive.yaml
172 m4 -DDEV < module-api.yaml.m4 > api.yaml
173
174config_local:
175 m4 app.yaml.m4 > app.yaml
176 m4 module-besearch.yaml.m4 > module-besearch.yaml
177 m4 module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml
178 m4 module-api.yaml.m4 > module-api.yaml
179
180deploy_dev: clean_deps deps build_js config_dev
181 $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD))
182 @echo "---[Dev $(DEVID)]---"
183 $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES) $(BACKEND_MODULES)
184
185deploy_cloud_dev: clean_deps deps build_js config
186 $(eval GCB_DIR:= $(shell mktemp -d -p /tmp monorail_XXXXX))
187 rsync -aLK . $(GCB_DIR) # Dereferences symlinks before snapshotting.
188 cd $(GCB_DIR) && tar cf ${_VERSION}.tar .
189 gsutil cp $(GCB_DIR)/${_VERSION}.tar gs://chrome-infra-builds/monorail/dev
190 rm -rf $(GCB_DIR)
191
192
193deploy:
194ifeq ($(SPIN),)
195 $(error "please install spin go/chops-install-spin")
196endif
197 $(SPIN) pipeline execute --name "Deploy Monorail" --application monorail
198 @echo "Follow progress here: https://spinnaker-1.endpoints.chrome-infra-spinnaker.cloud.goog/#/applications/monorail/executions"
199
200external_deps: clean_deps deps build_js config
201
202package_release:
203 rsync -aLK . $(TARDIR)/package
204
205
206
207lsbuilds:
208 gcloud builds list --filter="tags='monorail'"
209
210# AppEngine apps can be tested locally and in non-default versions upload to
211# the main app-id, but it is still sometimes useful to have a completely
212# separate app-id. E.g., for testing inbound email, load testing, or using
213# throwaway databases.
214deploy_staging: clean_deps deps build_js config_staging
215 @echo "---[Staging $(STAGEID)]---"
216 $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES) $(BACKEND_MODULES)
217
218# This is our production server that users actually use.
219deploy_prod: clean_deps deps build_js config_prod
220 @echo "---[Deploying prod instance $(PRODID)]---"
221 $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES) $(BACKEND_MODULES)
222
223# Note that we do not provide a command-line way to make the newly-uploaded
224# version the default version. This is for two reasons: a) You should be using
225# your browser to confirm that the new version works anyway, so just use the
226# console interface to make it the default; and b) If you really want to use
227# the command line you can use gae.py directly.