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 |
| 11 | PRODID= monorail-prod |
| 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) \ |
| 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 | |
| 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 |
| 139 | m4 -DPROD < module-besearch.yaml.m4 > module-besearch.yaml |
| 140 | m4 -DPROD < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml |
| 141 | m4 -DPROD < module-api.yaml.m4 > module-api.yaml |
| 142 | |
| 143 | # Generate yaml files used by spinnaker. |
| 144 | config_prod_cloud: |
| 145 | m4 -DPROD < app.yaml.m4 > app.prod.yaml |
| 146 | m4 -DPROD < module-besearch.yaml.m4 > besearch.prod.yaml |
| 147 | m4 -DPROD < module-latency-insensitive.yaml.m4 > latency-insensitive.prod.yaml |
| 148 | m4 -DPROD < module-api.yaml.m4 > api.prod.yaml |
| 149 | |
| 150 | config_staging: |
| 151 | m4 -DSTAGING < app.yaml.m4 > app.yaml |
| 152 | m4 -DSTAGING < module-besearch.yaml.m4 > module-besearch.yaml |
| 153 | m4 -DSTAGING < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml |
| 154 | m4 -DSTAGING < module-api.yaml.m4 > module-api.yaml |
| 155 | |
| 156 | config_staging_cloud: |
| 157 | m4 -DSTAGING < app.yaml.m4 > app.staging.yaml |
| 158 | m4 -DSTAGING < module-besearch.yaml.m4 > besearch.staging.yaml |
| 159 | m4 -DSTAGING < module-latency-insensitive.yaml.m4 > latency-insensitive.staging.yaml |
| 160 | m4 -DSTAGING < module-api.yaml.m4 > api.staging.yaml |
| 161 | |
| 162 | config_dev: |
| 163 | m4 -DDEV < app.yaml.m4 > app.yaml |
| 164 | m4 -DDEV < module-besearch.yaml.m4 > module-besearch.yaml |
| 165 | m4 -DDEV < module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml |
| 166 | m4 -DDEV < module-api.yaml.m4 > module-api.yaml |
| 167 | |
| 168 | config_dev_cloud: |
| 169 | m4 -DDEV < app.yaml.m4 > app.yaml |
| 170 | m4 -DDEV < module-besearch.yaml.m4 > besearch.yaml |
| 171 | m4 -DDEV < module-latency-insensitive.yaml.m4 > latency-insensitive.yaml |
| 172 | m4 -DDEV < module-api.yaml.m4 > api.yaml |
| 173 | |
| 174 | config_local: |
| 175 | m4 app.yaml.m4 > app.yaml |
| 176 | m4 module-besearch.yaml.m4 > module-besearch.yaml |
| 177 | m4 module-latency-insensitive.yaml.m4 > module-latency-insensitive.yaml |
| 178 | m4 module-api.yaml.m4 > module-api.yaml |
| 179 | |
| 180 | deploy_dev: clean_deps deps build_js config_dev |
| 181 | $(eval BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)) |
| 182 | @echo "---[Dev $(DEVID)]---" |
| 183 | $(GAE_PY) upload --tag $(BRANCH_NAME) -A $(DEVID) $(FRONTEND_MODULES) $(BACKEND_MODULES) |
| 184 | |
| 185 | deploy_cloud_dev: clean_deps deps build_js config |
| 186 | $(eval GCB_DIR:= $(shell mktemp -d -p /tmp monorail_XXXXX)) |
| 187 | rsync -aLK . $(GCB_DIR) # Dereferences symlinks before snapshotting. |
| 188 | cd $(GCB_DIR) && tar cf ${_VERSION}.tar . |
| 189 | gsutil cp $(GCB_DIR)/${_VERSION}.tar gs://chrome-infra-builds/monorail/dev |
| 190 | rm -rf $(GCB_DIR) |
| 191 | |
| 192 | |
| 193 | deploy: |
| 194 | ifeq ($(SPIN),) |
| 195 | $(error "please install spin go/chops-install-spin") |
| 196 | endif |
| 197 | $(SPIN) pipeline execute --name "Deploy Monorail" --application monorail |
| 198 | @echo "Follow progress here: https://spinnaker-1.endpoints.chrome-infra-spinnaker.cloud.goog/#/applications/monorail/executions" |
| 199 | |
| 200 | external_deps: clean_deps deps build_js config |
| 201 | |
| 202 | package_release: |
| 203 | rsync -aLK . $(TARDIR)/package |
| 204 | |
| 205 | |
| 206 | |
| 207 | lsbuilds: |
| 208 | gcloud builds list --filter="tags='monorail'" |
| 209 | |
| 210 | # AppEngine apps can be tested locally and in non-default versions upload to |
| 211 | # the main app-id, but it is still sometimes useful to have a completely |
| 212 | # separate app-id. E.g., for testing inbound email, load testing, or using |
| 213 | # throwaway databases. |
| 214 | deploy_staging: clean_deps deps build_js config_staging |
| 215 | @echo "---[Staging $(STAGEID)]---" |
| 216 | $(GAE_PY) upload -A $(STAGEID) $(FRONTEND_MODULES) $(BACKEND_MODULES) |
| 217 | |
| 218 | # This is our production server that users actually use. |
| 219 | deploy_prod: clean_deps deps build_js config_prod |
| 220 | @echo "---[Deploying prod instance $(PRODID)]---" |
| 221 | $(GAE_PY) upload -A $(PRODID) $(FRONTEND_MODULES) $(BACKEND_MODULES) |
| 222 | |
| 223 | # Note that we do not provide a command-line way to make the newly-uploaded |
| 224 | # version the default version. This is for two reasons: a) You should be using |
| 225 | # your browser to confirm that the new version works anyway, so just use the |
| 226 | # console interface to make it the default; and b) If you really want to use |
| 227 | # the command line you can use gae.py directly. |