blob: 57cf67957fa27aac96a6ad36f63e3815ddde8e8c [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
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020029RUN_CLOUD_TASKS := ../../cipd/cloud-tasks-emulator \
30 --queue projects/monorail-staging/locations/us-central1/queues/componentexport \
31 --queue projects/monorail-staging/locations/us-central1/queues/default \
32 --queue projects/monorail-staging/locations/us-central1/queues/notifications \
33 --queue projects/monorail-staging/locations/us-central1/queues/outboundemail \
34 --queue projects/monorail-staging/locations/us-central1/queues/recomputederivedfields \
35 --queue projects/monorail-staging/locations/us-central1/queues/spamexport \
36 --queue projects/monorail-staging/locations/us-central1/queues/wipeoutsendusers \
37 --queue projects/monorail-staging/locations/us-central1/queues/wipeoutdeleteusers \
38 --queue projects/monorail-staging/locations/us-central1/queues/deleteusers \
39 --queue projects/monorail-staging/locations/us-central1/queues/pubsub-issueupdates \
40 -host localhost \
41 -port 9090
42
Copybara854996b2021-09-07 19:36:02 +000043default: help
44
45check:
46ifndef NPM_VERSION
47 $(error npm not found. Install from nodejs.org or see README)
48endif
49
50help:
51 @echo "Available commands:"
52 @sed -n '/^[a-zA-Z0-9_.]*:/s/:.*//p' <Makefile
53
54# Run "eval `../../go/env.py`" before running the following prpc_proto commands
55prpc_proto_v0:
56 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
57 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
58 PATH=../../luci/appengine/components/tools:$(PATH) \
59 ../../cipd/protoc \
60 --python_out=. --prpc-python_out=. api/api_proto/*.proto
61 cd ../../go/src/infra/monorailv2 && \
62 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/api_proto/
63prpc_proto_v3:
64 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
65 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
66 PATH=../../luci/appengine/components/tools:$(PATH) \
Adrià Vilanova Martínezf5e10392021-12-07 22:55:40 +010067 ../../cipd/bin/protoc \
Copybara854996b2021-09-07 19:36:02 +000068 --python_out=. --prpc-python_out=. api/v3/api_proto/*.proto
69 cd ../../go/src/infra/monorailv2 && \
70 cproto -proto-path ../../../../appengine/monorail/ ../../../../appengine/monorail/api/v3/api_proto/
71
72business_proto:
73 touch ../../ENV/lib/python2.7/site-packages/google/__init__.py
74 PYTHONPATH=../../ENV/lib/python2.7/site-packages \
75 PATH=../../luci/appengine/components/tools:$(PATH) \
76 ../../cipd/protoc \
77 --python_out=. --prpc-python_out=. proto/*.proto
78
79test:
80 ../../test.py test appengine/monorail
81
82test_no_coverage:
83 ../../test.py test appengine/monorail --no-coverage
84
85coverage:
86 @echo "Running tests + HTML coverage report in ~/monorail-coverage:"
87 ../../test.py test appengine/monorail --html-report ~/monorail-coverage --coveragerc appengine/monorail/.coveragerc
88
89# Shows coverage on the tests themselves, helps illuminate when we have test
90# methods that aren't used.
91test_coverage:
92 @echo "Running tests + HTML coverage report (for tests) in ~/monorail-test-coverage:"
93 ../../test.py test appengine/monorail --html-report ~/monorail-test-coverage --coveragerc appengine/monorail/.testcoveragerc
94
95# Commands for running locally using dev_appserver.
96# devserver requires an application ID (-A) to be specified.
97# We are using `-A monorail-staging` because ml spam code is set up
98# to impersonate monorail-staging in the local environment.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +010099serve:
Copybara854996b2021-09-07 19:36:02 +0000100 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200101 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS)\
102 & $(WEBPACK_PATH) --watch\
103 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000104
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100105serve_email:
Copybara854996b2021-09-07 19:36:02 +0000106 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200107 $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\
108 & $(WEBPACK_PATH) --watch\
109 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000110
111# The _remote commands expose the app on 0.0.0.0, so that it is externally
112# accessible by hostname:port, rather than just localhost:port.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100113serve_remote:
Copybara854996b2021-09-07 19:36:02 +0000114 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200115 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS)\
116 & $(WEBPACK_PATH) --watch\
117 & $(RUN_CLOUD_TASKS)
Copybara854996b2021-09-07 19:36:02 +0000118
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100119serve_remote_email:
Copybara854996b2021-09-07 19:36:02 +0000120 @echo "---[Starting SDK AppEngine Server]---"
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +0200121 $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\
122 & $(WEBPACK_PATH) --watch\
123 & $(RUN_CLOUD_TASKS)
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100124
Copybara854996b2021-09-07 19:36:02 +0000125run: serve
126
127deps: node_deps
128 rm -f static/dist/*
129
130build_js:
131 $(WEBPACK_PATH) --mode=production
132
133clean_deps:
134 rm -rf node_modules
135
136node_deps:
137 npm ci --no-save
138
139dev_deps:
140 python -m pip install --no-deps -r requirements.dev.txt
141
142karma:
143 npx karma start --debug --coverage
144
145karma_debug:
146 npx karma start --debug
147
148pylint:
149 pylint -f parseable *py {$(PY_DIRS)}{/,/test/}*py
150
151py3lint:
152 pylint --py3k *py {$(PY_DIRS)}{/,/test/}*py
153
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100154deploy_dev: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000155 $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD))
156 @echo "---[Dev $(DEVID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200157 $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000158
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100159# Build target used by LUCI CD and manual process to build frontend.
160build_frontend: clean_deps deps build_js
Copybara854996b2021-09-07 19:36:02 +0000161
162package_release:
163 rsync -aLK . $(TARDIR)/package
164
Copybara854996b2021-09-07 19:36:02 +0000165lsbuilds:
166 gcloud builds list --filter="tags='monorail'"
167
168# AppEngine apps can be tested locally and in non-default versions upload to
169# the main app-id, but it is still sometimes useful to have a completely
170# separate app-id. E.g., for testing inbound email, load testing, or using
171# throwaway databases.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100172deploy_staging: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000173 @echo "---[Staging $(STAGEID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200174 $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000175
176# This is our production server that users actually use.
Adrià Vilanova Martínez2d5457a2022-01-13 13:25:39 +0100177deploy_prod: build_frontend
Copybara854996b2021-09-07 19:36:02 +0000178 @echo "---[Deploying prod instance $(PRODID)]---"
Adrià Vilanova Martínez515639b2021-07-06 16:43:59 +0200179 $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES)
Copybara854996b2021-09-07 19:36:02 +0000180
181# Note that we do not provide a command-line way to make the newly-uploaded
182# version the default version. This is for two reasons: a) You should be using
183# your browser to confirm that the new version works anyway, so just use the
184# console interface to make it the default; and b) If you really want to use
185# the command line you can use gae.py directly.