From 509f6aa77c12fbaf568bbe57fd427d23021d64e4 Mon Sep 17 00:00:00 2001 From: lucas-dall Date: Thu, 31 May 2018 16:39:28 -0300 Subject: [PATCH 1/5] feat: codedeploy push revision only script --- .../scripts/codeship_aws_codedeploy_push | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 deployment/scripts/codeship_aws_codedeploy_push diff --git a/deployment/scripts/codeship_aws_codedeploy_push b/deployment/scripts/codeship_aws_codedeploy_push new file mode 100644 index 0000000..2bec8a4 --- /dev/null +++ b/deployment/scripts/codeship_aws_codedeploy_push @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e +set -o pipefail + +APPLICATION_FOLDER=${1:?'You need to provide the directory with your code as the second parameter'} +APPLICATION_NAME=${2:?'You need to provide the CodeDeploy application name'} +S3_BUCKET=${3:?'You need to provide the S3 Bucket to upload the artefact to'} + +source utils +S3_BUCKET_SUBFOLDER_PATH=$(s3_bucket_subfolder_path $S3_BUCKET) +S3_BUCKET=$(s3_bucket_name $S3_BUCKET) + +echo "Pushing CodeDeploy revision to $APPLICATION_NAME" + +VERSION_NAME=${CI_COMMIT_ID}-${CI_BUILD_ID}-${CI_TIMESTAMP} +FILE_NAME=$VERSION_NAME.zip + +if [[ -z $S3_BUCKET_SUBFOLDER_PATH ]]; then + S3_KEY=$FILE_NAME + S3_PATH="s3://$S3_BUCKET/$FILE_NAME" +else + S3_KEY="$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" + S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" +fi + +aws deploy push --application-name "$APPLICATION_NAME" --description "$CI_COMMIT_MESSAGE" --ignore-hidden-files --s3-location "$S3_PATH" --source "$APPLICATION_FOLDER" From 84a102b18d928162f6bf5f8f34e12d17b6223e7f Mon Sep 17 00:00:00 2001 From: lucas-dall Date: Thu, 31 May 2018 16:40:04 -0300 Subject: [PATCH 2/5] feat: codedeploy deploy pushed revision script --- .../codeship_aws_codedeploy_deploy_revision | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 deployment/scripts/codeship_aws_codedeploy_deploy_revision diff --git a/deployment/scripts/codeship_aws_codedeploy_deploy_revision b/deployment/scripts/codeship_aws_codedeploy_deploy_revision new file mode 100644 index 0000000..2c0f3ca --- /dev/null +++ b/deployment/scripts/codeship_aws_codedeploy_deploy_revision @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e +set -o pipefail + +APPLICATION_FOLDER=${1:?'You need to provide the directory with your code as the second parameter'} +APPLICATION_NAME=${2:?'You need to provide the CodeDeploy application name'} +DEPLOYMENT_GROUP_NAME=${3:?'You need to provide the Deployment Group name'} +S3_BUCKET=${4:?'You need to provide the S3 Bucket to upload the artefact to'} +DEPLOYMENT_CONFIG_NAME=$5 + +source utils +S3_BUCKET_SUBFOLDER_PATH=$(s3_bucket_subfolder_path $S3_BUCKET) +S3_BUCKET=$(s3_bucket_name $S3_BUCKET) + +echo "Starting CodeDeploy deployment to $APPLICATION_NAME:$DEPLOYMENT_GROUP_NAME" + +VERSION_NAME=${CI_COMMIT_ID}-${CI_BUILD_ID}-${CI_TIMESTAMP} +FILE_NAME=$VERSION_NAME.zip + +if [[ -z $S3_BUCKET_SUBFOLDER_PATH ]]; then + S3_KEY=$FILE_NAME + S3_PATH="s3://$S3_BUCKET/$FILE_NAME" +else + S3_KEY="$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" + S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" +fi + +echo "Creating new Deployment: $VERSION_NAME" + +deployment=("--application-name" "$APPLICATION_NAME" "--deployment-group-name" "$DEPLOYMENT_GROUP_NAME" "--description" "$CI_COMMIT_MESSAGE" "--s3-location" "bucket=$S3_BUCKET,key=$S3_KEY,bundleType=zip") + +if [ ! -z "$DEPLOYMENT_CONFIG_NAME" ]; then + deployment+=("--deployment-config-name" "$DEPLOYMENT_CONFIG_NAME") +fi + +echo "Deployment Command: ${deployment[@]}" + +deployment_id=$(aws deploy create-deployment "${deployment[@]}" | jq -r .deploymentId) + +echo "Validating deployment: $deployment_id" +codeship_aws codedeploy_deploy_validation "$deployment_id" From 1dffdcf5e64304153270384d20fd19ad98833798 Mon Sep 17 00:00:00 2001 From: lucas-dall Date: Thu, 31 May 2018 17:15:07 -0300 Subject: [PATCH 3/5] feat: push script output --- deployment/scripts/codeship_aws_codedeploy_push | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deployment/scripts/codeship_aws_codedeploy_push b/deployment/scripts/codeship_aws_codedeploy_push index 2bec8a4..cc10173 100644 --- a/deployment/scripts/codeship_aws_codedeploy_push +++ b/deployment/scripts/codeship_aws_codedeploy_push @@ -24,4 +24,6 @@ else S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" fi -aws deploy push --application-name "$APPLICATION_NAME" --description "$CI_COMMIT_MESSAGE" --ignore-hidden-files --s3-location "$S3_PATH" --source "$APPLICATION_FOLDER" +REVISION=$(aws deploy push --application-name "$APPLICATION_NAME" --description "$CI_COMMIT_MESSAGE" --ignore-hidden-files --s3-location "$S3_PATH" --source "$APPLICATION_FOLDER") + +echo "Revision uploaded key : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1), eTag : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1)" \ No newline at end of file From 730f6e500241b63a1b022fb59b9bbcac844ed814 Mon Sep 17 00:00:00 2001 From: lucas-dall Date: Thu, 31 May 2018 17:17:59 -0300 Subject: [PATCH 4/5] fix: push script name --- ...ploy_deploy_revision => codeship_aws_codedeploy_push_revision} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename deployment/scripts/{codeship_aws_codedeploy_deploy_revision => codeship_aws_codedeploy_push_revision} (100%) diff --git a/deployment/scripts/codeship_aws_codedeploy_deploy_revision b/deployment/scripts/codeship_aws_codedeploy_push_revision similarity index 100% rename from deployment/scripts/codeship_aws_codedeploy_deploy_revision rename to deployment/scripts/codeship_aws_codedeploy_push_revision From d2895bf067192aecc753018ff5dc4ad84b560885 Mon Sep 17 00:00:00 2001 From: lucas-dall Date: Thu, 31 May 2018 17:21:04 -0300 Subject: [PATCH 5/5] fix: scripts name adjusted --- .../codeship_aws_codedeploy_deploy_revision | 42 +++++++++++++++++++ .../scripts/codeship_aws_codedeploy_push | 29 ------------- .../codeship_aws_codedeploy_push_revision | 21 ++-------- 3 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 deployment/scripts/codeship_aws_codedeploy_deploy_revision delete mode 100644 deployment/scripts/codeship_aws_codedeploy_push diff --git a/deployment/scripts/codeship_aws_codedeploy_deploy_revision b/deployment/scripts/codeship_aws_codedeploy_deploy_revision new file mode 100644 index 0000000..2c0f3ca --- /dev/null +++ b/deployment/scripts/codeship_aws_codedeploy_deploy_revision @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e +set -o pipefail + +APPLICATION_FOLDER=${1:?'You need to provide the directory with your code as the second parameter'} +APPLICATION_NAME=${2:?'You need to provide the CodeDeploy application name'} +DEPLOYMENT_GROUP_NAME=${3:?'You need to provide the Deployment Group name'} +S3_BUCKET=${4:?'You need to provide the S3 Bucket to upload the artefact to'} +DEPLOYMENT_CONFIG_NAME=$5 + +source utils +S3_BUCKET_SUBFOLDER_PATH=$(s3_bucket_subfolder_path $S3_BUCKET) +S3_BUCKET=$(s3_bucket_name $S3_BUCKET) + +echo "Starting CodeDeploy deployment to $APPLICATION_NAME:$DEPLOYMENT_GROUP_NAME" + +VERSION_NAME=${CI_COMMIT_ID}-${CI_BUILD_ID}-${CI_TIMESTAMP} +FILE_NAME=$VERSION_NAME.zip + +if [[ -z $S3_BUCKET_SUBFOLDER_PATH ]]; then + S3_KEY=$FILE_NAME + S3_PATH="s3://$S3_BUCKET/$FILE_NAME" +else + S3_KEY="$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" + S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" +fi + +echo "Creating new Deployment: $VERSION_NAME" + +deployment=("--application-name" "$APPLICATION_NAME" "--deployment-group-name" "$DEPLOYMENT_GROUP_NAME" "--description" "$CI_COMMIT_MESSAGE" "--s3-location" "bucket=$S3_BUCKET,key=$S3_KEY,bundleType=zip") + +if [ ! -z "$DEPLOYMENT_CONFIG_NAME" ]; then + deployment+=("--deployment-config-name" "$DEPLOYMENT_CONFIG_NAME") +fi + +echo "Deployment Command: ${deployment[@]}" + +deployment_id=$(aws deploy create-deployment "${deployment[@]}" | jq -r .deploymentId) + +echo "Validating deployment: $deployment_id" +codeship_aws codedeploy_deploy_validation "$deployment_id" diff --git a/deployment/scripts/codeship_aws_codedeploy_push b/deployment/scripts/codeship_aws_codedeploy_push deleted file mode 100644 index cc10173..0000000 --- a/deployment/scripts/codeship_aws_codedeploy_push +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -APPLICATION_FOLDER=${1:?'You need to provide the directory with your code as the second parameter'} -APPLICATION_NAME=${2:?'You need to provide the CodeDeploy application name'} -S3_BUCKET=${3:?'You need to provide the S3 Bucket to upload the artefact to'} - -source utils -S3_BUCKET_SUBFOLDER_PATH=$(s3_bucket_subfolder_path $S3_BUCKET) -S3_BUCKET=$(s3_bucket_name $S3_BUCKET) - -echo "Pushing CodeDeploy revision to $APPLICATION_NAME" - -VERSION_NAME=${CI_COMMIT_ID}-${CI_BUILD_ID}-${CI_TIMESTAMP} -FILE_NAME=$VERSION_NAME.zip - -if [[ -z $S3_BUCKET_SUBFOLDER_PATH ]]; then - S3_KEY=$FILE_NAME - S3_PATH="s3://$S3_BUCKET/$FILE_NAME" -else - S3_KEY="$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" - S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" -fi - -REVISION=$(aws deploy push --application-name "$APPLICATION_NAME" --description "$CI_COMMIT_MESSAGE" --ignore-hidden-files --s3-location "$S3_PATH" --source "$APPLICATION_FOLDER") - -echo "Revision uploaded key : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1), eTag : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1)" \ No newline at end of file diff --git a/deployment/scripts/codeship_aws_codedeploy_push_revision b/deployment/scripts/codeship_aws_codedeploy_push_revision index 2c0f3ca..cc10173 100644 --- a/deployment/scripts/codeship_aws_codedeploy_push_revision +++ b/deployment/scripts/codeship_aws_codedeploy_push_revision @@ -5,15 +5,13 @@ set -o pipefail APPLICATION_FOLDER=${1:?'You need to provide the directory with your code as the second parameter'} APPLICATION_NAME=${2:?'You need to provide the CodeDeploy application name'} -DEPLOYMENT_GROUP_NAME=${3:?'You need to provide the Deployment Group name'} -S3_BUCKET=${4:?'You need to provide the S3 Bucket to upload the artefact to'} -DEPLOYMENT_CONFIG_NAME=$5 +S3_BUCKET=${3:?'You need to provide the S3 Bucket to upload the artefact to'} source utils S3_BUCKET_SUBFOLDER_PATH=$(s3_bucket_subfolder_path $S3_BUCKET) S3_BUCKET=$(s3_bucket_name $S3_BUCKET) -echo "Starting CodeDeploy deployment to $APPLICATION_NAME:$DEPLOYMENT_GROUP_NAME" +echo "Pushing CodeDeploy revision to $APPLICATION_NAME" VERSION_NAME=${CI_COMMIT_ID}-${CI_BUILD_ID}-${CI_TIMESTAMP} FILE_NAME=$VERSION_NAME.zip @@ -26,17 +24,6 @@ else S3_PATH="s3://$S3_BUCKET/$S3_BUCKET_SUBFOLDER_PATH/$FILE_NAME" fi -echo "Creating new Deployment: $VERSION_NAME" +REVISION=$(aws deploy push --application-name "$APPLICATION_NAME" --description "$CI_COMMIT_MESSAGE" --ignore-hidden-files --s3-location "$S3_PATH" --source "$APPLICATION_FOLDER") -deployment=("--application-name" "$APPLICATION_NAME" "--deployment-group-name" "$DEPLOYMENT_GROUP_NAME" "--description" "$CI_COMMIT_MESSAGE" "--s3-location" "bucket=$S3_BUCKET,key=$S3_KEY,bundleType=zip") - -if [ ! -z "$DEPLOYMENT_CONFIG_NAME" ]; then - deployment+=("--deployment-config-name" "$DEPLOYMENT_CONFIG_NAME") -fi - -echo "Deployment Command: ${deployment[@]}" - -deployment_id=$(aws deploy create-deployment "${deployment[@]}" | jq -r .deploymentId) - -echo "Validating deployment: $deployment_id" -codeship_aws codedeploy_deploy_validation "$deployment_id" +echo "Revision uploaded key : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1), eTag : $(echo $REVISION | awk -F 'eTag=| --deployment' '{print $2}' | tail -1)" \ No newline at end of file