github.com/xsb/terraform@v0.6.13-0.20160314145438-fe415c2f09d7/website/scripts/deploy.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  PROJECT="terraform"
     5  PROJECT_URL="www.terraform.io"
     6  FASTLY_SERVICE_ID="7GrxRJP3PVBuqQbyxYQ0MV"
     7  
     8  # Ensure the proper AWS environment variables are set
     9  if [ -z "$AWS_ACCESS_KEY_ID" ]; then
    10    echo "Missing AWS_ACCESS_KEY_ID!"
    11    exit 1
    12  fi
    13  
    14  if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
    15    echo "Missing AWS_SECRET_ACCESS_KEY!"
    16    exit 1
    17  fi
    18  
    19  # Ensure the proper Fastly keys are set
    20  if [ -z "$FASTLY_API_KEY" ]; then
    21    echo "Missing FASTLY_API_KEY!"
    22    exit 1
    23  fi
    24  
    25  # Ensure we have s3cmd installed
    26  if ! command -v "s3cmd" >/dev/null 2>&1; then
    27    echo "Missing s3cmd!"
    28    exit 1
    29  fi
    30  
    31  # Get the parent directory of where this script is and change into our website
    32  # directory
    33  SOURCE="${BASH_SOURCE[0]}"
    34  while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
    35  DIR="$(cd -P "$( dirname "$SOURCE" )/.." && pwd)"
    36  
    37  # Delete any .DS_Store files for our OS X friends.
    38  find "$DIR" -type f -name '.DS_Store' -delete
    39  
    40  # Upload the files to S3 - we disable mime-type detection by the python library
    41  # and just guess from the file extension because it's surprisingly more
    42  # accurate, especially for CSS and javascript. We also tag the uploaded files
    43  # with the proper Surrogate-Key, which we will later purge in our API call to
    44  # Fastly.
    45  if [ -z "$NO_UPLOAD" ]; then
    46    echo "Uploading to S3..."
    47  
    48    # Check that the site has been built
    49    if [ ! -d "$DIR/build" ]; then
    50      echo "Missing compiled website! Run 'make build' to compile!"
    51      exit 1
    52    fi
    53  
    54    s3cmd \
    55      --quiet \
    56      --delete-removed \
    57      --guess-mime-type \
    58      --no-mime-magic \
    59      --acl-public \
    60      --recursive \
    61      --add-header="Cache-Control: max-age=31536000" \
    62      --add-header="x-amz-meta-surrogate-key: site-$PROJECT" \
    63      sync "$DIR/build/" "s3://hc-sites/$PROJECT/latest/"
    64  fi
    65  
    66  # Perform a soft-purge of the surrogate key.
    67  if [ -z "$NO_PURGE" ]; then
    68    echo "Purging Fastly cache..."
    69    curl \
    70      --fail \
    71      --silent \
    72      --output /dev/null \
    73      --request "POST" \
    74      --header "Accept: application/json" \
    75      --header "Fastly-Key: $FASTLY_API_KEY" \
    76      --header "Fastly-Soft-Purge: 1" \
    77      "https://api.fastly.com/service/$FASTLY_SERVICE_ID/purge/site-$PROJECT"
    78  fi
    79  
    80  # Warm the cache with recursive wget.
    81  if [ -z "$NO_WARM" ]; then
    82    echo "Warming Fastly cache..."
    83    wget \
    84      --recursive \
    85      --delete-after \
    86      --quiet \
    87      "https://$PROJECT_URL/"
    88  fi