blob: ac8c92a493ca6d23e96841f6953fc6e27f6fc171 [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
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020014DEV_APPSERVER_FLAGS?= --watcher_ignore_re="(.*/lib|.*/node_modules|.*/venv)"
Copybara854996b2021-09-07 19:36:02 +000015
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
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020029RUN_CLOUD_TASKS := ../../cipd/cloud-tasks-emulator \
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020030 --queue projects/monorail-staging/locations/us-central1/queues/default \
31 --queue projects/monorail-staging/locations/us-central1/queues/notifications \
32 --queue projects/monorail-staging/locations/us-central1/queues/outboundemail \
33 --queue projects/monorail-staging/locations/us-central1/queues/recomputederivedfields \
34 --queue projects/monorail-staging/locations/us-central1/queues/spamexport \
35 --queue projects/monorail-staging/locations/us-central1/queues/wipeoutsendusers \
36 --queue projects/monorail-staging/locations/us-central1/queues/wipeoutdeleteusers \
37 --queue projects/monorail-staging/locations/us-central1/queues/deleteusers \
38 --queue projects/monorail-staging/locations/us-central1/queues/pubsub-issueupdates \
39 -host localhost \
40 -port 9090
41
Copybara854996b2021-09-07 19:36:02 +000042default: help
43
44check:
45ifndef NPM_VERSION
46 $(error npm not found. Install from nodejs.org or see README)
47endif
48
49help:
50 @echo "Available commands:"
51 @sed -n '/^[a-zA-Z0-9_.]*:/s/:.*//p' <Makefile
52
53# Run "eval `../../go/env.py`" before running the following prpc_proto commands
54prpc_proto_v0:
55 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
56 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
57 PATH=../../luci/appengine/components/tools:$(PATH) \
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020058 ../../cipd/bin/protoc \
Copybara854996b2021-09-07 19:36:02 +000059 --python_out=. --prpc-python_out=. api/api_proto/*.proto
60 cd ../../go/src/infra/monorailv2 && \
61 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/api_proto/
62prpc_proto_v3:
63 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
64 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
65 PATH=../../luci/appengine/components/tools:$(PATH) \
Adrià Vilanova Martínezf5e10392021-12-07 22:55:40 +010066 ../../cipd/bin/protoc \
Copybara854996b2021-09-07 19:36:02 +000067 --python_out=. --prpc-python_out=. api/v3/api_proto/*.proto
68 cd ../../go/src/infra/monorailv2 && \
69 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/v3/api_proto/
70
71business_proto:
72 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
73 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
74 PATH=../../luci/appengine/components/tools:$(PATH) \
75 ../../cipd/protoc \
76 --python_out=. --prpc-python_out=. proto/*.proto
77
78test:
79 ../../test.py test appengine/monorail
80
81test_no_coverage:
82 ../../test.py test appengine/monorail --no-coverage
83
84coverage:
85 @echo "Running tests + HTML coverage report in ~/monorail-coverage:"
86 ../../test.py test appengine/monorail --html-report ~/monorail-coverage --coveragerc appengine/monorail/.coveragerc
87
88# Shows coverage on the tests themselves, helps illuminate when we have test
89# methods that aren't used.
90test_coverage:
91 @echo "Running tests + HTML coverage report (for tests) in ~/monorail-test-coverage:"
92 ../../test.py test appengine/monorail --html-report ~/monorail-test-coverage --coveragerc appengine/monorail/.testcoveragerc
93
94# Commands for running locally using dev_appserver.
95# devserver requires an application ID (-A) to be specified.
96# We are using `-A monorail-staging` because ml spam code is set up
97# to impersonate monorail-staging in the local environment.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +010098serve:
Copybara854996b2021-09-07 19:36:02 +000099 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +0200100 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) 2>&1 | grep -a -v 'AccessTokenRefreshError' | grep -a -v 'csp.do' \
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200101 & $(WEBPACK_PATH) --watch\
102 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000103
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100104serve_email:
Copybara854996b2021-09-07 19:36:02 +0000105 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200106 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\
107 & $(WEBPACK_PATH) --watch\
108 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000109
110# The _remote commands expose the app on 0.0.0.0, so that it is externally
111# accessible by hostname:port, rather than just localhost:port.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100112serve_remote:
Copybara854996b2021-09-07 19:36:02 +0000113 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200114 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS)\
115 & $(WEBPACK_PATH) --watch\
116 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000117
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100118serve_remote_email:
Copybara854996b2021-09-07 19:36:02 +0000119 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200120 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\
121 & $(WEBPACK_PATH) --watch\
122 & $(RUN_CLOUD_TASKS)
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100123
Copybara854996b2021-09-07 19:36:02 +0000124run: serve
125
126deps: node_deps
127 rm -f static/dist/*
128
129build_js:
130 $(WEBPACK_PATH) --mode=production
131
132clean_deps:
133 rm -rf node_modules
134
135node_deps:
136 npm ci --no-save
137
138dev_deps:
139 python -m pip install --no-deps -r requirements.dev.txt
140
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +0200141generate_requirements_txt:
142 vpython3 -m pip freeze > requirements.txt
143 printf "# This file is generated from the .vpython3 spec file.\n# Use \`make generate_requirements_txt\` to update.\n$$(cat requirements.txt)" > requirements.txt
144
Copybara854996b2021-09-07 19:36:02 +0000145karma:
146 npx karma start --debug --coverage
147
148karma_debug:
149 npx karma start --debug
150
151pylint:
152 pylint -f parseable *py {$(PY_DIRS)}{/,/test/}*py
153
154py3lint:
155 pylint --py3k *py {$(PY_DIRS)}{/,/test/}*py
156
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100157deploy_dev: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000158 $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD))
159 @echo "---[Dev $(DEVID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200160 $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000161
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100162# Build target used by LUCI CD and manual process to build frontend.
163build_frontend: clean_deps deps build_js
Copybara854996b2021-09-07 19:36:02 +0000164
165package_release:
166 rsync -aLK . $(TARDIR)/package
167
Copybara854996b2021-09-07 19:36:02 +0000168lsbuilds:
169 gcloud builds list --filter="tags='monorail'"
170
171# AppEngine apps can be tested locally and in non-default versions upload to
172# the main app-id, but it is still sometimes useful to have a completely
173# separate app-id. E.g., for testing inbound email, load testing, or using
174# throwaway databases.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100175deploy_staging: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000176 @echo "---[Staging $(STAGEID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200177 $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000178
179# This is our production server that users actually use.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100180deploy_prod: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000181 @echo "---[Deploying prod instance $(PRODID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200182 $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000183
184# Note that we do not provide a command-line way to make the newly-uploaded
185# version the default version. This is for two reasons: a) You should be using
186# your browser to confirm that the new version works anyway, so just use the
187# console interface to make it the default; and b) If you really want to use
188# the command line you can use gae.py directly.