-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
109 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,93 @@ | ||
#!/bin/sh | ||
SRC_DIR='dist/travis' | ||
DISTRIBUTION_ID='E6OL76123FRO6' | ||
|
||
# this will deploy the current public folder to a subfolder in the s3 bucket | ||
# the subfolder is the name of the TRAVIS_BRANCH | ||
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then | ||
echo "skipping deploy to S3: this is a pull request" | ||
exit 0 | ||
#!/bin/bash | ||
|
||
# Follow instructions in this guide to setup an S3 & Cloudfront distribution: | ||
# https://docs.google.com/document/d/1EacCSUhaHXaL8ll8xjcd4svyguEO-ipf5aF980-_q8E | ||
|
||
# Typically this is the Project name. | ||
# The trailing slash is important | ||
# Can be set to an empty string for working at the top level of the bucket | ||
S3_BUCKET_PREFIX='codap-dev/' | ||
# AWS CloudFront distribution domain | ||
DISTRIBUTION_DOMAIN='codap-dev.concord.org' | ||
# name of branch to deploy to root of site | ||
ROOT_BRANCH='production' | ||
# Bucket to deploy to, typically this is 'model-resources', but some projects | ||
# have their own buckets | ||
S3_BUCKET='models-resources' | ||
# location of built files | ||
SRC_DIR='dist/ci' | ||
|
||
# exit when any command fails | ||
set -e | ||
|
||
# keep track of the last executed command | ||
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | ||
# echo an error message before exiting | ||
trap 'echo "\"${last_command}\" command exited with code $?."' EXIT | ||
|
||
# extract current TAG if present | ||
# the 2> is to prevent error messages when no match is found | ||
# the || echo prevents script exit when it doesn't match | ||
CURRENT_TAG=`git describe --tags --exact-match $GITHUB_SHA 2> /dev/null || echo ''` | ||
|
||
# Extract the branch or tag name from the GITHUB_REF | ||
# it should either be: refs/head/branch-name or | ||
# or refs/tags/v1.2.3 | ||
# since we ought to know if this is a branch or tag based on the ref | ||
# we could simplify the CURRENT_TAG approach above | ||
BRANCH_OR_TAG=${GITHUB_REF#refs/*/} | ||
echo branch or tag: $BRANCH_OR_TAG | ||
|
||
# strip PT ID from branch name for branch builds | ||
DEPLOY_DIR_NAME=$BRANCH_OR_TAG | ||
PT_PREFIX_REGEX="^([0-9]{8,}-)(.+)$" | ||
PT_SUFFIX_REGEX="^(.+)(-[0-9]{8,})$" | ||
if [[ $DEPLOY_DIR_NAME =~ $PT_PREFIX_REGEX ]]; then | ||
DEPLOY_DIR_NAME=${BASH_REMATCH[2]} | ||
fi | ||
if [[ $DEPLOY_DIR_NAME =~ $PT_SUFFIX_REGEX ]]; then | ||
DEPLOY_DIR_NAME=${BASH_REMATCH[1]} | ||
fi | ||
|
||
# tagged builds deploy to /version/TAG_NAME | ||
if [ "$BRANCH_OR_TAG" = "$CURRENT_TAG" ]; then | ||
mkdir -p _site/version | ||
S3_DEPLOY_DIR="version/$BRANCH_OR_TAG" | ||
DEPLOY_DEST="_site/$S3_DEPLOY_DIR" | ||
# in this case we are going to deploy this code to a subfolder of version | ||
# So ignore everything except this folder. | ||
# Currently this only escapes `.` | ||
S3_DEPLOY_DIR_ESCAPED=$(sed 's/[.]/[&]/g;' <<<"$S3_DEPLOY_DIR") | ||
IGNORE_ON_SERVER="^(?!$S3_BUCKET_PREFIX$S3_DEPLOY_DIR_ESCAPED/)" | ||
|
||
# root branch builds deploy to root of site | ||
elif [ "$BRANCH_OR_TAG" = "$ROOT_BRANCH" ]; then | ||
DEPLOY_DEST="_site" | ||
# in this case we are going to deploy this branch to the top level | ||
# so we need to ignore the version and branch folders | ||
IGNORE_ON_SERVER="^$S3_BUCKET_PREFIX(version/|branch/)" | ||
|
||
if [ "$TRAVIS_BRANCH" = 'master' ]; then | ||
mv $SRC_DIR _site | ||
INVAL_PATH="/index.html" | ||
# branch builds deploy to /branch/BRANCH_NAME | ||
else | ||
# the 2> is to prevent error messages when no match is found | ||
CURRENT_TAG=`git describe --tags --exact-match $TRAVIS_COMMIT 2> /dev/null` | ||
if [ "$TRAVIS_BRANCH" = "$CURRENT_TAG" ]; then | ||
echo "skipping deploy to S3: this is a release tag" | ||
exit 0 | ||
else | ||
# this is a branch build | ||
mkdir -p _site/branch | ||
DEPLOY_DIR=branch/$TRAVIS_BRANCH | ||
INVAL_PATH="/branch/$TRAVIS_BRANCH/index.html" | ||
fi | ||
mv $SRC_DIR _site/$DEPLOY_DIR | ||
export DEPLOY_DIR | ||
mkdir -p _site/branch | ||
S3_DEPLOY_DIR="branch/$DEPLOY_DIR_NAME" | ||
DEPLOY_DEST="_site/$S3_DEPLOY_DIR" | ||
# in this case we are going to deploy this code to a subfolder of branch | ||
# So ignore everything except this folder. | ||
# Currently this only escapes `.` | ||
S3_DEPLOY_DIR_ESCAPED=$(sed 's/[.]/[&]/g;' <<<"$S3_DEPLOY_DIR") | ||
IGNORE_ON_SERVER="^(?!$S3_BUCKET_PREFIX$S3_DEPLOY_DIR_ESCAPED/)" | ||
fi | ||
s3_website push --site _site | ||
# explicit CloudFront invalidation to workaround s3_website gem invalidation bug | ||
# with origin path (https://github.com/laurilehmijoki/s3_website/issues/207). | ||
# aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $INVAL_PATH | ||
|
||
# used by s3_website.yml | ||
export S3_BUCKET_PREFIX | ||
export IGNORE_ON_SERVER | ||
export DISTRIBUTION_DOMAIN | ||
export S3_BUCKET | ||
|
||
# copy files to destination | ||
mv $SRC_DIR $DEPLOY_DEST | ||
|
||
# deploy the site contents; increase memory for s3_website gem | ||
echo Deploying "$BRANCH_OR_TAG" to "$S3_BUCKET:$S3_BUCKET_PREFIX$S3_DEPLOY_DIR"... | ||
JAVA_TOOL_OPTIONS="-Xms1g -Xmx2g" s3_website push --site _site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,15 @@ | ||
s3_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> | ||
s3_secret: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> | ||
s3_bucket: models-resources | ||
s3_key_prefix: codap-dev | ||
s3_bucket: <%= ENV['S3_BUCKET'] %> | ||
# only add the s3_key_prefix if there is one | ||
<% if ENV['S3_BUCKET_PREFIX'] != '' %> | ||
# Everywhere else the s3 prefix needs a trailing slash | ||
# However s3_website config doesn't need one | ||
s3_key_prefix: <%= ENV['S3_BUCKET_PREFIX'].sub(/\\/$/, '') %> | ||
<% end %> | ||
s3_endpoint: us-east-1 | ||
gzip: true | ||
|
||
cloudfront_distribution_id: E6OL76123FRO6 | ||
cloudfront_invalidate_root: true | ||
cloudfront_wildcard_invalidation: true | ||
|
||
<% if ENV['TRAVIS_BRANCH'] == 'master' %> | ||
# in this case we are going to deploy this branch to the top level of the domain | ||
# so we need to ignore the version and branch folders | ||
ignore_on_server: ^codap-dev/(version/|branch/) | ||
<% else %> | ||
# in this case we are going to deploy this code to a subfolder of either the branch | ||
# or version folder. So ignore everything except this folder. | ||
ignore_on_server: ^(?!codap-dev/<%= Regexp.escape(ENV['DEPLOY_DIR']) %>/) | ||
<% end %> | ||
ignore_on_server: <%= ENV['IGNORE_ON_SERVER'] %> | ||
max_age: | ||
"codap-dev/*": 600 # 10 minutes | ||
"codap-dev/version/*": 31536000 # 1 year | ||
"codap-dev/branch/*": 0 | ||
|
||
cloudfront_distribution_config: | ||
aliases: | ||
quantity: 1 | ||
items: | ||
- codap-dev.concord.org | ||
"<%= ENV['S3_BUCKET_PREFIX'] %>*": 600 # 10 minutes | ||
"<%= ENV['S3_BUCKET_PREFIX'] %>version/*": 31536000 # 1 year | ||
"<%= ENV['S3_BUCKET_PREFIX'] %>branch/*": 0 |