|
| 1 | +# Copyright 2023 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +#!/bin/bash |
| 16 | + |
| 17 | +PROJECT_ID=$(gcloud config get-value project) |
| 18 | + |
| 19 | +SCRIPT_DIR=$(dirname "$0") |
| 20 | +cd $SCRIPT_DIR/.. |
| 21 | + |
| 22 | +# build container |
| 23 | +export DOCKER_BUILDKIT=1 |
| 24 | +IMAGE_PATH="gcr.io/$PROJECT_ID/python-bigtable-benchmark" |
| 25 | +docker build -t $IMAGE_PATH -f $SCRIPT_DIR/Dockerfile . |
| 26 | +docker push $IMAGE_PATH |
| 27 | + |
| 28 | +# deploy to GCE |
| 29 | +INSTANCE_NAME="python-bigtable-benchmark-$(date +%s)" |
| 30 | +ZONE=us-central1-b |
| 31 | +gcloud compute instances create-with-container $INSTANCE_NAME \ |
| 32 | + --container-image=$IMAGE_PATH \ |
| 33 | + --machine-type=n1-standard-4 \ |
| 34 | + --zone=$ZONE \ |
| 35 | + --scopes=cloud-platform \ |
| 36 | + --container-restart-policy=never |
| 37 | + |
| 38 | +# find container id |
| 39 | +echo "waiting for container to start..." |
| 40 | +while [[ -z "$CONTAINER_ID" ]]; do |
| 41 | + sleep 1 |
| 42 | + CONTAINER_ID=$(gcloud compute instances get-serial-port-output $INSTANCE_NAME --zone $ZONE 2>/dev/null | grep "Starting a container with ID" | awk '{print $NF}') |
| 43 | +done |
| 44 | +echo "found container id: $CONTAINER_ID" |
| 45 | + |
| 46 | +# print logs |
| 47 | +gcloud beta logging tail "$CONTAINER_ID" --format='value(jsonPayload.message)' |
0 commit comments