blob: 41246b7ec8f335a8e3acacf523c8c719fd20da4a [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
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +020011PRODID= avm99963-bugs
Copybara854996b2021-09-07 19:36:02 +000012
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
Copybara854996b2021-09-07 19:36:02 +0000139
140# Generate yaml files used by spinnaker.
141config_prod_cloud:
142 m4 -DPROD < app.yaml.m4 > app.prod.yaml
Copybara854996b2021-09-07 19:36:02 +0000143
144config_staging:
145 m4 -DSTAGING < app.yaml.m4 > app.yaml
Copybara854996b2021-09-07 19:36:02 +0000146
147config_staging_cloud:
148 m4 -DSTAGING < app.yaml.m4 > app.staging.yaml
Copybara854996b2021-09-07 19:36:02 +0000149
150config_dev:
151 m4 -DDEV < app.yaml.m4 > app.yaml
Copybara854996b2021-09-07 19:36:02 +0000152
153config_dev_cloud:
154 m4 -DDEV < app.yaml.m4 > app.yaml
Copybara854996b2021-09-07 19:36:02 +0000155
156config_local:
157 m4 app.yaml.m4 > app.yaml
Copybara854996b2021-09-07 19:36:02 +0000158
159deploy_dev: clean_deps deps build_js config_dev
160 $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD))
161 @echo "---[Dev $(DEVID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200162 $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000163
164deploy_cloud_dev: clean_deps deps build_js config
165 $(eval GCB_DIR:= $(shell mktemp -d -p /tmp monorail_XXXXX))
166 rsync -aLK . $(GCB_DIR) # Dereferences symlinks before snapshotting.
167 cd $(GCB_DIR) && tar cf ${_VERSION}.tar .
168 gsutil cp $(GCB_DIR)/${_VERSION}.tar gs://chrome-infra-builds/monorail/dev
169 rm -rf $(GCB_DIR)
170
171
172deploy:
173ifeq ($(SPIN),)
174 $(error "please install spin go/chops-install-spin")
175endif
176 $(SPIN) pipeline execute --name "Deploy Monorail" --application monorail
177 @echo "Follow progress here: https://spinnaker-1.endpoints.chrome-infra-spinnaker.cloud.goog/#/applications/monorail/executions"
178
179external_deps: clean_deps deps build_js config
180
181package_release:
182 rsync -aLK . $(TARDIR)/package
183
184
185
186lsbuilds:
187 gcloud builds list --filter="tags='monorail'"
188
189# AppEngine apps can be tested locally and in non-default versions upload to
190# the main app-id, but it is still sometimes useful to have a completely
191# separate app-id. E.g., for testing inbound email, load testing, or using
192# throwaway databases.
193deploy_staging: clean_deps deps build_js config_staging
194 @echo "---[Staging $(STAGEID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200195 $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000196
197# This is our production server that users actually use.
198deploy_prod: clean_deps deps build_js config_prod
199 @echo "---[Deploying prod instance $(PRODID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200200 $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000201
202# Note that we do not provide a command-line way to make the newly-uploaded
203# version the default version. This is for two reasons: a) You should be using
204# your browser to confirm that the new version works anyway, so just use the
205# console interface to make it the default; and b) If you really want to use
206# the command line you can use gae.py directly.