blob: 8e111282f670dc7fe156dd3921cb7aa3af53b529 [file] [log] [blame]
Primiano Tuccifd5e4d82018-08-06 22:17:56 +01001#!/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
16set -e
17
Hector Dearmanf01fe912020-06-26 14:53:17 +010018function print_usage {
19 echo "Usage: $0 [--no-clean] [--prod] [--staging]"
20 echo " --no-clean Don't remove $OUT_DIR"
Isabelle Taylor73b779e2020-07-20 17:32:22 +010021 echo " --prod Deploy prod version"
Hector Dearmanf01fe912020-06-26 14:53:17 +010022 echo " --staging Deploy staging version"
Isabelle Taylor73b779e2020-07-20 17:32:22 +010023 echo " --debug Do a debug build"
Hector Dearmanf01fe912020-06-26 14:53:17 +010024 echo " -h|--help Display this message"
25}
26
Hector Dearmanbe998ce2018-08-09 15:39:10 +010027function echo_and_do {
28 echo $@
29 $@
30}
31
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010032PROJECT_ROOT="$(cd -P ${BASH_SOURCE[0]%/*}/..; pwd)"
33OUT_DIR="$PROJECT_ROOT/out/ui-deploy.tmp"
34UI_DIST_DIR="$OUT_DIR/ui-dist"
35
Hector Dearmanbe998ce2018-08-09 15:39:10 +010036CLEAN_OUT_DIR=true
37DEPLOY_PROD=false
Primiano Tuccie36ca632018-08-21 14:32:23 +020038DEPLOY_STAGING=false
Isabelle Taylor73b779e2020-07-20 17:32:22 +010039DEBUG_BUILD=false
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010040
Hector Dearmanbe998ce2018-08-09 15:39:10 +010041while [[ $# -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 Tuccie36ca632018-08-21 14:32:23 +020052 --staging)
53 DEPLOY_STAGING=true
54 shift
55 ;;
Isabelle Taylor73b779e2020-07-20 17:32:22 +010056 --debug)
57 DEBUG_BUILD=true
Primiano Tuccia4238af2018-08-21 22:50:24 +020058 shift
59 ;;
Hector Dearmanbe998ce2018-08-09 15:39:10 +010060 -h|--help)
Hector Dearmanf01fe912020-06-26 14:53:17 +010061 print_usage
Hector Dearmanbe998ce2018-08-09 15:39:10 +010062 exit 0
63 shift
64 ;;
Hector Dearmanf01fe912020-06-26 14:53:17 +010065 *)
66 print_usage
67 exit 1
68 shift
69 ;;
Hector Dearmanbe998ce2018-08-09 15:39:10 +010070 esac
71done
72
73if [ "$CLEAN_OUT_DIR" = true ]; then
74 echo_and_do rm -rf "$OUT_DIR"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010075fi
Hector Dearmanbe998ce2018-08-09 15:39:10 +010076echo_and_do mkdir -p "$UI_DIST_DIR"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010077
Primiano Tuccia4238af2018-08-21 22:50:24 +020078if [ "$DEBUG_BUILD" = true ]; then
79 echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=true"
80else
81 echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=false"
82fi
83
Hector Dearmanbe998ce2018-08-09 15:39:10 +010084echo_and_do "$PROJECT_ROOT/tools/ninja" -C "$OUT_DIR" ui
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010085
Hector Dearmanbe998ce2018-08-09 15:39:10 +010086echo "Writing $UI_DIST_DIR/app.yaml"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010087cat<<EOF > "$UI_DIST_DIR/app.yaml"
88runtime: python27
89api_version: 1
90threadsafe: yes
91instance_class: B1
Primiano Tucciad2046a2020-02-03 11:51:11 +000092default_expiration: "1m"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010093manual_scaling:
94 instances: 1
95handlers:
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 Dearmane97a4992019-02-13 10:49:27 +0000105- url: /assets/(.*)
106 static_files: static/assets/\1
107 upload: static/assets/(.*)
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100108- url: /(.*)
109 static_files: static/\1
110 upload: static/(.*)
111EOF
112
Primiano Tuccie36ca632018-08-21 14:32:23 +0200113echo_and_do ln -fs ../ui $UI_DIST_DIR/static
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100114
115(
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100116 echo_and_do cd "$UI_DIST_DIR";
117 if [ "$DEPLOY_PROD" = true ]; then
Primiano Tuccie36ca632018-08-21 14:32:23 +0200118 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 Dearmanbe998ce2018-08-09 15:39:10 +0100122 else
123 echo_and_do gcloud app deploy app.yaml --project perfetto-ui \
Primiano Tuccie36ca632018-08-21 14:32:23 +0200124 -v $USER --no-promote --stop-previous-version
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100125 fi
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100126)
127
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100128if [ "$CLEAN_OUT_DIR" = true ]; then
129 echo_and_do rm -rf "$OUT_DIR"
130fi