Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # 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 | |
| 9 | DEVID = monorail-dev |
| 10 | STAGEID= monorail-staging |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 11 | PRODID= avm99963-bugs |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 12 | |
| 13 | GAE_PY?= python gae.py |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 14 | DEV_APPSERVER_FLAGS?= --watcher_ignore_re="(.*/lib|.*/node_modules|.*/venv)" |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 15 | |
| 16 | WEBPACK_PATH := ./node_modules/webpack-cli/bin/cli.js |
| 17 | |
| 18 | TARDIR ?= "/workspace" |
| 19 | |
| 20 | FRONTEND_MODULES?= default |
| 21 | BACKEND_MODULES?= besearch latency-insensitive api |
| 22 | |
| 23 | BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD) |
| 24 | |
| 25 | PY_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ínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 29 | RUN_CLOUD_TASKS := ../../cipd/cloud-tasks-emulator \ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 30 | --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 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 42 | default: help |
| 43 | |
| 44 | check: |
| 45 | ifndef NPM_VERSION |
| 46 | $(error npm not found. Install from nodejs.org or see README) |
| 47 | endif |
| 48 | |
| 49 | help: |
| 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 |
| 54 | prpc_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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 58 | ../../cipd/bin/protoc \ |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 59 | --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/ |
| 62 | prpc_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ínez | f5e1039 | 2021-12-07 22:55:40 +0100 | [diff] [blame] | 66 | ../../cipd/bin/protoc \ |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 67 | --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 | |
| 71 | business_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 | |
Adrià Vilanova Martínez | 9f9ade5 | 2022-10-10 23:20:11 +0200 | [diff] [blame^] | 78 | pytest: |
| 79 | GAE_RUNTIME=python3 GAE_APPLICATION=testbed-test SERVER_SOFTWARE=test pytest |
| 80 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 81 | test: |
| 82 | ../../test.py test appengine/monorail |
| 83 | |
| 84 | test_no_coverage: |
| 85 | ../../test.py test appengine/monorail --no-coverage |
| 86 | |
| 87 | coverage: |
| 88 | @echo "Running tests + HTML coverage report in ~/monorail-coverage:" |
| 89 | ../../test.py test appengine/monorail --html-report ~/monorail-coverage --coveragerc appengine/monorail/.coveragerc |
| 90 | |
| 91 | # Shows coverage on the tests themselves, helps illuminate when we have test |
| 92 | # methods that aren't used. |
| 93 | test_coverage: |
| 94 | @echo "Running tests + HTML coverage report (for tests) in ~/monorail-test-coverage:" |
| 95 | ../../test.py test appengine/monorail --html-report ~/monorail-test-coverage --coveragerc appengine/monorail/.testcoveragerc |
| 96 | |
| 97 | # Commands for running locally using dev_appserver. |
| 98 | # devserver requires an application ID (-A) to be specified. |
| 99 | # We are using `-A monorail-staging` because ml spam code is set up |
| 100 | # to impersonate monorail-staging in the local environment. |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 101 | serve: |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 102 | @echo "---[Starting SDK AppEngine Server]---" |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 103 | $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) 2>&1 | grep -a -v 'AccessTokenRefreshError' | grep -a -v 'csp.do' \ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 104 | & $(WEBPACK_PATH) --watch\ |
| 105 | & $(RUN_CLOUD_TASKS) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 106 | |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 107 | serve_email: |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 108 | @echo "---[Starting SDK AppEngine Server]---" |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 109 | $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\ |
| 110 | & $(WEBPACK_PATH) --watch\ |
| 111 | & $(RUN_CLOUD_TASKS) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 112 | |
| 113 | # The _remote commands expose the app on 0.0.0.0, so that it is externally |
| 114 | # accessible by hostname:port, rather than just localhost:port. |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 115 | serve_remote: |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 116 | @echo "---[Starting SDK AppEngine Server]---" |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 117 | $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS)\ |
| 118 | & $(WEBPACK_PATH) --watch\ |
| 119 | & $(RUN_CLOUD_TASKS) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 120 | |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 121 | serve_remote_email: |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 122 | @echo "---[Starting SDK AppEngine Server]---" |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 123 | $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS) --enable_sendmail=True\ |
| 124 | & $(WEBPACK_PATH) --watch\ |
| 125 | & $(RUN_CLOUD_TASKS) |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 126 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 127 | run: serve |
| 128 | |
Adrià Vilanova Martínez | 9f9ade5 | 2022-10-10 23:20:11 +0200 | [diff] [blame^] | 129 | pydeps: |
| 130 | pip install -r requirements.txt |
| 131 | |
| 132 | jsdeps: deps |
| 133 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 134 | deps: node_deps |
| 135 | rm -f static/dist/* |
| 136 | |
| 137 | build_js: |
| 138 | $(WEBPACK_PATH) --mode=production |
| 139 | |
| 140 | clean_deps: |
| 141 | rm -rf node_modules |
| 142 | |
| 143 | node_deps: |
| 144 | npm ci --no-save |
| 145 | |
| 146 | dev_deps: |
| 147 | python -m pip install --no-deps -r requirements.dev.txt |
| 148 | |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 149 | generate_requirements_txt: |
| 150 | vpython3 -m pip freeze > requirements.txt |
| 151 | printf "# This file is generated from the .vpython3 spec file.\n# Use \`make generate_requirements_txt\` to update.\n$$(cat requirements.txt)" > requirements.txt |
| 152 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 153 | karma: |
| 154 | npx karma start --debug --coverage |
| 155 | |
| 156 | karma_debug: |
| 157 | npx karma start --debug |
| 158 | |
| 159 | pylint: |
| 160 | pylint -f parseable *py {$(PY_DIRS)}{/,/test/}*py |
| 161 | |
| 162 | py3lint: |
| 163 | pylint --py3k *py {$(PY_DIRS)}{/,/test/}*py |
| 164 | |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 165 | deploy_dev: build_frontend |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 166 | $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)) |
| 167 | @echo "---[Dev $(DEVID)]---" |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 168 | $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 169 | |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 170 | # Build target used by LUCI CD and manual process to build frontend. |
| 171 | build_frontend: clean_deps deps build_js |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 172 | |
| 173 | package_release: |
| 174 | rsync -aLK . $(TARDIR)/package |
| 175 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 176 | lsbuilds: |
| 177 | gcloud builds list --filter="tags='monorail'" |
| 178 | |
| 179 | # AppEngine apps can be tested locally and in non-default versions upload to |
| 180 | # the main app-id, but it is still sometimes useful to have a completely |
| 181 | # separate app-id. E.g., for testing inbound email, load testing, or using |
| 182 | # throwaway databases. |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 183 | deploy_staging: build_frontend |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 184 | @echo "---[Staging $(STAGEID)]---" |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 185 | $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 186 | |
| 187 | # This is our production server that users actually use. |
Adrià Vilanova Martínez | 2d5457a | 2022-01-13 13:25:39 +0100 | [diff] [blame] | 188 | deploy_prod: build_frontend |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 189 | @echo "---[Deploying prod instance $(PRODID)]---" |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 190 | $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 191 | |
| 192 | # Note that we do not provide a command-line way to make the newly-uploaded |
| 193 | # version the default version. This is for two reasons: a) You should be using |
| 194 | # your browser to confirm that the new version works anyway, so just use the |
| 195 | # console interface to make it the default; and b) If you really want to use |
| 196 | # the command line you can use gae.py directly. |