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 |
| 14 | DEV_APPSERVER_FLAGS?= --watcher_ignore_re="(.*/lib|.*/node_modules|.*/third_party|.*/venv)" |
| 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 | |
| 29 | SPIN = $(shell command -v spin 2> /dev/null) |
| 30 | |
| 31 | default: help |
| 32 | |
| 33 | check: |
| 34 | ifndef NPM_VERSION |
| 35 | $(error npm not found. Install from nodejs.org or see README) |
| 36 | endif |
| 37 | |
| 38 | help: |
| 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 |
| 43 | prpc_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/ |
| 51 | prpc_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) \ |
Adrià Vilanova Martínez | f5e1039 | 2021-12-07 22:55:40 +0100 | [diff] [blame^] | 55 | ../../cipd/bin/protoc \ |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 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 | |
| 60 | business_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 | |
| 67 | test: |
| 68 | ../../test.py test appengine/monorail |
| 69 | |
| 70 | test_no_coverage: |
| 71 | ../../test.py test appengine/monorail --no-coverage |
| 72 | |
| 73 | coverage: |
| 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. |
| 79 | test_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. |
| 87 | serve: config_local |
| 88 | @echo "---[Starting SDK AppEngine Server]---" |
| 89 | $(GAE_PY) devserver -A monorail-staging -- $(DEV_APPSERVER_FLAGS)& $(WEBPACK_PATH) --watch |
| 90 | |
| 91 | serve_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. |
| 97 | serve_remote: config_local |
| 98 | @echo "---[Starting SDK AppEngine Server]---" |
| 99 | $(GAE_PY) devserver -A monorail-staging -o -- $(DEV_APPSERVER_FLAGS)& $(WEBPACK_PATH) --watch |
| 100 | |
| 101 | serve_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 | |
| 105 | run: serve |
| 106 | |
| 107 | deps: node_deps |
| 108 | rm -f static/dist/* |
| 109 | |
| 110 | build_js: |
| 111 | $(WEBPACK_PATH) --mode=production |
| 112 | |
| 113 | clean_deps: |
| 114 | rm -rf node_modules |
| 115 | |
| 116 | node_deps: |
| 117 | npm ci --no-save |
| 118 | |
| 119 | dev_deps: |
| 120 | python -m pip install --no-deps -r requirements.dev.txt |
| 121 | |
| 122 | karma: |
| 123 | npx karma start --debug --coverage |
| 124 | |
| 125 | karma_debug: |
| 126 | npx karma start --debug |
| 127 | |
| 128 | pylint: |
| 129 | pylint -f parseable *py {$(PY_DIRS)}{/,/test/}*py |
| 130 | |
| 131 | py3lint: |
| 132 | pylint --py3k *py {$(PY_DIRS)}{/,/test/}*py |
| 133 | |
| 134 | config: 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 |
| 137 | config_prod: |
| 138 | m4 -DPROD < app.yaml.m4 > app.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 139 | |
| 140 | # Generate yaml files used by spinnaker. |
| 141 | config_prod_cloud: |
| 142 | m4 -DPROD < app.yaml.m4 > app.prod.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 143 | |
| 144 | config_staging: |
| 145 | m4 -DSTAGING < app.yaml.m4 > app.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 146 | |
| 147 | config_staging_cloud: |
| 148 | m4 -DSTAGING < app.yaml.m4 > app.staging.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 149 | |
| 150 | config_dev: |
| 151 | m4 -DDEV < app.yaml.m4 > app.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 152 | |
| 153 | config_dev_cloud: |
| 154 | m4 -DDEV < app.yaml.m4 > app.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 155 | |
| 156 | config_local: |
| 157 | m4 app.yaml.m4 > app.yaml |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 158 | |
| 159 | deploy_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ínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 162 | $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 163 | |
| 164 | deploy_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 | |
| 172 | deploy: |
| 173 | ifeq ($(SPIN),) |
| 174 | $(error "please install spin go/chops-install-spin") |
| 175 | endif |
| 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 | |
| 179 | external_deps: clean_deps deps build_js config |
| 180 | |
| 181 | package_release: |
| 182 | rsync -aLK . $(TARDIR)/package |
| 183 | |
| 184 | |
| 185 | |
| 186 | lsbuilds: |
| 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. |
| 193 | deploy_staging: clean_deps deps build_js config_staging |
| 194 | @echo "---[Staging $(STAGEID)]---" |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 195 | $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 196 | |
| 197 | # This is our production server that users actually use. |
| 198 | deploy_prod: clean_deps deps build_js config_prod |
| 199 | @echo "---[Deploying prod instance $(PRODID)]---" |
Adrià Vilanova Martínez | 515639b | 2021-07-06 16:43:59 +0200 | [diff] [blame] | 200 | $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 201 | |
| 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. |