From cb0780667da167f155ba88be73929418fa87bab1 Mon Sep 17 00:00:00 2001 From: Eric Griffis Date: Fri, 21 Jun 2024 16:18:59 -0400 Subject: [PATCH] Circle - add script for deploys; refactor deploys to only deploy necessary views and separate test and dev views --- .circleci/config.yml | 42 ++++++++++++++++++++++------------ scripts/deploy.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 15 deletions(-) create mode 100755 scripts/deploy.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d5e8deb..a971c4e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,18 +17,6 @@ aws-export: &aws-export echo 'export AWS_SECRET_ACCESS_KEY=${WEB_CDN_AWS_SECRET_ACCESS_KEY}' >> $BASH_ENV echo 'export AWS_REGION=us-east-1' >> $BASH_ENV -# Note that `aws s3 sync ... --exact-timestamps` only works for downloads from S3, -# not uploads: https://github.com/aws/aws-cli/issues/4460. The only safe way -# to update is to upload absolutely everything using `cp` and then deleting -# removed files using `sync --delete`. There are many other open GitHub issues -# related to this behavior. Here's another: https://github.com/aws/aws-cli/issues/3273. -aws-sync-s3: &aws-sync-s3 - run: - name: Deploy to S3 - command: | - aws s3 cp --recursive primo-customization $S3_URI/primo-customization && \ - aws s3 sync --delete primo-customization $S3_URI/primo-customization - version: 2.1 orbs: aws-cli: circleci/aws-cli@4.1.1 @@ -116,6 +104,18 @@ jobs: environment: VIEW: 01NYU_US-SH + deploy_test: + <<: *docker-defaults + steps: + - checkout + - setup_remote_docker + - *asset_sanity_check + - *aws-export + - aws-cli/setup + - run: + name: Deploy test views to dev S3 + command: ./scripts/deploy.sh test + deploy_dev: <<: *docker-defaults steps: @@ -124,7 +124,10 @@ jobs: - *asset_sanity_check - *aws-export - aws-cli/setup - - *aws-sync-s3 + - run: + name: Deploy dev views to dev S3 + command: ./scripts/deploy.sh dev + deploy_prod: <<: *docker-defaults steps: @@ -133,7 +136,9 @@ jobs: - *asset_sanity_check - *aws-export - aws-cli/setup - - *aws-sync-s3 + - run: + name: Deploy prod views to prod S3 + command: ./scripts/deploy.sh prod workflows: version: 2.1 @@ -198,7 +203,6 @@ workflows: - run-e2e-nyhs-dev - run-e2e-nysid-dev - run-e2e-nyu-dev - - run-e2e-nyu-test - run-e2e-sh-dev context: web-cdn-aws-nyulitsdev filters: @@ -217,3 +221,11 @@ workflows: filters: branches: only: main + - deploy_test: + requires: + - run-e2e-nyu-test + context: web-cdn-aws-nyulitsdev + filters: + branches: + only: + - /test\/.*/ diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..0eb4655 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,54 @@ +#!/bin/bash -e + +DEV_S3_URI='s3://cdn-dev.library.nyu.edu' +PROD_S3_URI='s3://cdn.library.nyu.edu' + +if [ -z "$1" ] +then + echo "Usage: " + echo "To deploy primo-customization-cdn resources to a given cdn environment" + echo " $0 " + exit +fi + +# get env from argument and set s3 uri +env=$1 +if [[ "$env" == "dev" || "$env" == "test" ]] +then + s3_uri=$DEV_S3_URI +elif [[ "$env" == "prod" ]] +then + s3_uri=$PROD_S3_URI +else + echo "Error: Invalid environment \"$env\"" + exit 1 +fi + +# get subdirs (views) to copy +view_dir='primo-customization' +common_subdir='00_common' +test_subdir='01NYU_INST-TESTWS01' +if [[ "$env" == "dev" ]] +then + subdirs=`ls "$view_dir" | grep -v "$common_subdir" | grep -v "$test_subdir" | grep '_DEV$'` +elif [[ "$env" == "prod" ]] +then + subdirs=`ls "$view_dir" | grep -v "$common_subdir" | grep -v "$test_subdir" | grep -v '_DEV$'` +elif [[ "$env" == "test" ]] +then + subdirs=$test_subdir +fi +subdirs="$common_subdir $subdirs" + +# sync files, deleting any removed +for dir in $subdirs +do + echo "Deploying primo-customization/$dir => $s3_uri/primo-customization/$dir" + # Note that `aws s3 sync ... --exact-timestamps` only works for downloads from S3, + # not uploads: https://github.com/aws/aws-cli/issues/4460. The only safe way + # to update is to upload absolutely everything using `cp` and then deleting + # removed files using `sync --delete`. There are many other open GitHub issues + # related to this behavior. Here's another: https://github.com/aws/aws-cli/issues/3273. + aws s3 cp --recursive primo-customization/$dir $s3_uri/primo-customization/$dir + aws s3 sync --delete primo-customization/$dir $s3_uri/primo-customization/$dir +done