|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2018 Google Inc. All Rights Reserved. |
| 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 | + |
| 17 | +# This script deploys examples to GCP so they can be statically hosted. |
| 18 | +# |
| 19 | +# The script can either be used without arguments, which deploys all demos: |
| 20 | +# ./deploy.sh |
| 21 | +# Or you can pass a single argument specifying a single demo to deploy: |
| 22 | +# ./deploy.sh mnist |
| 23 | +# |
| 24 | +# This script assumes that a directory in this repo corresponds to an example. |
| 25 | +# |
| 26 | +# Example directories should have: |
| 27 | +# - package.json |
| 28 | +# - `yarn build` script which generates a dist/ folder in the example directory. |
| 29 | + |
| 30 | +if [ -z "$1" ] |
| 31 | + then |
| 32 | + EXAMPLES=$(ls -d */) |
| 33 | +else |
| 34 | + EXAMPLES=$1 |
| 35 | + if [ ! -d "$EXAMPLES" ]; then |
| 36 | + echo "Error: Could not find example $1" |
| 37 | + echo "Make sure the first argument to this script matches the example dir" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +fi |
| 41 | + |
| 42 | +for i in $EXAMPLES; do |
| 43 | + cd ${i} |
| 44 | + # Strip any trailing slashes. |
| 45 | + EXAMPLE_NAME=${i%/} |
| 46 | + |
| 47 | + echo "building ${EXAMPLE_NAME}..." |
| 48 | + yarn |
| 49 | + yarn build |
| 50 | + gsutil mkdir -p gs://tfjs-examples/$EXAMPLE_NAME |
| 51 | + gsutil mkdir -p gs://tfjs-examples/$EXAMPLE_NAME/dist |
| 52 | + gsutil -m cp dist/* gs://tfjs-examples/$EXAMPLE_NAME/dist |
| 53 | + cd .. |
| 54 | +done |
| 55 | + |
| 56 | +gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.html" |
| 57 | +gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.css" |
| 58 | +gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.js" |
0 commit comments