Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 27f3dad

Browse files
authored
Merge pull request #147 from crabba/assets
Assets
2 parents a99614e + 5ad4e8e commit 27f3dad

File tree

5 files changed

+197
-52
lines changed

5 files changed

+197
-52
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ script:
2424
before_deploy:
2525

2626
- pip install awscli --upgrade
27-
- bash _scripts/configure-deploy.sh
27+
- bash _scripts/configure-deploy.sh --clobber
2828

2929
deploy:
3030
- provider: script
31-
script: bash _scripts/deploy.sh production
31+
script: bash _scripts/deploy.sh --public --verbose production
3232
skip_cleanup: true
3333
on:
3434
repo: aws-samples/aws-genomics-workflows
3535
branch: release
3636
tags: true
3737
- provider: script
38-
script: bash _scripts/deploy.sh test
38+
script: bash _scripts/deploy.sh --public --verbose test
3939
skip_cleanup: true
4040
on:
4141
repo: aws-samples/aws-genomics-workflows

_scripts/configure-deploy.sh

100644100755
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,60 @@
11
#!/bin/bash
22

3+
# Create a default ~/.aws/configure file for Travis testing
4+
35
set -e
46

57
# This script expects the following environment variable(s)
68
# ASSET_ROLE_ARN: the AWS role ARN that is used to publish assets
79

10+
usage() {
11+
cat <<EOM
12+
Usage:
13+
$(basename $0) [--clobber]
14+
15+
--clobber Overwrite ~/.aws/configure file without asking
16+
EOM
17+
}
18+
19+
CLOBBER=''
20+
PARAMS=""
21+
while (( "$#" )); do
22+
case "$1" in
23+
--clobber)
24+
CLOBBER=1
25+
shift
26+
;;
27+
--help)
28+
usage
29+
exit 0
30+
;;
31+
--) # end optional argument parsing
32+
shift
33+
break
34+
;;
35+
-*|--*=)
36+
echo "Error: unsupported argument $1" >&2
37+
exit 1
38+
;;
39+
*) # positional agruments
40+
PARAMS="$PARAMS $1"
41+
shift
42+
;;
43+
esac
44+
done
45+
eval set -- "$PARAMS"
46+
47+
if [ -z $CLOBBER ]; then
48+
while true; do
49+
read -p "Overwrite ~/.aws/config file [y/n]? " yn
50+
case $yn in
51+
[Yy]* ) CLOBBER=1; break;;
52+
[Nn]* ) echo "Exiting"; exit;;
53+
* ) echo "Please answer yes or no.";;
54+
esac
55+
done
56+
fi
57+
858
mkdir -p $HOME/.aws
959
cat << EOF > $HOME/.aws/config
1060
[default]

_scripts/deploy.sh

100644100755
Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
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

87
SITE_BUCKET=s3://docs.opendata.aws/genomics-workflows
98
ASSET_BUCKET=s3://aws-genomics-workflows
109
ASSET_STAGE=test
1110
ASSET_PROFILE=asset-publisher
1211
DEPLOY_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=''
1429
PARAMS=""
1530
while (( "$#" )); 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
4673
done
47-
4874
eval set -- "$PARAMS"
4975

5076
ASSET_STAGE=${1:-$ASSET_STAGE}
5177

78+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
79+
bash ${DIR}/make-dist.sh $VERBOSE
80+
5281
function 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

81112
function 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

151184
function 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

170219
echo "DEPLOYMENT STAGE: $ASSET_STAGE"
171220
case $ASSET_STAGE in

0 commit comments

Comments
 (0)