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

Push revision only step, and deploy revision only step scripts #72

Open
wants to merge 5 commits into
base: master
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: 42 additions & 0 deletions deployment/scripts/codeship_aws_codedeploy_deploy_revision
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions deployment/scripts/codeship_aws_codedeploy_push_revision
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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)"