Skip to content

Commit

Permalink
Merge pull request #8 from BillBrower/master
Browse files Browse the repository at this point in the history
Add support for --file-exists-behavior flag. Fixes #4. Fixes #7.
  • Loading branch information
virgofx authored Jan 27, 2019
2 parents 374089b + 01d6d69 commit fecb091
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,28 @@ Include the `aws-code-deploy` from NPM as a local or global dependency.

Environment variables are used to control the deployment actions. A brief summary is listed in the table below. Full descriptions with recommendations can be found by searching the readme for the variable name.

| Variable | Required | Description |
| :---------------------------------------- | :------- | :----------------------------------------------------------|
| `AWS_CODE_DEPLOY_KEY` | No | If specified, sets the AWS key id |
| `AWS_CODE_DEPLOY_SECRET` | No | If specified, sets the AWS secret key |
| `AWS_CODE_DEPLOY_REGION` | No | If specified, sets the AWS region |
| `AWS_CODE_DEPLOY_APPLICATION_NAME` | **Yes** | Application name. If it does not exist, will create. |
| `AWS_CODE_DEPLOY_DEPLOYMENT_GROUP_NAME` | **Yes** | Deployment group name. If it does not exist, will create. |
| `AWS_CODE_DEPLOY_DEPLOYMENT_CONFIG_NAME` | No | Deployment config name. By default: _CodeDeployDefault.OneAtATime_ |
| `AWS_CODE_DEPLOY_MINIMUM_HEALTHY_HOSTS` | No | The minimum number of healthy instances during deployment. By default: _type=FLEET_PERCENT,value=75_ |
| `AWS_CODE_DEPLOY_SERVICE_ROLE_ARN` | No | Service role arn giving permissions to use Code Deploy when creating a deployment group |
| `AWS_CODE_DEPLOY_EC2_TAG_FILTERS` | No | EC2 tags to filter on when creating a deployment group |
| `AWS_CODE_DEPLOY_AUTO_SCALING_GROUPS` | No | Auto Scaling groups when creating a deployment group |
| `AWS_CODE_DEPLOY_APP_SOURCE` | **Yes** | The source directory used to create the deploy archive or a pre-bundled tar, tgz, or zip |
| `AWS_CODE_DEPLOY_S3_BUCKET` | **Yes** | The name of the S3 bucket to deploy the revision |
| `AWS_CODE_DEPLOY_S3_KEY_PREFIX` | No | A prefix to use for the revision bucket key |
| `AWS_CODE_DEPLOY_S3_FILENAME` | **Yes** | The destination name within S3. |
| `AWS_CODE_DEPLOY_S3_LIMIT_BUCKET_FILES` | No | Number of revisions to limit. If 0, unlimited. Default = `0` |
| `AWS_CODE_DEPLOY_S3_SSE` | No | If specified and `true` will ensure the CodeDeploy archive is stored in S3 with Server Side Encryption (SSE) |
| `AWS_CODE_DEPLOY_REVISION_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific revision |
| `AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific deployment |
| `AWS_CODE_DEPLOY_OUTPUT_STATUS_LIVE` | No | Boolean `true\|false` that specifies whether the deployment status should use a single line showing live status. In CI environments where the `\r` is not supported, set this to `false` for better logging. Default = `true` |
| Variable | Required | Description |
| :-------------------------------------------------| :------- | :----------------------------------------------------------|
| `AWS_CODE_DEPLOY_KEY` | No | If specified, sets the AWS key id |
| `AWS_CODE_DEPLOY_SECRET` | No | If specified, sets the AWS secret key |
| `AWS_CODE_DEPLOY_REGION` | No | If specified, sets the AWS region |
| `AWS_CODE_DEPLOY_APPLICATION_NAME` | **Yes** | Application name. If it does not exist, will create. |
| `AWS_CODE_DEPLOY_DEPLOYMENT_GROUP_NAME` | **Yes** | Deployment group name. If it does not exist, will create. |
| `AWS_CODE_DEPLOY_DEPLOYMENT_CONFIG_NAME` | No | Deployment config name. By default: _CodeDeployDefault.OneAtATime_ |
| `AWS_CODE_DEPLOY_MINIMUM_HEALTHY_HOSTS` | No | The minimum number of healthy instances during deployment. By default: _type=FLEET_PERCENT,value=75_ |
| `AWS_CODE_DEPLOY_SERVICE_ROLE_ARN` | No | Service role arn giving permissions to use Code Deploy when creating a deployment group |
| `AWS_CODE_DEPLOY_EC2_TAG_FILTERS` | No | EC2 tags to filter on when creating a deployment group |
| `AWS_CODE_DEPLOY_AUTO_SCALING_GROUPS` | No | Auto Scaling groups when creating a deployment group |
| `AWS_CODE_DEPLOY_APP_SOURCE` | **Yes** | The source directory used to create the deploy archive or a pre-bundled tar, tgz, or zip |
| `AWS_CODE_DEPLOY_S3_BUCKET` | **Yes** | The name of the S3 bucket to deploy the revision |
| `AWS_CODE_DEPLOY_S3_KEY_PREFIX` | No | A prefix to use for the revision bucket key |
| `AWS_CODE_DEPLOY_S3_FILENAME` | **Yes** | The destination name within S3. |
| `AWS_CODE_DEPLOY_S3_LIMIT_BUCKET_FILES` | No | Number of revisions to limit. If 0, unlimited. Default = `0` |
| `AWS_CODE_DEPLOY_S3_SSE` | No | If specified and `true` will ensure the CodeDeploy archive is stored in S3 with Server Side Encryption (SSE) |
| `AWS_CODE_DEPLOY_REVISION_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific revision |
| `AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific deployment |
| `AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR` | No | String `DISALLOW|OVERWRITE|RETAIN` that defines how AWS CodeDeploy handles files that already exist in a deployment target location but weren't part of the previous successful deployment. Default = `DISALLOW`
| `AWS_CODE_DEPLOY_OUTPUT_STATUS_LIVE` | No | Boolean `true\|false` that specifies whether the deployment status should use a single line showing live status. In CI environments where the `\r` is not supported, set this to `false` for better logging. Default = `true` |


