Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2018 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -e |
| 17 | |
Hector Dearman | f01fe91 | 2020-06-26 14:53:17 +0100 | [diff] [blame] | 18 | function print_usage { |
| 19 | echo "Usage: $0 [--no-clean] [--prod] [--staging]" |
| 20 | echo " --no-clean Don't remove $OUT_DIR" |
Isabelle Taylor | 73b779e | 2020-07-20 17:32:22 +0100 | [diff] [blame] | 21 | echo " --prod Deploy prod version" |
Hector Dearman | f01fe91 | 2020-06-26 14:53:17 +0100 | [diff] [blame] | 22 | echo " --staging Deploy staging version" |
Isabelle Taylor | 73b779e | 2020-07-20 17:32:22 +0100 | [diff] [blame] | 23 | echo " --debug Do a debug build" |
Hector Dearman | f01fe91 | 2020-06-26 14:53:17 +0100 | [diff] [blame] | 24 | echo " -h|--help Display this message" |
| 25 | } |
| 26 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 27 | function echo_and_do { |
| 28 | echo $@ |
| 29 | $@ |
| 30 | } |
| 31 | |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 32 | PROJECT_ROOT="$(cd -P ${BASH_SOURCE[0]%/*}/..; pwd)" |
| 33 | OUT_DIR="$PROJECT_ROOT/out/ui-deploy.tmp" |
| 34 | UI_DIST_DIR="$OUT_DIR/ui-dist" |
| 35 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 36 | CLEAN_OUT_DIR=true |
| 37 | DEPLOY_PROD=false |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 38 | DEPLOY_STAGING=false |
Isabelle Taylor | 73b779e | 2020-07-20 17:32:22 +0100 | [diff] [blame] | 39 | DEBUG_BUILD=false |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 40 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 41 | while [[ $# -gt 0 ]]; do |
| 42 | key="$1" |
| 43 | case $key in |
| 44 | --no-clean) |
| 45 | CLEAN_OUT_DIR=false |
| 46 | shift |
| 47 | ;; |
| 48 | --prod) |
| 49 | DEPLOY_PROD=true |
| 50 | shift |
| 51 | ;; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 52 | --staging) |
| 53 | DEPLOY_STAGING=true |
| 54 | shift |
| 55 | ;; |
Isabelle Taylor | 73b779e | 2020-07-20 17:32:22 +0100 | [diff] [blame] | 56 | --debug) |
| 57 | DEBUG_BUILD=true |
Primiano Tucci | a4238af | 2018-08-21 22:50:24 +0200 | [diff] [blame] | 58 | shift |
| 59 | ;; |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 60 | -h|--help) |
Hector Dearman | f01fe91 | 2020-06-26 14:53:17 +0100 | [diff] [blame] | 61 | print_usage |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 62 | exit 0 |
| 63 | shift |
| 64 | ;; |
Hector Dearman | f01fe91 | 2020-06-26 14:53:17 +0100 | [diff] [blame] | 65 | *) |
| 66 | print_usage |
| 67 | exit 1 |
| 68 | shift |
| 69 | ;; |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 70 | esac |
| 71 | done |
| 72 | |
| 73 | if [ "$CLEAN_OUT_DIR" = true ]; then |
| 74 | echo_and_do rm -rf "$OUT_DIR" |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 75 | fi |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 76 | echo_and_do mkdir -p "$UI_DIST_DIR" |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 77 | |
Primiano Tucci | a4238af | 2018-08-21 22:50:24 +0200 | [diff] [blame] | 78 | if [ "$DEBUG_BUILD" = true ]; then |
| 79 | echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=true" |
| 80 | else |
| 81 | echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=false" |
| 82 | fi |
| 83 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 84 | echo_and_do "$PROJECT_ROOT/tools/ninja" -C "$OUT_DIR" ui |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 85 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 86 | echo "Writing $UI_DIST_DIR/app.yaml" |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 87 | cat<<EOF > "$UI_DIST_DIR/app.yaml" |
| 88 | runtime: python27 |
| 89 | api_version: 1 |
| 90 | threadsafe: yes |
| 91 | instance_class: B1 |
Primiano Tucci | ad2046a | 2020-02-03 11:51:11 +0000 | [diff] [blame] | 92 | default_expiration: "1m" |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 93 | manual_scaling: |
| 94 | instances: 1 |
| 95 | handlers: |
| 96 | - url: / |
| 97 | static_files: static/index.html |
| 98 | upload: static/index.html |
| 99 | secure: always |
| 100 | redirect_http_response_code: 301 |
| 101 | - url: /(.*[.]wasm) |
| 102 | static_files: static/\1 |
| 103 | upload: static/(.*[.]wasm) |
| 104 | mime_type: application/wasm |
Hector Dearman | e97a499 | 2019-02-13 10:49:27 +0000 | [diff] [blame] | 105 | - url: /assets/(.*) |
| 106 | static_files: static/assets/\1 |
| 107 | upload: static/assets/(.*) |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 108 | - url: /(.*) |
| 109 | static_files: static/\1 |
| 110 | upload: static/(.*) |
| 111 | EOF |
| 112 | |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 113 | echo_and_do ln -fs ../ui $UI_DIST_DIR/static |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 114 | |
| 115 | ( |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 116 | echo_and_do cd "$UI_DIST_DIR"; |
| 117 | if [ "$DEPLOY_PROD" = true ]; then |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 118 | echo_and_do gcloud app deploy app.yaml --project perfetto-ui -v prod |
| 119 | elif [ "$DEPLOY_STAGING" = true ]; then |
| 120 | echo_and_do gcloud app deploy app.yaml --project perfetto-ui \ |
| 121 | -v staging --no-promote --stop-previous-version |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 122 | else |
| 123 | echo_and_do gcloud app deploy app.yaml --project perfetto-ui \ |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 124 | -v $USER --no-promote --stop-previous-version |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 125 | fi |
Primiano Tucci | fd5e4d8 | 2018-08-06 22:17:56 +0100 | [diff] [blame] | 126 | ) |
| 127 | |
Hector Dearman | be998ce | 2018-08-09 15:39:10 +0100 | [diff] [blame] | 128 | if [ "$CLEAN_OUT_DIR" = true ]; then |
| 129 | echo_and_do rm -rf "$OUT_DIR" |
| 130 | fi |