-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make S3 bucket script machine runnable (#60)
* feat(makeReactBucket.sh): bypass user input with shell arg * feat(makeReactBucket.sh): make script callable from anywhere * chore(makeReactBucket.sh): make quotes convention more consistent * feat(makeReactBucket.sh): extract initials validation function * refactor(/devops): moved function to a helper file * refactor(/devops): make function take arg instead of use global * chore(/devops): lint, change from .sh to .bash * refactor(makeReactBucket.json): converted to yml for consistency with other template files * chore(makeReactBucket.json): delete file * Merge development into dj-40 commit 875b6bc Author: Daniel <[email protected]> Date: Thu Feb 3 16:02:49 2022 -0800 Python script run feedback datasets#22 (#30) * first * update on assignment * Modified task.py * deleted floop_data_15k.json and word2vec11.model * removed the commented * word2vec11.model file added * updated * update line 83 * update csv file * updates of * Update on the code * floop_data_15k.json deleted * DataFromS3 to Field1 changed * line 25 added * Update on task.py and added info.md file commit 4880bf7 Merge: d0940f8 8c0b991 Author: ChrisNavo <[email protected]> Date: Thu Feb 3 14:11:15 2022 -0800 Merge pull request #59 from North-Seattle-College/react-S3-action React S3 Action deploy commit 8c0b991 Author: CNavo <[email protected]> Date: Wed Feb 2 21:50:37 2022 -0800 React S3 Action deploy
- Loading branch information
Showing
5 changed files
with
148 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
################################# | ||
# Validate that a string has the following characteristics: | ||
# - At least 2 chars | ||
# - No more than 5 chars | ||
# - Has no whitespace | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# initials | ||
################################# | ||
function validateInitials() { | ||
MIN=2 | ||
MAX=5 | ||
|
||
initials=$1 | ||
|
||
if [ -z "$initials" ]; then | ||
printf '%s\n' "Error: initials can't be empty" >&2 | ||
return 1 | ||
elif [[ "${initials}" =~ [^a-zA-Z] ]]; then | ||
printf '%s\n' "Error: initials must only contain letters, a-z" >&2 | ||
return 1 | ||
elif [[ "${#initials}" < $MIN ]]; then | ||
printf '%s\n' "Error: initials must be at least $MIN characters" >&2 | ||
return 1 | ||
elif [[ "${#initials}" > $MAX ]]; then | ||
printf '%s\n' "Error: initials must be no more than $MAX characters" >&2 | ||
return 1 | ||
fi | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_PATH=$(dirname "$0") | ||
|
||
# import validateInitials from common.lib | ||
# shellcheck disable=SC1091 | ||
. "$SCRIPT_PATH/../common.lib" | ||
|
||
RANDOM_STRING=$(cat /dev/urandom | base64 | tr -dc 'a-z0-9' | fold -w 5 | head -n 1) | ||
BUCKET_TEMPLATE="$SCRIPT_PATH/makeReactBucket.yml" | ||
INITIALS_PROMPT="What are your initials? ('q' to quit)" | ||
|
||
initials="$1" | ||
skipPrompt=false | ||
|
||
while :; do | ||
# get and validate user initials if not passed as arg | ||
if [[ -z "$initials" ]]; then | ||
printf "%s\n" "$INITIALS_PROMPT" >&1 | ||
printf "%s" "> " >&1 | ||
while read -r initials && [ "$initials" != "q" ]; do | ||
if validateInitials "$initials"; then | ||
break | ||
fi | ||
printf "%s\n" "$INITIALS_PROMPT" >&1 | ||
printf "%s" "> " >&1 | ||
done | ||
elif validateInitials "$initials"; then | ||
skipPrompt=true | ||
answer=y | ||
else | ||
break | ||
fi | ||
|
||
if [ "$initials" == "q" ]; then | ||
printf '%s\n' "Done" >&1 | ||
break | ||
fi | ||
|
||
formattedInitials="$(echo "${initials}" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')" | ||
todayDate=$(date +'%Y%m%d') | ||
uniqueName=$formattedInitials-$RANDOM_STRING-$todayDate | ||
|
||
bucketName=$uniqueName-bucket | ||
stackName=$uniqueName-stack | ||
|
||
if [ "$skipPrompt" = false ]; then | ||
# show user name of bucket and stack, get confirmation to create resources | ||
printf "%s\n" "Your bucket and stack will be named as follows:" \ | ||
" - bucket: $bucketName" \ | ||
" - stack: $stackName" \ | ||
"Create bucket and stack? (y/n)" >&1 | ||
printf "%s" "> " >&1 | ||
while read -r answer && [ "$answer" != "q" ]; do | ||
if [ "${answer:0:1}" == "y" ] || [ "${answer:0:1}" == "n" ]; then | ||
break | ||
else | ||
printf "%s\n" "Create bucket? (y/n)" >&1 | ||
printf "%s" "> " >&1 | ||
fi | ||
done | ||
fi | ||
|
||
if [ "${answer:0:1}" == "y" ]; then | ||
printf '%s\n' "aws cloudformation deploy --template-file $BUCKET_TEMPLATE --stack-name $stackName --parameter-overrides BucketName=$bucketName" >&1 | ||
aws cloudformation deploy --template-file "$BUCKET_TEMPLATE" --stack-name "$stackName" --parameter-overrides BucketName="$bucketName" | ||
fi | ||
printf '%s\n' "Done" >&1 | ||
break | ||
done |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Parameters: | ||
BucketName: | ||
Description: Name of your S3 bucket. Must be unique. | ||
Type: String | ||
Resources: | ||
ReactBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: !Ref BucketName | ||
AccessControl: PublicRead | ||
WebsiteConfiguration: | ||
IndexDocument: index.html | ||
ErrorDocument: index.html | ||
ReactBucketPolicy: | ||
Type: AWS::S3::BucketPolicy | ||
Properties: | ||
Bucket: !Ref ReactBucket | ||
PolicyDocument: | ||
Id: MyPolicy | ||
Version: 2012-10-17 | ||
Statement: | ||
Sid: PublicReadForGetBucketObjects | ||
Effect: Allow | ||
Principal: '*' | ||
Action: s3:GetObject | ||
Resource: !Join | ||
- '' | ||
- - 'arn:aws:s3:::' | ||
- !Ref ReactBucket | ||
- /* | ||
Outputs: | ||
WebsiteURL: | ||
Value: !GetAtt | ||
- ReactBucket | ||
- WebsiteURL | ||
Description: URL for website hosted on S3 | ||
S3BucketSecureURL: | ||
Value: !Join | ||
- '' | ||
- - 'https://' | ||
- !GetAtt | ||
- ReactBucket | ||
- DomainName | ||
Description: Name of S3 bucket to hold website content |