Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # | 2 # |
|
Sharu Jiang
2016/11/04 18:39:46
We may also have some code in scripts to share bet
stgao
2016/11/08 18:53:32
Good point. Will add.
| |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 # This script is to ease running Findit locally, running its unit tests, and | 7 # This script is to ease running Findit locally, running its unit tests, and |
| 8 # deploying Findit to App Engine. | 8 # deploying Findit to App Engine. |
| 9 | 9 |
| 10 THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE:-$0}" )" && pwd )" | 10 THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE:-$0}" )" && pwd )" |
| 11 FINDIT_DIR="${THIS_SCRIPT_DIR}/.." | 11 FINDIT_DIR="${THIS_SCRIPT_DIR}/.." |
| 12 INFRA_DIR="${FINDIT_DIR}/../.." | 12 INFRA_DIR="${FINDIT_DIR}/../.." |
| 13 GOOGLE_APP_ENGINE_DIR="${INFRA_DIR}/../google_appengine" | 13 GOOGLE_APP_ENGINE_DIR="${INFRA_DIR}/../google_appengine" |
| 14 has_realpath="$(which realpath > /dev/null && echo 0)" | 14 has_realpath="$(which realpath > /dev/null && echo 0)" |
| 15 if [[ has_realpath == "0" ]]; then | 15 if [[ ${has_realpath} == "0" ]]; then |
| 16 FINDIT_DIR="$(realpath ${FINDIT_DIR})" | 16 FINDIT_DIR="$(realpath ${FINDIT_DIR})" |
| 17 INFRA_DIR="$(realpath ${INFRA_DIR})" | 17 INFRA_DIR="$(realpath ${INFRA_DIR})" |
| 18 GOOGLE_APP_ENGINE_DIR="$(realpath ${GOOGLE_APP_ENGINE_DIR})" | 18 GOOGLE_APP_ENGINE_DIR="$(realpath ${GOOGLE_APP_ENGINE_DIR})" |
| 19 fi | 19 fi |
| 20 APP_CFG="${GOOGLE_APP_ENGINE_DIR}/appcfg.py" | 20 APP_CFG="${GOOGLE_APP_ENGINE_DIR}/appcfg.py" |
| 21 FINDIT_MODULES="${FINDIT_DIR}/app.yaml ${FINDIT_DIR}/waterfall-frontend.yaml ${F INDIT_DIR}/waterfall-backend.yaml ${FINDIT_DIR}/crash-frontend.yaml ${FINDIT_DIR }/crash-backend-fracas.yaml" | 21 |
| 22 DEFAULT_MODULE="${FINDIT_DIR}/app.yaml" | |
| 23 OTHER_MODULES="${FINDIT_DIR}/frontend.yaml ${FINDIT_DIR}/backend.yaml" | |
| 24 | |
| 22 | 25 |
| 23 if [[ -z "${USER}" ]]; then | 26 if [[ -z "${USER}" ]]; then |
| 24 echo "Cannot identify who is deploying Findit. Please set USER." | 27 echo "Cannot identify who is deploying Findit. Please set USER." |
| 25 exit 1 | 28 exit 1 |
| 26 fi | 29 fi |
| 27 | 30 |
| 28 if [[ -z "${APPENGINE_TMP}" ]]; then | 31 if [[ -z "${APPENGINE_TMP}" ]]; then |
| 29 TMP_DIR="${FINDIT_DIR}/.tmp" | 32 TMP_DIR="${FINDIT_DIR}/.tmp" |
| 30 else | 33 else |
| 31 TMP_DIR=${APPENGINE_TMP} | 34 TMP_DIR=${APPENGINE_TMP} |
| 32 fi | 35 fi |
| 33 | 36 |
| 34 print_usage() { | 37 print_usage() { |
| 35 echo | 38 echo |
| 36 echo "Usage:" | 39 echo "Usage:" |
| 37 echo "$0 <command>" | 40 echo "$0 <command>" |
| 38 echo | 41 echo |
| 39 echo "Supported commands:" | 42 echo "Supported commands:" |
| 40 echo " test Run the unittest" | 43 echo " test Run unittests" |
| 41 echo " run Run Findit locally" | 44 echo " run Run Findit locally" |
| 42 echo " deploy-prod Deploy Findit to findit-for-me for release" | 45 echo " deploy-prod Deploy Findit to findit-for-me for release" |
| 43 echo " deploy-test-dev Deploy Findit to findit-for-me-dev for test" | 46 echo " deploy-test-prod Deploy Findit to findit-for-me for test" |
| 44 echo " deploy-test-prod Deploy Findit to findit-for-me for staging test" | 47 echo " deploy-staging Deploy Findit to findit-for-me-staging for test" |
| 45 exit 1 | 48 exit 1 |
| 46 } | 49 } |
| 47 | 50 |
| 48 print_command_for_queue_cron_dispatch() { | 51 print_command_for_queue_cron_dispatch() { |
| 49 echo | 52 echo |
| 50 echo "If there is any change to cron.yaml, dispatch.yaml, index.yaml, or" | 53 echo "If there is any change to cron.yaml, dispatch.yaml, index.yaml, or" |
| 51 echo " queue.yaml since last deployment, please run appropriate commands" | 54 echo " queue.yaml since last deployment, please run appropriate commands" |
| 52 echo " below to update them:" | 55 echo " below to update them:" |
| 53 echo " ${APP_CFG} update_cron -A $1 ${FINDIT_DIR}" | 56 echo " ${APP_CFG} update_cron -A $1 ${FINDIT_DIR}" |
| 54 echo " ${APP_CFG} update_dispatch -A $1 ${FINDIT_DIR}" | 57 echo " ${APP_CFG} update_dispatch -A $1 ${FINDIT_DIR}" |
| 55 echo " ${APP_CFG} update_indexes -A $1 ${FINDIT_DIR}" | 58 echo " ${APP_CFG} update_indexes -A $1 ${FINDIT_DIR}" |
| 56 echo " ${APP_CFG} update_queues -A $1 ${FINDIT_DIR}" | 59 echo " ${APP_CFG} update_queues -A $1 ${FINDIT_DIR}" |
| 57 } | 60 } |
| 58 | 61 |
| 59 run_unittests() { | 62 run_unittests() { |
| 60 local findit="appengine/findit" | 63 local findit="appengine/findit_mock" |
| 61 local coverage_report_parent_dir="${TMP_DIR}/coverage" | 64 local coverage_report_parent_dir="${TMP_DIR}/coverage" |
| 62 # TODO: move this directory autovivification to test.py itself | |
| 63 mkdir -p ${coverage_report_parent_dir} | 65 mkdir -p ${coverage_report_parent_dir} |
| 64 python ${INFRA_DIR}/test.py test ${findit} --html-report ${coverage_report_par ent_dir} | 66 python ${INFRA_DIR}/test.py test ${findit} --html-report ${coverage_report_par ent_dir} |
| 65 [ $? -ne 0 ] || echo "Code coverage report file://${coverage_report_parent_dir }/${findit}/index.html" | 67 [ $? -ne 0 ] || echo "Code coverage report file://${coverage_report_parent_dir }/${findit}/index.html" |
| 66 } | 68 } |
| 67 | 69 |
| 68 run_findit_locally() { | 70 run_locally() { |
| 69 local storage_path="${TMP_DIR}/findit" | 71 local storage_path="${TMP_DIR}/findit" |
| 70 local options="--storage_path ${storage_path}" | 72 local options="--storage_path ${storage_path}" |
| 71 # TODO: move this directory autovivification to dev_appserver.py itself | |
| 72 mkdir -p "${storage_path}" | 73 mkdir -p "${storage_path}" |
| 73 python ${GOOGLE_APP_ENGINE_DIR}/dev_appserver.py ${options} ${FINDIT_DIR}/disp atch.yaml ${FINDIT_MODULES} | 74 # Because of the reference in dispatch.yaml, we have to run all modules. |
| 75 python ${GOOGLE_APP_ENGINE_DIR}/dev_appserver.py ${options} ${FINDIT_DIR}/disp atch.yaml ${DEFAULT_MODULE} ${OTHER_MODULES} | |
| 74 } | 76 } |
| 75 | 77 |
| 76 deploy_findit_for_test() { | 78 deploy_for_test() { |
| 77 # Deploy a version for testing, the version name is the same as the user name. | 79 # Deploy a version for testing, the version name is the same as the user name. |
| 78 if [[ -z ${APP_ID} ]]; then | 80 local app_id_to_use=${APP_ID} |
| 79 if [[ "$1" == "prod" ]]; then | 81 local app_env=$1 |
| 82 if [[ -z ${app_id_to_use} ]]; then | |
| 83 if [[ "${app_env}" == "prod" ]]; then | |
| 80 local app_id_to_use="findit-for-me" | 84 local app_id_to_use="findit-for-me" |
| 81 else | 85 else |
| 82 local app_id_to_use="findit-for-me-dev" | 86 local app_id_to_use="findit-for-me-staging" |
| 83 fi | 87 fi |
| 84 else | |
| 85 local app_id_to_use=${APP_ID} | |
| 86 fi | 88 fi |
| 87 echo "app id is ${app_id_to_use}" | 89 echo "app id is ${app_id_to_use}" |
| 88 | 90 |
| 89 local new_version=${USER} | 91 local new_version=${USER} |
| 90 | 92 |
| 91 echo "-----------------------------------" | 93 echo "-----------------------------------" |
| 92 python ${APP_CFG} update -A ${app_id_to_use} $FINDIT_MODULES --version ${new_v ersion} | 94 python ${APP_CFG} update -A ${app_id_to_use} --version ${new_version} ${DEFAUL T_MODULE} ${OTHER_MODULES} |
| 93 echo "-----------------------------------" | 95 echo "-----------------------------------" |
| 94 print_command_for_queue_cron_dispatch ${app_id_to_use} | 96 print_command_for_queue_cron_dispatch ${app_id_to_use} |
| 95 echo "-----------------------------------" | 97 echo "-----------------------------------" |
| 96 echo Findit was deployed to "https://${new_version}-dot-${app_id_to_use}.appsp ot.com/" | 98 echo Findit was deployed to "https://${new_version}-dot-${app_id_to_use}.appsp ot.com/" |
| 97 } | 99 } |
| 98 | 100 |
| 99 deploy_findit_for_prod() { | 101 deploy_for_prod() { |
| 100 local app_id="findit-for-me" | 102 local app_id="findit-for-me" |
| 101 | 103 |
| 102 # Sync to latest code. | 104 # Sync to latest code. |
| 103 local update_log="${TMP_DIR}/update.log" | 105 local update_log="${TMP_DIR}/update.log" |
| 104 echo "Syncing code to tip of tree, logging in ${update_log} ..." | 106 echo "Syncing code to tip of tree, logging in ${update_log} ..." |
| 105 local update="0" #"$(cd ${INFRA_DIR} && git pull >>${update_log} 2>>${update_l og} && gclient sync >>$update_log >>${update_log} 2>>${update_log} && echo $?)" | 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 $?) " |
| 106 if [[ "${update}" != "0" ]]; then | 108 if [[ "${update}" != "0" ]]; then |
| 107 echo "Failed to run 'git pull && gclient sync'!" | 109 echo "Failed to run 'git pull && gclient sync'!" |
| 108 echo "Please check log at ${update_log}" | 110 echo "Please check log at ${update_log}" |
| 109 return | 111 return |
| 110 fi | 112 fi |
| 111 echo "Code was synced successfully." | 113 echo "Code was synced successfully." |
| 112 | 114 |
| 113 # Check uncommitted local changes. | 115 # Check uncommitted local changes. |
| 114 local changed_file_number="$(git status --porcelain | wc -l)" | 116 local changed_file_number="$(git status --porcelain | wc -l)" |
| 115 if [[ "${changed_file_number}" != "0" ]]; then | 117 if [[ "${changed_file_number}" != "0" ]]; then |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 134 echo "Failed to retrieve current version of Findit from the live app." | 136 echo "Failed to retrieve current version of Findit from the live app." |
| 135 echo "Please input the current version, followed by [ENTER]:" | 137 echo "Please input the current version, followed by [ENTER]:" |
| 136 read current_version | 138 read current_version |
| 137 fi | 139 fi |
| 138 | 140 |
| 139 echo "Current deployed version is ${current_version}" | 141 echo "Current deployed version is ${current_version}" |
| 140 echo "Deploying new version '${new_version}'..." | 142 echo "Deploying new version '${new_version}'..." |
| 141 | 143 |
| 142 echo | 144 echo |
| 143 echo "-----------------------------------" | 145 echo "-----------------------------------" |
| 144 python ${APP_CFG} update -A ${app_id} $FINDIT_MODULES --version ${new_version} | 146 python ${APP_CFG} update -A ${app_id} --version ${new_version} ${DEFAULT_MODUL E} ${OTHER_MODULES} |
| 145 echo "-----------------------------------" | 147 echo "-----------------------------------" |
| 146 print_command_for_queue_cron_dispatch ${app_id} | 148 print_command_for_queue_cron_dispatch ${app_id} |
| 147 echo "-----------------------------------" | 149 echo "-----------------------------------" |
| 148 echo | 150 echo |
| 149 | 151 |
| 150 echo "New version '${new_version}' of Findit was deployed to ${app_id}." | 152 echo "New version '${new_version}' of Findit was deployed to ${app_id}." |
| 151 | 153 |
| 152 local dashboard_url="https://${new_version}-dot-waterfall-frontend-dot-${app_i d}.appspot.com/waterfall/list-analyses" | 154 app_console_url="https://pantheon.corp.google.com/appengine/versions?project=$ {app_id}" |
| 153 echo "Please force a re-run of a recent build failure on dashboard ${dashboard _url}," | 155 local dashboard_url="https://${new_version}-dot-${service_frontend}-dot-${app_ id}.appspot.com/waterfall/list-analyses" |
| 154 echo "ensure that the analysis is run in the new-version waterfall frontend & backend and gives correct results," | 156 echo "Please force a re-run of a recent build failure on the dashboard ${dashb oard_url}," |
| 155 echo "and then set the new version ${new_version} as default for three modules default, waterfall-frontend and waterfall-backend." | 157 echo "ensure that the analysis is run in the new-version findit frontend & bac kend and gives correct results." |
| 158 echo | |
| 159 echo "Then press [ENTER] to confirm that the new version works as expected:" | |
| 160 read unused_var | |
| 161 echo | |
| 162 echo "Now please set the new version ${new_version} as default for the modules default, frontend and backend on ${app_console_url}." | |
| 163 echo "Then press [ENTER] to confirm that the new version was set default:" | |
| 164 read unused_var | |
| 156 echo | 165 echo |
| 157 | 166 |
| 158 local change_log_url="https://chromium.googlesource.com/infra/infra/+log/${cur rent_version}..${new_version}/appengine/findit" | 167 local change_logs_url="https://chromium.googlesource.com/infra/infra/+log/${cu rrent_version}..${new_version}/appengine/findit" |
| 159 echo "If the release is for findit-for-me, please email chrome-findit with the following:" | 168 echo "Please email chrome-findit@ with the following:" |
| 160 echo "Subject: Release: findit-for-me updated to ${new_version}." | 169 echo |
| 170 echo "Subject: Release: ${app_id} updated to ${new_version}." | |
| 161 echo "Hi all," | 171 echo "Hi all," |
| 162 echo | 172 echo |
| 163 echo "The app findit-for-me was updated from ${current_version} to ${new_versi on}." | 173 echo "The app ${app_id} was updated from ${current_version} to ${new_version}. " |
| 164 echo "Changelogs: ${change_log_url}" | 174 echo "Changelogs: ${change_logs_url}" |
| 165 echo | 175 echo |
| 166 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" | 176 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" |
| 167 echo | 177 echo |
| 168 echo "Thanks," | 178 echo "Thanks," |
| 169 echo "Released by ${USER}@" | 179 echo "Released by ${USER}@" |
| 170 } | 180 } |
| 171 | 181 |
| 172 case "$1" in | 182 case "$1" in |
| 173 test) | 183 test) |
| 174 run_unittests | 184 run_unittests |
| 175 ;; | 185 ;; |
| 176 run) | 186 run) |
| 177 run_findit_locally | 187 run_locally |
| 178 ;; | 188 ;; |
| 179 deploy-prod) | 189 deploy-prod) |
| 180 deploy_findit_for_prod | 190 deploy_for_prod |
| 181 ;; | |
| 182 deploy-test-dev) | |
| 183 deploy_findit_for_test "dev" | |
| 184 ;; | 191 ;; |
| 185 deploy-test-prod) | 192 deploy-test-prod) |
| 186 deploy_findit_for_test "prod" | 193 deploy_for_test "prod" |
| 194 ;; | |
| 195 deploy-staging) | |
| 196 deploy_for_test "dev" | |
| 187 ;; | 197 ;; |
| 188 *) | 198 *) |
| 189 print_usage | 199 print_usage |
| 190 ;; | 200 ;; |
| 191 esac | 201 esac |
| OLD | NEW |