## Examples
Expand All @@ -145,8 +146,6 @@ Environment variables are used to control the deployment actions. A brief summar
machine:

environment:
DEPLOY_DIR: $HOME/deploy

# We are defining the $AWS_CODE_DEPLOY_KEY and $AWS_CODE_DEPLOY_SECRET in the CircleCI Project Settings >
# AWS Permissions which automatically configure these for use via aws cli and are automatically read
# via aws-code-deploy.sh. Alternatively, these could be specified securely (not via project code) using
Expand All @@ -165,6 +164,7 @@ machine:
AWS_CODE_DEPLOY_S3_SSE: true
AWS_CODE_DEPLOY_REVISION_DESCRIPTION: "${CIRCLE_BRANCH} (#${CIRCLE_SHA1:0:7})"
AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION: "Deployed via CircleCI on $(date)"
AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR: "OVERWRITE"

# ...

Expand Down
10 changes: 10 additions & 0 deletions bin/aws-code-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ if [ -z "$AWS_CODE_DEPLOY_S3_FILENAME" ]; then
exit 1
fi

if [[ -n "$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR" && ! "$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR" =~ ^(DISALLOW|OVERWRITE|RETAIN)$ ]]; then
error "$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR is not a valid option for the \"\$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR\" variable"
exit 1
fi


# ----- Install AWS Cli -----
Expand Down Expand Up @@ -476,13 +480,19 @@ runCommand "${REGISTER_APP_CMD}" \
# see documentation http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html
# ----------------------
DEPLOYMENT_DESCRIPTION="$AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION"
DEPLOYMENT_FILE_EXISTS_BEHAVIOR="$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR"
h1 "Step 10: Creating Deployment"
DEPLOYMENT_CMD="aws deploy create-deployment --output json --application-name $APPLICATION_NAME --deployment-config-name $DEPLOYMENT_CONFIG_NAME --deployment-group-name $DEPLOYMENT_GROUP --s3-location $S3_LOCATION"

if [ -n "$DEPLOYMENT_DESCRIPTION" ]; then
DEPLOYMENT_CMD="$DEPLOYMENT_CMD --description \"$DEPLOYMENT_DESCRIPTION\""
fi

if [ -z "$DEPLOYMENT_FILE_EXISTS_BEHAVIOR" ]; then
DEPLOYMENT_FILE_EXISTS_BEHAVIOR="DISALLOW"
fi
DEPLOYMENT_CMD="$DEPLOYMENT_CMD --file-exists-behavior $DEPLOYMENT_FILE_EXISTS_BEHAVIOR"

DEPLOYMENT_OUTPUT=""
runCommand "$DEPLOYMENT_CMD" \
"Deployment of application \"$APPLICATION_NAME\" on deployment group \"$DEPLOYMENT_GROUP\" failed" \
Expand Down

0 comments on commit fecb091

Please sign in to comment.