From d4658db6562002c28a8073c4aa0262efb3e44833 Mon Sep 17 00:00:00 2001 From: Andrew Crabb Date: Fri, 19 Mar 2021 19:49:38 -0400 Subject: [PATCH 1/5] Use absolute paths, add verbose flag --- _scripts/deploy.sh | 6 +-- _scripts/make-dist.sh | 115 ++++++++++++++++++++++++++++-------------- 2 files changed, 81 insertions(+), 40 deletions(-) mode change 100644 => 100755 _scripts/deploy.sh diff --git a/_scripts/deploy.sh b/_scripts/deploy.sh old mode 100644 new mode 100755 index 199455dd4..a0644e662 --- a/_scripts/deploy.sh +++ b/_scripts/deploy.sh @@ -2,9 +2,10 @@ set -e -bash _scripts/make-dist.sh +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +bash ${DIR}/make-dist.sh mkdocs build - +exit SITE_BUCKET=s3://docs.opendata.aws/genomics-workflows ASSET_BUCKET=s3://aws-genomics-workflows ASSET_STAGE=test @@ -44,7 +45,6 @@ while (( "$#" )); do ;; esac done - eval set -- "$PARAMS" ASSET_STAGE=${1:-$ASSET_STAGE} diff --git a/_scripts/make-dist.sh b/_scripts/make-dist.sh index d32539adb..015fc9f81 100755 --- a/_scripts/make-dist.sh +++ b/_scripts/make-dist.sh @@ -1,5 +1,39 @@ #!/bin/bash +# make-dist.sh: Create distribution artifacts +# This script is expected to be in a subdirectory of the top-level directory +# It accesses the subdirectory 'src', and creates a subdirectory 'dist', in the top-level directory: +# . +# |-_scripts +# |---make-dist.sh +# |-dist +# |-src + + +VERBOSE="" +PARAMS="" +while (( "$#" )); do + case "$1" in + --verbose) + VERBOSE='-v' + shift + ;; + --) # 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" + echo "checking for dependencies" DEPENDENCIES=$(cat < /dev/null && pwd )" +INSTALL_DIR=`dirname $DIR` +SOURCE_PATH=$INSTALL_DIR/src +DIST_PATH=$INSTALL_DIR/dist -TEMP_PATH=${DIST_PATH}/tmp -ARTIFACT_PATH=${DIST_PATH}/artifacts -TEMPLATES_PATH=${DIST_PATH}/templates +TEMP_PATH=$DIST_PATH/tmp +ARTIFACT_PATH=$DIST_PATH/artifacts +TEMPLATES_PATH=$DIST_PATH/templates if [ ! -d $DIST_PATH ]; then mkdir -p $DIST_PATH @@ -39,11 +75,10 @@ fi cd $DIST_PATH # clean up previous dist build -echo "removing previous dist" -rm -rf ./* +echo "removing previous dist in $DIST_PATH" +[ ! -z $DIR ] && rm -rf $DIST_PATH/* -for d in $TEMP_PATH $ARTIFACT_PATH $TEMPLATES_PATH; -do +for d in $TEMP_PATH $ARTIFACT_PATH $TEMPLATES_PATH; do if [ ! -d $d ]; then echo "creating $d" @@ -55,69 +90,75 @@ done # combines the latest release of amazon-ebs-autoscale with compatibility shim # scripts in ./ebs-autoscale/ echo "packaging amazon-ebs-autoscale" -cd ${TEMP_PATH} +cd $TEMP_PATH EBS_AUTOSCALE_VERSION=$(curl --silent "https://api.github.com/repos/awslabs/amazon-ebs-autoscale/releases/latest" | jq -r .tag_name) curl --silent -L \ "https://github.com/awslabs/amazon-ebs-autoscale/archive/${EBS_AUTOSCALE_VERSION}.tar.gz" \ -o ./amazon-ebs-autoscale.tar.gz -tar -xzvf ./amazon-ebs-autoscale.tar.gz +echo "copying `tar -tzf ./amazon-ebs-autoscale.tar.gz | wc -l` files from ebs-autoscale $EBS_AUTOSCALE_VERSION into tmp/amazon-ebs-autoscale/" +tar $VERBOSE -xzf ./amazon-ebs-autoscale.tar.gz mv ./amazon-ebs-autoscale*/ ./amazon-ebs-autoscale echo $EBS_AUTOSCALE_VERSION > ./amazon-ebs-autoscale/VERSION -cp -Rfv $SOURCE_PATH/ebs-autoscale . -cp -Rfv ./amazon-ebs-autoscale/* ./ebs-autoscale/ - -tar -czvf ${ARTIFACT_PATH}/aws-ebs-autoscale.tgz ./ebs-autoscale/ +echo "copying src/ebs-autoscale with `find $SOURCE_PATH/ebs-autoscale/ -type f | wc -l` files to tmp/" +cp $VERBOSE -Rf $SOURCE_PATH/ebs-autoscale . +echo "copying `find amazon-ebs-autoscale -type f | wc -l` files from tmp/amazon-ebs-autoscale/ to tmp/ebs-autoscale/" +cp $VERBOSE -Rf ./amazon-ebs-autoscale/* ./ebs-autoscale/ +echo "creating artifacts/aws-ebs-autoscale.tgz with `find ./ebs-autoscale/ -type f | wc -l` files from tmp/ebs-autoscale/" +tar $VERBOSE -czf $ARTIFACT_PATH/aws-ebs-autoscale.tgz ./ebs-autoscale/ # add a copy of the release tarball for naming consistency -tar -czvf ${ARTIFACT_PATH}/amazon-ebs-autoscale.tgz ./amazon-ebs-autoscale +echo "creating artifacts/amazon-ebs-autoscale.tgz with `find ./amazon-ebs-autoscale/ -type f | wc -l` files from tmp/amazon-ebs-autoscale/" +tar $VERBOSE -czf $ARTIFACT_PATH/amazon-ebs-autoscale.tgz ./amazon-ebs-autoscale # add a retrieval script -cp -vf ${SOURCE_PATH}/ebs-autoscale/get-amazon-ebs-autoscale.sh ${ARTIFACT_PATH} +cp $VERBOSE -f $SOURCE_PATH/ebs-autoscale/get-amazon-ebs-autoscale.sh $ARTIFACT_PATH # package crhelper lambda(s) -cd ${SOURCE_PATH}/lambda +cd $SOURCE_PATH/lambda for fn in `ls .`; do echo "packaging crhelper lambda $fn" - mkdir -p ${TEMP_PATH}/lambda/$fn - cp -Rv ${SOURCE_PATH}/lambda/$fn/. ${TEMP_PATH}/lambda/$fn - - cd ${TEMP_PATH}/lambda/$fn - pip install -t . -r requirements.txt - zip -r -v $ARTIFACT_PATH/lambda-$fn.zip . + mkdir -p $TEMP_PATH/lambda/$fn + cp $VERBOSE -R $SOURCE_PATH/lambda/$fn/. $TEMP_PATH/lambda/$fn + + cd $TEMP_PATH/lambda/$fn + [ -z $VERBOSE ] && P_QUIET='--quiet' || P_QUIET='' + pip $P_QUIET install -t . -r requirements.txt + echo "creating artifacts/lambda-${fn}.zip with `find . -type f | wc -l` files" + [ -z $VERBOSE ] && Z_QUIET='-q' || Z_QUIET='' + zip $Z_QUIET -r $ARTIFACT_PATH/lambda-$fn.zip . done - # package ecs-additions echo "packaging ecs-additions" -cd ${TEMP_PATH} -mkdir -p ${TEMP_PATH}/ecs-additions -cp -Rv ${SOURCE_PATH}/ecs-additions/. ${TEMP_PATH}/ecs-additions +cd $TEMP_PATH +mkdir -p $TEMP_PATH/ecs-additions +cp $VERBOSE -R $SOURCE_PATH/ecs-additions/. $TEMP_PATH/ecs-additions # add the amazon-ebs-autoscale retrieval script to additions -cp -v ${SOURCE_PATH}/ebs-autoscale/get-amazon-ebs-autoscale.sh ${TEMP_PATH}/ecs-additions +cp $VERBOSE $SOURCE_PATH/ebs-autoscale/get-amazon-ebs-autoscale.sh $TEMP_PATH/ecs-additions # keep tarball for backwards compatibilty -cd ${TEMP_PATH} -tar -czvf ${ARTIFACT_PATH}/aws-ecs-additions.tgz ./ecs-additions/ +cd $TEMP_PATH +tar $VERBOSE -czf $ARTIFACT_PATH/aws-ecs-additions.tgz ./ecs-additions/ # zip file for codecommit repo -cd ${TEMP_PATH}/ecs-additions/ -zip -r -v ${ARTIFACT_PATH}/aws-ecs-additions.zip ./* +cd $TEMP_PATH/ecs-additions/ +zip $Z_QUIET -r $ARTIFACT_PATH/aws-ecs-additions.zip ./* # package container code -echo "packaging container definitions" +echo "packaging container definitions with `find $SOURCE_PATH/containers -type f | wc -l` files" cd $SOURCE_PATH/containers -zip -r -v $ARTIFACT_PATH/containers.zip ./* +zip $Z_QUIET -r $ARTIFACT_PATH/containers.zip ./* # add templates to dist -echo "copying cloudformation templates" -cp -Rv $SOURCE_PATH/templates/. $TEMPLATES_PATH +echo "copying `find $SOURCE_PATH/templates/ -type f | wc -l` cloudformation templates" +cp $VERBOSE -R $SOURCE_PATH/templates/. $TEMPLATES_PATH # cleanup From 984b311256803fb839137f0951b92a603948ad84 Mon Sep 17 00:00:00 2001 From: Andrew Crabb Date: Sun, 21 Mar 2021 19:32:38 -0400 Subject: [PATCH 2/5] Add verbose flag, use absolute paths --- _scripts/deploy.sh | 37 ++++++++++++++++++++++++++++++------- _scripts/make-dist.sh | 18 +++++++++--------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/_scripts/deploy.sh b/_scripts/deploy.sh index a0644e662..e03003e45 100755 --- a/_scripts/deploy.sh +++ b/_scripts/deploy.sh @@ -1,17 +1,16 @@ #!/bin/bash +# deploy.sh: Create and deploy distribution artifacts + set -e -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -bash ${DIR}/make-dist.sh -mkdocs build -exit 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 +VERBOSE='' PARAMS="" while (( "$#" )); do case "$1" in @@ -31,6 +30,10 @@ while (( "$#" )); do DEPLOY_REGION=$2 shift 2 ;; + --verbose) + VERBOSE='--verbose' + shift + ;; --) # end optional argument parsing shift break @@ -49,6 +52,9 @@ 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 @@ -68,20 +74,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 \ --delete \ --metadata commit=$(git rev-parse HEAD) \ $source \ - $destination + $destination" + echo $cmd + eval $cmd + exit } 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 @@ -149,6 +158,13 @@ function templates() { function site() { + echo "building site" + if [[ ! `command -v mkdocs` ]]; then + echo "requirement mkdocs not found. aborting" + exit 1 + fi + mkdocs build + echo "publishing site" aws s3 sync \ --region $DEPLOY_REGION \ @@ -166,6 +182,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 diff --git a/_scripts/make-dist.sh b/_scripts/make-dist.sh index 015fc9f81..d871adb82 100755 --- a/_scripts/make-dist.sh +++ b/_scripts/make-dist.sh @@ -60,7 +60,7 @@ set -e CWD=`pwd` DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -INSTALL_DIR=`dirname $DIR` +INSTALL_DIR=$(dirname $DIR) SOURCE_PATH=$INSTALL_DIR/src DIST_PATH=$INSTALL_DIR/dist @@ -97,20 +97,20 @@ curl --silent -L \ "https://github.com/awslabs/amazon-ebs-autoscale/archive/${EBS_AUTOSCALE_VERSION}.tar.gz" \ -o ./amazon-ebs-autoscale.tar.gz -echo "copying `tar -tzf ./amazon-ebs-autoscale.tar.gz | wc -l` files from ebs-autoscale $EBS_AUTOSCALE_VERSION into tmp/amazon-ebs-autoscale/" +echo "copying $(tar -tzf ./amazon-ebs-autoscale.tar.gz | wc -l) files from ebs-autoscale $EBS_AUTOSCALE_VERSION into tmp/amazon-ebs-autoscale/" tar $VERBOSE -xzf ./amazon-ebs-autoscale.tar.gz mv ./amazon-ebs-autoscale*/ ./amazon-ebs-autoscale echo $EBS_AUTOSCALE_VERSION > ./amazon-ebs-autoscale/VERSION -echo "copying src/ebs-autoscale with `find $SOURCE_PATH/ebs-autoscale/ -type f | wc -l` files to tmp/" +echo "copying src/ebs-autoscale with $(find $SOURCE_PATH/ebs-autoscale/ -type f | wc -l) files to tmp/" cp $VERBOSE -Rf $SOURCE_PATH/ebs-autoscale . -echo "copying `find amazon-ebs-autoscale -type f | wc -l` files from tmp/amazon-ebs-autoscale/ to tmp/ebs-autoscale/" +echo "copying $(find amazon-ebs-autoscale -type f | wc -l) files from tmp/amazon-ebs-autoscale/ to tmp/ebs-autoscale/" cp $VERBOSE -Rf ./amazon-ebs-autoscale/* ./ebs-autoscale/ -echo "creating artifacts/aws-ebs-autoscale.tgz with `find ./ebs-autoscale/ -type f | wc -l` files from tmp/ebs-autoscale/" +echo "creating artifacts/aws-ebs-autoscale.tgz with $(find ./ebs-autoscale/ -type f | wc -l) files from tmp/ebs-autoscale/" tar $VERBOSE -czf $ARTIFACT_PATH/aws-ebs-autoscale.tgz ./ebs-autoscale/ # add a copy of the release tarball for naming consistency -echo "creating artifacts/amazon-ebs-autoscale.tgz with `find ./amazon-ebs-autoscale/ -type f | wc -l` files from tmp/amazon-ebs-autoscale/" +echo "creating artifacts/amazon-ebs-autoscale.tgz with $(find ./amazon-ebs-autoscale/ -type f | wc -l) files from tmp/amazon-ebs-autoscale/" tar $VERBOSE -czf $ARTIFACT_PATH/amazon-ebs-autoscale.tgz ./amazon-ebs-autoscale # add a retrieval script @@ -126,7 +126,7 @@ for fn in `ls .`; do cd $TEMP_PATH/lambda/$fn [ -z $VERBOSE ] && P_QUIET='--quiet' || P_QUIET='' pip $P_QUIET install -t . -r requirements.txt - echo "creating artifacts/lambda-${fn}.zip with `find . -type f | wc -l` files" + echo "creating artifacts/lambda-${fn}.zip with $(find . -type f | wc -l) files" [ -z $VERBOSE ] && Z_QUIET='-q' || Z_QUIET='' zip $Z_QUIET -r $ARTIFACT_PATH/lambda-$fn.zip . done @@ -151,13 +151,13 @@ zip $Z_QUIET -r $ARTIFACT_PATH/aws-ecs-additions.zip ./* # package container code -echo "packaging container definitions with `find $SOURCE_PATH/containers -type f | wc -l` files" +echo "packaging container definitions with $(find $SOURCE_PATH/containers -type f | wc -l) files" cd $SOURCE_PATH/containers zip $Z_QUIET -r $ARTIFACT_PATH/containers.zip ./* # add templates to dist -echo "copying `find $SOURCE_PATH/templates/ -type f | wc -l` cloudformation templates" +echo "copying $(find $SOURCE_PATH/templates/ -type f | wc -l) cloudformation templates" cp $VERBOSE -R $SOURCE_PATH/templates/. $TEMPLATES_PATH From e1a1cc6cec7aab14fbf4ef069fa8ef65fd8855e3 Mon Sep 17 00:00:00 2001 From: Andrew Crabb Date: Mon, 22 Mar 2021 11:57:30 -0400 Subject: [PATCH 3/5] Use --verbose when calling deploy.sh from travis --- .travis.yml | 4 ++-- _scripts/deploy.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a29c5928..94add2e5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,14 +28,14 @@ before_deploy: deploy: - provider: script - script: bash _scripts/deploy.sh production + script: bash _scripts/deploy.sh --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 --verbose test skip_cleanup: true on: repo: aws-samples/aws-genomics-workflows diff --git a/_scripts/deploy.sh b/_scripts/deploy.sh index e03003e45..4e40237c6 100755 --- a/_scripts/deploy.sh +++ b/_scripts/deploy.sh @@ -77,6 +77,7 @@ function s3_sync() { cmd="aws s3 sync \ --profile $ASSET_PROFILE \ --region $DEPLOY_REGION \ + --acl public-read \ --delete \ --metadata commit=$(git rev-parse HEAD) \ $source \ From 679e202ac7e6f2a33f48ffb0902d9893bfd58877 Mon Sep 17 00:00:00 2001 From: Andrew Crabb Date: Mon, 22 Mar 2021 19:59:11 -0400 Subject: [PATCH 4/5] Add option to deploy to public buckets. Add clobber option to configure-deploy --- .travis.yml | 6 ++--- _scripts/configure-deploy.sh | 50 ++++++++++++++++++++++++++++++++++++ _scripts/deploy.sh | 31 +++++++++++++++++++--- _scripts/make-dist.sh | 7 ++++- 4 files changed, 87 insertions(+), 7 deletions(-) mode change 100644 => 100755 _scripts/configure-deploy.sh diff --git a/.travis.yml b/.travis.yml index 94add2e5c..240c76254 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 --verbose 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 --verbose test + script: bash _scripts/deploy.sh --public --verbose test skip_cleanup: true on: repo: aws-samples/aws-genomics-workflows diff --git a/_scripts/configure-deploy.sh b/_scripts/configure-deploy.sh old mode 100644 new mode 100755 index 309192f25..1fe6dcccc --- a/_scripts/configure-deploy.sh +++ b/_scripts/configure-deploy.sh @@ -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 <&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] diff --git a/_scripts/deploy.sh b/_scripts/deploy.sh index 4e40237c6..dc30d0225 100755 --- a/_scripts/deploy.sh +++ b/_scripts/deploy.sh @@ -10,6 +10,21 @@ ASSET_STAGE=test ASSET_PROFILE=asset-publisher DEPLOY_REGION=us-east-1 +usage() { + cat < Date: Tue, 23 Mar 2021 16:22:42 -0400 Subject: [PATCH 5/5] Source nextflow container image from ECR Public --- _scripts/deploy.sh | 6 +++--- src/containers/nextflow/Dockerfile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_scripts/deploy.sh b/_scripts/deploy.sh index dc30d0225..e00ab7aae 100755 --- a/_scripts/deploy.sh +++ b/_scripts/deploy.sh @@ -107,7 +107,6 @@ function s3_sync() { $destination" echo $cmd eval $cmd - exit } function publish() { @@ -158,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 } diff --git a/src/containers/nextflow/Dockerfile b/src/containers/nextflow/Dockerfile index 920e7ab06..249ffdd16 100644 --- a/src/containers/nextflow/Dockerfile +++ b/src/containers/nextflow/Dockerfile @@ -1,5 +1,5 @@ ARG VERSION=latest -FROM nextflow/nextflow:${VERSION} AS build +FROM public.ecr.aws/seqera-labs/nextflow:${VERSION} AS build # The upstream nextflow containers are based on alpine # which are not compatible with the aws cli