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

Commit

Permalink
Merge pull request #147 from crabba/assets
Browse files Browse the repository at this point in the history
Assets
  • Loading branch information
wleepang authored Mar 24, 2021
2 parents a99614e + 5ad4e8e commit 27f3dad
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ script:
before_deploy:

- pip install awscli --upgrade
- bash _scripts/configure-deploy.sh
- bash _scripts/configure-deploy.sh --clobber

deploy:
- provider: script
script: bash _scripts/deploy.sh production
script: bash _scripts/deploy.sh --public --verbose production
skip_cleanup: true
on:
repo: aws-samples/aws-genomics-workflows
branch: release
tags: true
- provider: script
script: bash _scripts/deploy.sh test
script: bash _scripts/deploy.sh --public --verbose test
skip_cleanup: true
on:
repo: aws-samples/aws-genomics-workflows
Expand Down
50 changes: 50 additions & 0 deletions _scripts/configure-deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
#!/bin/bash

# Create a default ~/.aws/configure file for Travis testing

set -e

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

usage() {
cat <<EOM
Usage:
$(basename $0) [--clobber]
--clobber Overwrite ~/.aws/configure file without asking
EOM
}

CLOBBER=''
PARAMS=""
while (( "$#" )); do
case "$1" in
--clobber)
CLOBBER=1
shift
;;
--help)
usage
exit 0
;;
--) # end optional argument parsing
shift
break
;;
-*|--*=)
echo "Error: unsupported argument $1" >&2
exit 1
;;
*) # positional agruments
PARAMS="$PARAMS $1"
shift
;;
esac
done
eval set -- "$PARAMS"

if [ -z $CLOBBER ]; then
while true; do
read -p "Overwrite ~/.aws/config file [y/n]? " yn
case $yn in
[Yy]* ) CLOBBER=1; break;;
[Nn]* ) echo "Exiting"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi

mkdir -p $HOME/.aws
cat << EOF > $HOME/.aws/config
[default]
Expand Down
69 changes: 59 additions & 10 deletions _scripts/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
#!/bin/bash

set -e
# deploy.sh: Create and deploy distribution artifacts

bash _scripts/make-dist.sh
mkdocs build
set -e

SITE_BUCKET=s3://docs.opendata.aws/genomics-workflows
ASSET_BUCKET=s3://aws-genomics-workflows
ASSET_STAGE=test
ASSET_PROFILE=asset-publisher
DEPLOY_REGION=us-east-1

usage() {
cat <<EOM
Usage:
$(basename $0) [--site-bucket BUCKET] [--asset-bucket BUCKET] [--asset-profile PROFILE] [--deploy-region REGION] [--public] [--verbose]
--site-bucket BUCKET Deploy documentation site to BUCKET
--asset-bucket BUCKET Deploy assets to BUCKET
--asset-profile PROFILE Use PROFILE for AWS CLI commands
--deploy-region REGION Deploy in region REGION
--public Deploy to public bucket with '--acl public-read' (Default false)
--verbose Display more output
EOM
}

ACL_PUBLIC_READ=''
VERBOSE=''
PARAMS=""
while (( "$#" )); do
case "$1" in
Expand All @@ -30,6 +45,18 @@ while (( "$#" )); do
DEPLOY_REGION=$2
shift 2
;;
--help)
usage
exit 0
;;
--public)
ACL_PUBLIC_READ='--acl public-read'
shift
;;
--verbose)
VERBOSE='--verbose'
shift
;;
--) # end optional argument parsing
shift
break
Expand All @@ -44,11 +71,13 @@ while (( "$#" )); do
;;
esac
done

eval set -- "$PARAMS"

ASSET_STAGE=${1:-$ASSET_STAGE}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
bash ${DIR}/make-dist.sh $VERBOSE

function s3_uri() {
BUCKET=$1
shift
Expand All @@ -68,20 +97,23 @@ function s3_sync() {
echo "syncing ..."
echo " from: $source"
echo " to: $destination"
aws s3 sync \
cmd="aws s3 sync \
--profile $ASSET_PROFILE \
--region $DEPLOY_REGION \
--acl public-read \
$ACL_PUBLIC_READ \
--delete \
--metadata commit=$(git rev-parse HEAD) \
$source \
$destination
$destination"
echo $cmd
eval $cmd
}

function publish() {
local source=$1
local destination=$2

echo "publish(source: $source, destintation: $destination)"
if [[ $USE_RELEASE_TAG && ! -z "$TRAVIS_TAG" ]]; then
# create explicit pinned versions "latest" and TRAVIS_TAG
# pin the TRAVIS_TAG first, since the files are modified inplace
Expand Down Expand Up @@ -125,11 +157,12 @@ function pin_version() {
local version=$1
local asset=$2
local folder=$3

echo "PINNING VERSIONS"
for file in `grep -irl "$asset # dist: pin_version" $folder`; do
echo "pinning '$asset' as '$version/$asset' in '$file'"
sed -i'' -e "s|$asset # dist: pin_version|$version/$asset #|g" $file
sed -e "s|$asset # dist: pin_version|$version/$asset #|g" $file > $file.tmp
mv $file.tmp $file
done
}

Expand All @@ -149,10 +182,19 @@ function templates() {


function site() {
echo "building site"
if [[ ! `command -v mkdocs` ]]; then
echo "requirement mkdocs not found. aborting"
exit 1
fi
[ -z $VERBOSE ] && QUIET='-q' || QUIET=''
mkdocs build $QUIET

echo "publishing site"
aws s3 sync \
--profile $ASSET_PROFILE \
--region $DEPLOY_REGION \
--acl public-read \
$ACL_PUBLIC_READ \
--delete \
--metadata commit=$(git rev-parse HEAD) \
./site \
Expand All @@ -166,6 +208,13 @@ function all() {
site
}

# Add 's3://' when missing from bucket names
for bucketname in ASSET_BUCKET SITE_BUCKET; do
if [[ ! $(echo ${!bucketname} | grep 's3://') ]]; then
newname="s3://${!bucketname}";
eval $bucketname=\$newname;
fi
done

echo "DEPLOYMENT STAGE: $ASSET_STAGE"
case $ASSET_STAGE in
Expand Down
Loading

0 comments on commit 27f3dad

Please sign in to comment.