1 #!/usr/bin/env bash 2 # Copyright 2016 The TensorFlow Authors. 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 # Driver script for TensorFlow-GCS smoke test. 18 # 19 # Usage: 20 # gcs_smoke.sh <WHL_URL> <GCLOUD_JSON_KEY_PATH> <GCS_BUCKET_URL> 21 # 22 # Input arguments: 23 # WHL_URL: URL to the TensorFlow wheel file to use in this test. 24 # GCLOUD_KEY_JSON_PATH: Path to the Google Cloud JSON key file. 25 # See https://cloud.google.com/storage/docs/authentication for details. 26 # 27 # GCS_BUCKET_URL: URL to the GCS bucket for testing. 28 # E.g., gs://my-gcs-bucket/test-directory 29 30 # Configurations 31 DOCKER_IMG="tensorflow-gcs-test" 32 33 print_usage() { 34 echo "Usage: gcs_smoke.sh <GCLOUD_JSON_KEY_PATH> <GCS_BUCKET_URL>" 35 echo "" 36 } 37 38 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 39 source "${SCRIPT_DIR}/../ci_build/builds/builds_common.sh" 40 41 # Check input arguments 42 WHL_URL=$1 43 GCLOUD_JSON_KEY_PATH=$2 44 GCS_BUCKET_URL=$3 45 if [[ -z "${GCLOUD_JSON_KEY_PATH}" ]]; then 46 print_usage 47 die "ERROR: Command-line argument GCLOUD_JSON_KEY_PATH is not supplied" 48 fi 49 if [[ -z "${GCS_BUCKET_URL}" ]]; then 50 print_usage 51 die "ERROR: Command-line argument GCS_BUCKET_URL is not supplied" 52 fi 53 54 if [[ ! -f "${GCLOUD_JSON_KEY_PATH}" ]]; then 55 die "ERROR: Path to Google Cloud JSON key file is invalid: \""\ 56 "${GCLOUD_JSON_KEY_PATH}\"" 57 fi 58 59 # Create temporary directory for docker build 60 BUILD_DIR=$(mktemp -d) 61 echo "" 62 echo "Using whl file URL: ${WHL_URL}" 63 echo "Building in temporary directory: ${BUILD_DIR}" 64 65 cp -r ${SCRIPT_DIR}/* "${BUILD_DIR}"/ || \ 66 die "Failed to copy files to ${BUILD_DIR}" 67 68 DOCKERFILE="${BUILD_DIR}/Dockerfile" 69 if [[ ! -f "${DOCKERFILE}" ]]; then 70 die "ERROR: Cannot find Dockerfile at expected path ${DOCKERFILE}" 71 fi 72 73 # Download whl file into the build context directory. 74 wget -P "${BUILD_DIR}" ${WHL_URL} || \ 75 die "Failed to download tensorflow whl file from URL: ${WHL_URL}" 76 77 # Build the docker image for testing 78 docker build --no-cache \ 79 -f "${DOCKERFILE}" -t "${DOCKER_IMG}" "${BUILD_DIR}" || \ 80 die "FAIL: Failed to build docker image for testing" 81 82 # Clean up docker build context directory. 83 rm -rf "${BUILD_DIR}" 84 85 # Run the docker image with the GCS key file mapped and the gcloud-required 86 # environment variables set. 87 docker run --rm \ 88 -v ${GCLOUD_JSON_KEY_PATH}:/gcloud-key.json \ 89 -e "GOOGLE_APPLICATION_CREDENTIALS=/gcloud-key.json" \ 90 "${DOCKER_IMG}" \ 91 /gcs-smoke/gcs_smoke_wrapper.sh "${GCS_BUCKET_URL}" 92