Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/refactor deploys #193

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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\/.*/
54 changes: 54 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -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 <environment>"
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