aboutsummaryrefslogtreecommitdiff
path: root/ui/deploy
blob: 2923f1d452d54da8f92c7049a0825ef4d6cc0662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

function echo_and_do {
  echo $@
  $@
}

PROJECT_ROOT="$(cd -P ${BASH_SOURCE[0]%/*}/..; pwd)"
OUT_DIR="$PROJECT_ROOT/out/ui-deploy.tmp"
UI_DIST_DIR="$OUT_DIR/ui-dist"

CLEAN_OUT_DIR=true
DEPLOY_PROD=false
DEPLOY_STAGING=false
DEBUG_BUILD=true

while [[ $# -gt 0 ]]; do
  key="$1"
  case $key in
      --no-clean)
      CLEAN_OUT_DIR=false
      shift
      ;;
      --prod)
      DEPLOY_PROD=true
      DEBUG_BUILD=false
      shift
      ;;
      --staging)
      DEPLOY_STAGING=true
      shift
      ;;
      --release)
      DEBUG_BUILD=false
      shift
      ;;
      -h|--help)
      echo "Usage: $0 [--no-clean] [--prod] [--staging]"
      echo "    --no-clean  Don't remove $OUT_DIR"
      echo "    --prod      Deploy prod version (implies --release)"
      echo "    --staging   Deploy staging version"
      echo "    --release   Do a release build"
      echo "    -h|--help   Display this message"
      exit 0
      shift
      ;;
  esac
done

if [ "$CLEAN_OUT_DIR" = true ]; then
  echo_and_do rm -rf "$OUT_DIR"
fi
echo_and_do mkdir -p "$UI_DIST_DIR"

if [ "$DEBUG_BUILD" = true ]; then
  echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=true"
else
  echo_and_do "$PROJECT_ROOT/tools/gn" gen "$OUT_DIR" --args="is_debug=false"
fi

echo_and_do "$PROJECT_ROOT/tools/ninja" -C "$OUT_DIR" ui

echo "Writing $UI_DIST_DIR/app.yaml"
cat<<EOF > "$UI_DIST_DIR/app.yaml"
runtime: python27
api_version: 1
threadsafe: yes
instance_class: B1
manual_scaling:
  instances: 1
handlers:
- url: /
  static_files: static/index.html
  upload: static/index.html
  secure: always
  redirect_http_response_code: 301
- url: /(.*[.]wasm)
  static_files: static/\1
  upload: static/(.*[.]wasm)
  mime_type: application/wasm
- url: /assets/(.*)
  static_files: static/assets/\1
  upload: static/assets/(.*)
  expiration: "1d"
- url: /(.*)
  static_files: static/\1
  upload: static/(.*)
EOF

echo_and_do ln -fs ../ui $UI_DIST_DIR/static

(
  echo_and_do cd "$UI_DIST_DIR";
  if [ "$DEPLOY_PROD" = true ]; then
    echo_and_do gcloud app deploy app.yaml --project perfetto-ui -v prod
  elif [ "$DEPLOY_STAGING" = true ]; then
    echo_and_do gcloud app deploy app.yaml --project perfetto-ui \
        -v staging --no-promote --stop-previous-version
  else
    echo_and_do gcloud app deploy app.yaml --project perfetto-ui \
        -v $USER --no-promote --stop-previous-version
  fi
)

if [ "$CLEAN_OUT_DIR" = true ]; then
  echo_and_do rm -rf "$OUT_DIR"
fi