Skip to content
Merged
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
17 changes: 17 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ if [ -z "$INPUT_S3_BUCKET" ]; then
exit 1;
fi

echo "::debug::Input variables correctly validated."

# 1) Load our permissions in for aws-cli
export AWS_ACCESS_KEY_ID=$INPUT_AWS_ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=$INPUT_AWS_SECRET_KEY
Expand All @@ -45,24 +47,32 @@ if [ ! -f "$DIR_TO_ZIP/appspec.yml" ]; then
exit 1;
fi

echo "::debug::Zip directory located (with appspec.yml)."

ZIP_FILENAME=$GITHUB_RUN_ID-$GITHUB_SHA.zip

# This creates a temp file to explode space delimited excluded files
# into newline delimited exclusions passed to "-x" on the zip command.
EXCLUSION_FILE=$(mktemp /tmp/zip-excluded.XXXXXX)
echo "$INPUT_EXCLUDED_FILES" | tr ' ' '\n' > "$EXCLUSION_FILE"

echo "::debug::Exclusion file created for files to ignore in Zip Generation."

zip -r --quiet "$ZIP_FILENAME" "$DIR_TO_ZIP" -x "@$EXCLUSION_FILE"
if [ ! -f "$ZIP_FILENAME" ]; then
echo "::error::$ZIP_FILENAME was not generated properly (zip generation failed)."
exit 1;
fi

echo "::debug::Zip Archive created."

if [ "$(unzip -l "$ZIP_FILENAME" | grep -q appspec.yml)" = "0" ]; then
echo "::error::$ZIP_FILENAME was not generated properly (missing appspec.yml)."
exit 1;
fi

echo "::debug::Zip Archived validated."

# 3) Upload the deployment to S3, drop old archive.
function getArchiveETag() {
aws s3api head-object \
Expand All @@ -72,10 +82,17 @@ function getArchiveETag() {
}

aws s3 cp "$ZIP_FILENAME" s3://"$INPUT_S3_BUCKET"/"$INPUT_S3_FOLDER"/"$ZIP_FILENAME" > /dev/null 2>&1

echo "::debug::Zip uploaded to S3."

ZIP_ETAG=$(getArchiveETag)

echo "::debug::Obtained ETag of uploaded S3 Zip Archive."

rm "$ZIP_FILENAME"

echo "::debug::Removed old local ZIP Archive."

# 4) Start the CodeDeploy
function getActiveDeployments() {
aws deploy list-deployments \
Expand Down