Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: appengine/predator/scripts/run.sh

Issue 2447253002: [Findit & Predator] Code reorg of Findit. (Closed)
Patch Set: Clean up. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/bin/bash
2 #
3 # Copyright 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 #
7 # This script is to ease running Predator locally, running its unit tests, and
8 # deploying Predator to App Engine.
9
10 THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE:-$0}" )" && pwd )"
11 PREDATOR_DIR="${THIS_SCRIPT_DIR}/.."
12 INFRA_DIR="${PREDATOR_DIR}/../.."
13 GOOGLE_APP_ENGINE_DIR="${INFRA_DIR}/../google_appengine"
14 has_realpath="$(which realpath 1>/dev/null 2>/dev/null && echo 0)"
15 if [[ ${has_realpath} == "0" ]]; then
16 PREDATOR_DIR="$(realpath ${PREDATOR_DIR})"
17 INFRA_DIR="$(realpath ${INFRA_DIR})"
18 GOOGLE_APP_ENGINE_DIR="$(realpath ${GOOGLE_APP_ENGINE_DIR})"
19 fi
20 APP_CFG="${GOOGLE_APP_ENGINE_DIR}/appcfg.py"
21
22 DEFAULT_MODULE="${PREDATOR_DIR}/app/app.yaml"
23 BACKEND_MODULES="${PREDATOR_DIR}/app/backend-clusterfuzz.yaml ${PREDATOR_DIR}/ap p/backend-fracas.yaml ${PREDATOR_DIR}/app/backend-cracas.yaml"
24
25
26 if [[ -z "${USER}" ]]; then
27 echo "Cannot identify who is deploying Predator. Please set USER."
28 exit 1
29 fi
30
31 if [[ -z "${APPENGINE_TMP}" ]]; then
32 TMP_DIR="${PREDATOR_DIR}/.tmp"
33 else
34 TMP_DIR=${APPENGINE_TMP}
35 fi
36
37 print_usage() {
38 echo
39 echo "Usage:"
40 echo "$0 <command>"
41 echo
42 echo "Supported commands:"
43 echo " test Run unittests"
44 echo " run Run Predator locally"
45 echo " deploy-prod Deploy predator to predator-for-me for release"
46 echo " deploy-test-prod Deploy predator to predator-for-me for test"
47 echo " deploy-staging Deploy predator to predator-for-me-staging for te st"
48 exit 1
49 }
50
51 print_command_for_queue_cron_dispatch() {
52 app_id=$1
53 echo
54 echo "If there is any change to cron.yaml, dispatch.yaml, index.yaml, or"
55 echo " queue.yaml since last deployment, please run appropriate commands"
56 echo " below to update them:"
57 echo " ${APP_CFG} update_cron -A ${app_id} ${PREDATOR_DIR}"
58 echo " ${APP_CFG} update_dispatch -A ${app_id} ${PREDATOR_DIR}"
59 echo " ${APP_CFG} update_indexes -A ${app_id} ${PREDATOR_DIR}"
60 echo " ${APP_CFG} update_queues -A ${app_id} ${PREDATOR_DIR}"
61 }
62
63 run_unittests() {
64 local predator="appengine/predator"
65 local coverage_report_parent_dir="${TMP_DIR}/coverage"
66 mkdir -p ${coverage_report_parent_dir}
67 python ${INFRA_DIR}/test.py test ${predator} --html-report ${coverage_report_p arent_dir}
68 [ $? -ne 0 ] || echo "Code coverage report file://${coverage_report_parent_dir }/${predator}/index.html"
69 }
70
71 run_locally() {
72 local storage_path="${TMP_DIR}/predator"
73 local options="--storage_path ${storage_path}"
74 mkdir -p "${storage_path}"
75 python ${GOOGLE_APP_ENGINE_DIR}/dev_appserver.py ${options} ${DEFAULT_MODULE} ${BACKEND_MODULES}
76 }
77
78 deploy_for_test() {
79 # Deploy a version for testing, the version name is the same as the user name.
80 local app_id_to_use=${APP_ID}
81 local app_env=$1
82 if [[ -z ${app_id_to_use} ]]; then
83 if [[ "${app_env}" == "prod" ]]; then
84 local app_id_to_use="predator-for-me"
85 else
86 local app_id_to_use="predator-for-me-staging"
87 fi
88 fi
89 echo "app id is ${app_id_to_use}"
90
91 local new_version=${USER}
92
93 echo "-----------------------------------"
94 python ${APP_CFG} update -A ${app_id_to_use} --version ${new_version} ${DEFAUL T_MODULE} ${BACKEND_MODULES}
95 echo "-----------------------------------"
96 print_command_for_queue_cron_dispatch ${app_id_to_use}
97 echo "-----------------------------------"
98 echo "Predator was deployed to https://${new_version}-dot-${app_id_to_use}.app spot.com/"
99 }
100
101 deploy_for_prod() {
102 local app_id="predator-for-me"
103
104 # Sync to latest code.
105 local update_log="${TMP_DIR}/update.log"
106 echo "Syncing code to tip of tree, logging in ${update_log} ..."
107 local update="0" #"$(cd ${INFRA_DIR} && git pull >>${update_log} 2>>${update_l og} && gclient sync >>${update_log} >>${update_log} 2>>${update_log} && echo $?) "
108 if [[ "${update}" != "0" ]]; then
109 echo "Failed to run 'git pull && gclient sync'!"
110 echo "Please check log at ${update_log}"
111 return
112 fi
113 echo "Code was synced successfully."
114
115 # Check uncommitted local changes.
116 local changed_file_number="$(git status --porcelain | wc -l)"
117 if [[ "${changed_file_number}" != "0" ]]; then
118 echo "You have uncommitted local changes!"
119 echo "Please run 'git status' to check local changes."
120 return
121 fi
122
123 local new_version="$(git rev-parse --short HEAD)"
124
125 # Check committed local changes.
126 local tot_version="$(git rev-parse --short origin/master)"
127 if [[ "${new_version}" != "${tot_version}" ]]; then
128 echo "You have local commits!"
129 echo "Please run 'git reset ${tot_version}' to reset the local changes."
130 return
131 fi
132
133 # Check current deployed version.
134 local current_version=`curl -s https://${app_id}.appspot.com/version`
135 if ! [[ ${current_version} =~ ^[0-9a-fA-F]+$ ]]; then
136 echo "Failed to retrieve current version of predator from the live app."
137 echo "Please input the current version, followed by [ENTER]:"
138 read current_version
139 fi
140
141 echo "Current deployed version is ${current_version}"
142 echo "Deploying new version '${new_version}'..."
143
144 echo
145 echo "-----------------------------------"
146 python ${APP_CFG} update -A ${app_id} --version ${new_version} ${DEFAULT_MODUL E} ${BACKEND_MODULES}
147 echo "-----------------------------------"
148 print_command_for_queue_cron_dispatch ${app_id}
149 echo "-----------------------------------"
150 echo
151
152 echo "New version '${new_version}' of Predator was deployed to ${app_id}."
153
154 app_console_url="https://pantheon.corp.google.com/appengine/versions?project=$ {app_id}"
155 local frontend_url="https://${new_version}-dot-${app_id}.appspot.com/"
156 echo "Please checkout the frontend ${frontend_url}, and verify that the new ve rsion works as expected."
157 echo
158 echo "Then press [ENTER] to confirm that the new version works as expected:"
159 read unused_var
160 echo "Now please set the new version ${new_version} as default for the modules default, and backend-* on ${app_console_url}."
161 echo "Then press [ENTER] to confirm that the new version was set default:"
162 read unused_var
163
164 local change_logs_url="https://chromium.googlesource.com/infra/infra/+log/${cu rrent_version}..${new_version}/appengine/predator"
165 echo "Please email chrome-predator@ with the following:"
166 echo
167 echo "Subject: Release: ${app_id} updated to ${new_version}."
168 echo "Hi all,"
169 echo
170 echo "The app ${app_id} was updated from ${current_version} to ${new_version}. "
171 echo "Changelogs: ${change_logs_url}"
172 echo
173 echo "If your bug fixes/features are included in the release, please verify on ${app_id} and mark them as verified on http://crbug.com"
174 echo
175 echo "Thanks,"
176 echo "Released by ${USER}@"
177 }
178
179 case "$1" in
180 test)
181 run_unittests
182 ;;
183 run)
184 run_locally
185 ;;
186 deploy-prod)
187 deploy_for_prod
188 ;;
189 deploy-test-prod)
190 deploy_for_test "prod"
191 ;;
192 deploy-staging)
193 deploy_for_test "dev"
194 ;;
195 *)
196 print_usage
197 ;;
198 esac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698