11#! /bin/bash
22
3- set -e
3+ # deploy.sh: Create and deploy distribution artifacts
44
5- bash _scripts/make-dist.sh
6- mkdocs build
5+ set -e
76
87SITE_BUCKET=s3://docs.opendata.aws/genomics-workflows
98ASSET_BUCKET=s3://aws-genomics-workflows
109ASSET_STAGE=test
1110ASSET_PROFILE=asset-publisher
1211DEPLOY_REGION=us-east-1
1312
13+ usage () {
14+ cat << EOM
15+ Usage:
16+ $( basename $0 ) [--site-bucket BUCKET] [--asset-bucket BUCKET] [--asset-profile PROFILE] [--deploy-region REGION] [--public] [--verbose]
17+
18+ --site-bucket BUCKET Deploy documentation site to BUCKET
19+ --asset-bucket BUCKET Deploy assets to BUCKET
20+ --asset-profile PROFILE Use PROFILE for AWS CLI commands
21+ --deploy-region REGION Deploy in region REGION
22+ --public Deploy to public bucket with '--acl public-read' (Default false)
23+ --verbose Display more output
24+ EOM
25+ }
26+
27+ ACL_PUBLIC_READ=' '
28+ VERBOSE=' '
1429PARAMS=" "
1530while (( "$# " )) ; do
1631 case " $1 " in
@@ -30,6 +45,18 @@ while (( "$#" )); do
3045 DEPLOY_REGION=$2
3146 shift 2
3247 ;;
48+ --help)
49+ usage
50+ exit 0
51+ ;;
52+ --public)
53+ ACL_PUBLIC_READ=' --acl public-read'
54+ shift
55+ ;;
56+ --verbose)
57+ VERBOSE=' --verbose'
58+ shift
59+ ;;
3360 --) # end optional argument parsing
3461 shift
3562 break
@@ -44,11 +71,13 @@ while (( "$#" )); do
4471 ;;
4572 esac
4673done
47-
4874eval set -- " $PARAMS "
4975
5076ASSET_STAGE=${1:- $ASSET_STAGE }
5177
78+ DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
79+ bash ${DIR} /make-dist.sh $VERBOSE
80+
5281function s3_uri() {
5382 BUCKET=$1
5483 shift
@@ -68,20 +97,23 @@ function s3_sync() {
6897 echo " syncing ..."
6998 echo " from: $source "
7099 echo " to: $destination "
71- aws s3 sync \
100+ cmd= " aws s3 sync \
72101 --profile $ASSET_PROFILE \
73102 --region $DEPLOY_REGION \
74- --acl public-read \
103+ $ACL_PUBLIC_READ \
75104 --delete \
76105 --metadata commit=$( git rev-parse HEAD) \
77106 $source \
78- $destination
107+ $destination "
108+ echo $cmd
109+ eval $cmd
79110}
80111
81112function publish() {
82113 local source=$1
83114 local destination=$2
84115
116+ echo " publish(source: $source , destintation: $destination )"
85117 if [[ $USE_RELEASE_TAG && ! -z " $TRAVIS_TAG " ]]; then
86118 # create explicit pinned versions "latest" and TRAVIS_TAG
87119 # pin the TRAVIS_TAG first, since the files are modified inplace
@@ -125,11 +157,12 @@ function pin_version() {
125157 local version=$1
126158 local asset=$2
127159 local folder=$3
128-
160+
129161 echo " PINNING VERSIONS"
130162 for file in ` grep -irl " $asset # dist: pin_version" $folder ` ; do
131163 echo " pinning '$asset ' as '$version /$asset ' in '$file '"
132- sed -i' ' -e " s|$asset # dist: pin_version|$version /$asset #|g" $file
164+ sed -e " s|$asset # dist: pin_version|$version /$asset #|g" $file > $file .tmp
165+ mv $file .tmp $file
133166 done
134167}
135168
@@ -149,10 +182,19 @@ function templates() {
149182
150183
151184function site() {
185+ echo " building site"
186+ if [[ ! ` command -v mkdocs` ]]; then
187+ echo " requirement mkdocs not found. aborting"
188+ exit 1
189+ fi
190+ [ -z $VERBOSE ] && QUIET=' -q' || QUIET=' '
191+ mkdocs build $QUIET
192+
152193 echo " publishing site"
153194 aws s3 sync \
195+ --profile $ASSET_PROFILE \
154196 --region $DEPLOY_REGION \
155- --acl public-read \
197+ $ACL_PUBLIC_READ \
156198 --delete \
157199 --metadata commit=$( git rev-parse HEAD) \
158200 ./site \
@@ -166,6 +208,13 @@ function all() {
166208 site
167209}
168210
211+ # Add 's3://' when missing from bucket names
212+ for bucketname in ASSET_BUCKET SITE_BUCKET; do
213+ if [[ ! $( echo ${! bucketname} | grep ' s3://' ) ]]; then
214+ newname=" s3://${! bucketname} " ;
215+ eval $bucketname =\$ newname;
216+ fi
217+ done
169218
170219echo " DEPLOYMENT STAGE: $ASSET_STAGE "
171220case $ASSET_STAGE in
0 commit comments