blob: 2923f1d452d54da8f92c7049a0825ef4d6cc0662 [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 Dearmanbe998ce2018-08-09 15:39:10 +010018function echo_and_do {
19 echo $@
20 $@
21}
22
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010023PROJECT_ROOT="$(cd -P ${BASH_SOURCE[0]%/*}/..; pwd)"
24OUT_DIR="$PROJECT_ROOT/out/ui-deploy.tmp"
25UI_DIST_DIR="$OUT_DIR/ui-dist"
26
Hector Dearmanbe998ce2018-08-09 15:39:10 +010027CLEAN_OUT_DIR=true
28DEPLOY_PROD=false
Primiano Tuccie36ca632018-08-21 14:32:23 +020029DEPLOY_STAGING=false
Primiano Tuccia4238af2018-08-21 22:50:24 +020030DEBUG_BUILD=true
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010031
Hector Dearmanbe998ce2018-08-09 15:39:10 +010032while [[ $# -gt 0 ]]; do
33 key="$1"
34 case $key in
35 --no-clean)
36 CLEAN_OUT_DIR=false
37 shift
38 ;;
39 --prod)
40 DEPLOY_PROD=true
Primiano Tuccia4238af2018-08-21 22:50:24 +020041 DEBUG_BUILD=false
Hector Dearmanbe998ce2018-08-09 15:39:10 +010042 shift
43 ;;
Primiano Tuccie36ca632018-08-21 14:32:23 +020044 --staging)
45 DEPLOY_STAGING=true
46 shift
47 ;;
Primiano Tuccia4238af2018-08-21 22:50:24 +020048 --release)
49 DEBUG_BUILD=false
50 shift
51 ;;
Hector Dearmanbe998ce2018-08-09 15:39:10 +010052 -h|--help)
Primiano Tuccie36ca632018-08-21 14:32:23 +020053 echo "Usage: $0 [--no-clean] [--prod] [--staging]"
Hector Dearmanbe998ce2018-08-09 15:39:10 +010054 echo " --no-clean Don't remove $OUT_DIR"
Primiano Tuccia4238af2018-08-21 22:50:24 +020055 echo " --prod Deploy prod version (implies --release)"
Primiano Tuccie36ca632018-08-21 14:32:23 +020056 echo " --staging Deploy staging version"
Primiano Tuccia4238af2018-08-21 22:50:24 +020057 echo " --release Do a release build"
Hector Dearmanbe998ce2018-08-09 15:39:10 +010058 echo " -h|--help Display this message"
59 exit 0
60 shift
61 ;;
62 esac
63done
64
65if [ "$CLEAN_OUT_DIR" = true ]; then
66 echo_and_do rm -rf "$OUT_DIR"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010067fi
Hector Dearmanbe998ce2018-08-09 15:39:10 +010068echo_and_do mkdir -p "$UI_DIST_DIR"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010069
Primiano Tuccia4238af2018-08-21 22:50:24 +020070if [ "$DEBUG_BUILD" = true ]; then
71 echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=true"
72else
73 echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=false"
74fi
75
Hector Dearmanbe998ce2018-08-09 15:39:10 +010076echo_and_do "$PROJECT_ROOT/tools/ninja" -C "$OUT_DIR" ui
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010077
Hector Dearmanbe998ce2018-08-09 15:39:10 +010078echo "Writing $UI_DIST_DIR/app.yaml"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +010079cat<<EOF > "$UI_DIST_DIR/app.yaml"
80runtime: python27
81api_version: 1
82threadsafe: yes
83instance_class: B1
84manual_scaling:
85 instances: 1
86handlers:
87- url: /
88 static_files: static/index.html
89 upload: static/index.html
90 secure: always
91 redirect_http_response_code: 301
92- url: /(.*[.]wasm)
93 static_files: static/\1
94 upload: static/(.*[.]wasm)
95 mime_type: application/wasm
Hector Dearmane97a4992019-02-13 10:49:27 +000096- url: /assets/(.*)
97 static_files: static/assets/\1
98 upload: static/assets/(.*)
99 expiration: "1d"
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100100- url: /(.*)
101 static_files: static/\1
102 upload: static/(.*)
103EOF
104
Primiano Tuccie36ca632018-08-21 14:32:23 +0200105echo_and_do ln -fs ../ui $UI_DIST_DIR/static
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100106
107(
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100108 echo_and_do cd "$UI_DIST_DIR";
109 if [ "$DEPLOY_PROD" = true ]; then
Primiano Tuccie36ca632018-08-21 14:32:23 +0200110 echo_and_do gcloud app deploy app.yaml --project perfetto-ui -v prod
111 elif [ "$DEPLOY_STAGING" = true ]; then
112 echo_and_do gcloud app deploy app.yaml --project perfetto-ui \
113 -v staging --no-promote --stop-previous-version
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100114 else
115 echo_and_do gcloud app deploy app.yaml --project perfetto-ui \
Primiano Tuccie36ca632018-08-21 14:32:23 +0200116 -v $USER --no-promote --stop-previous-version
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100117 fi
Primiano Tuccifd5e4d82018-08-06 22:17:56 +0100118)
119
Hector Dearmanbe998ce2018-08-09 15:39:10 +0100120if [ "$CLEAN_OUT_DIR" = true ]; then
121 echo_and_do rm -rf "$OUT_DIR"
122fi