Skip to content

Commit 01d6d69

Browse files
committed
Add support for --file-exists-behavior flag. Fixes #4. Fixes #7.
1 parent 374089b commit 01d6d69

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

README.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,28 @@ Include the `aws-code-deploy` from NPM as a local or global dependency.
113113

114114
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.
115115

116-
| Variable | Required | Description |
117-
| :---------------------------------------- | :------- | :----------------------------------------------------------|
118-
| `AWS_CODE_DEPLOY_KEY` | No | If specified, sets the AWS key id |
119-
| `AWS_CODE_DEPLOY_SECRET` | No | If specified, sets the AWS secret key |
120-
| `AWS_CODE_DEPLOY_REGION` | No | If specified, sets the AWS region |
121-
| `AWS_CODE_DEPLOY_APPLICATION_NAME` | **Yes** | Application name. If it does not exist, will create. |
122-
| `AWS_CODE_DEPLOY_DEPLOYMENT_GROUP_NAME` | **Yes** | Deployment group name. If it does not exist, will create. |
123-
| `AWS_CODE_DEPLOY_DEPLOYMENT_CONFIG_NAME` | No | Deployment config name. By default: _CodeDeployDefault.OneAtATime_ |
124-
| `AWS_CODE_DEPLOY_MINIMUM_HEALTHY_HOSTS` | No | The minimum number of healthy instances during deployment. By default: _type=FLEET_PERCENT,value=75_ |
125-
| `AWS_CODE_DEPLOY_SERVICE_ROLE_ARN` | No | Service role arn giving permissions to use Code Deploy when creating a deployment group |
126-
| `AWS_CODE_DEPLOY_EC2_TAG_FILTERS` | No | EC2 tags to filter on when creating a deployment group |
127-
| `AWS_CODE_DEPLOY_AUTO_SCALING_GROUPS` | No | Auto Scaling groups when creating a deployment group |
128-
| `AWS_CODE_DEPLOY_APP_SOURCE` | **Yes** | The source directory used to create the deploy archive or a pre-bundled tar, tgz, or zip |
129-
| `AWS_CODE_DEPLOY_S3_BUCKET` | **Yes** | The name of the S3 bucket to deploy the revision |
130-
| `AWS_CODE_DEPLOY_S3_KEY_PREFIX` | No | A prefix to use for the revision bucket key |
131-
| `AWS_CODE_DEPLOY_S3_FILENAME` | **Yes** | The destination name within S3. |
132-
| `AWS_CODE_DEPLOY_S3_LIMIT_BUCKET_FILES` | No | Number of revisions to limit. If 0, unlimited. Default = `0` |
133-
| `AWS_CODE_DEPLOY_S3_SSE` | No | If specified and `true` will ensure the CodeDeploy archive is stored in S3 with Server Side Encryption (SSE) |
134-
| `AWS_CODE_DEPLOY_REVISION_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific revision |
135-
| `AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific deployment |
136-
| `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` |
116+
| Variable | Required | Description |
117+
| :-------------------------------------------------| :------- | :----------------------------------------------------------|
118+
| `AWS_CODE_DEPLOY_KEY` | No | If specified, sets the AWS key id |
119+
| `AWS_CODE_DEPLOY_SECRET` | No | If specified, sets the AWS secret key |
120+
| `AWS_CODE_DEPLOY_REGION` | No | If specified, sets the AWS region |
121+
| `AWS_CODE_DEPLOY_APPLICATION_NAME` | **Yes** | Application name. If it does not exist, will create. |
122+
| `AWS_CODE_DEPLOY_DEPLOYMENT_GROUP_NAME` | **Yes** | Deployment group name. If it does not exist, will create. |
123+
| `AWS_CODE_DEPLOY_DEPLOYMENT_CONFIG_NAME` | No | Deployment config name. By default: _CodeDeployDefault.OneAtATime_ |
124+
| `AWS_CODE_DEPLOY_MINIMUM_HEALTHY_HOSTS` | No | The minimum number of healthy instances during deployment. By default: _type=FLEET_PERCENT,value=75_ |
125+
| `AWS_CODE_DEPLOY_SERVICE_ROLE_ARN` | No | Service role arn giving permissions to use Code Deploy when creating a deployment group |
126+
| `AWS_CODE_DEPLOY_EC2_TAG_FILTERS` | No | EC2 tags to filter on when creating a deployment group |
127+
| `AWS_CODE_DEPLOY_AUTO_SCALING_GROUPS` | No | Auto Scaling groups when creating a deployment group |
128+
| `AWS_CODE_DEPLOY_APP_SOURCE` | **Yes** | The source directory used to create the deploy archive or a pre-bundled tar, tgz, or zip |
129+
| `AWS_CODE_DEPLOY_S3_BUCKET` | **Yes** | The name of the S3 bucket to deploy the revision |
130+
| `AWS_CODE_DEPLOY_S3_KEY_PREFIX` | No | A prefix to use for the revision bucket key |
131+
| `AWS_CODE_DEPLOY_S3_FILENAME` | **Yes** | The destination name within S3. |
132+
| `AWS_CODE_DEPLOY_S3_LIMIT_BUCKET_FILES` | No | Number of revisions to limit. If 0, unlimited. Default = `0` |
133+
| `AWS_CODE_DEPLOY_S3_SSE` | No | If specified and `true` will ensure the CodeDeploy archive is stored in S3 with Server Side Encryption (SSE) |
134+
| `AWS_CODE_DEPLOY_REVISION_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific revision |
135+
| `AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION` | No | A description that is stored within AWS Code Deploy that stores information about the specific deployment |
136+
| `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`
137+
| `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` |
137138

138139

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

147148
environment:
148-
DEPLOY_DIR: $HOME/deploy
149-
150149
# We are defining the $AWS_CODE_DEPLOY_KEY and $AWS_CODE_DEPLOY_SECRET in the CircleCI Project Settings >
151150
# AWS Permissions which automatically configure these for use via aws cli and are automatically read
152151
# via aws-code-deploy.sh. Alternatively, these could be specified securely (not via project code) using
@@ -165,6 +164,7 @@ machine:
165164
AWS_CODE_DEPLOY_S3_SSE: true
166165
AWS_CODE_DEPLOY_REVISION_DESCRIPTION: "${CIRCLE_BRANCH} (#${CIRCLE_SHA1:0:7})"
167166
AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION: "Deployed via CircleCI on $(date)"
167+
AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR: "OVERWRITE"
168168

169169
# ...
170170

bin/aws-code-deploy.sh

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ if [ -z "$AWS_CODE_DEPLOY_S3_FILENAME" ]; then
157157
exit 1
158158
fi
159159

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

161165

162166
# ----- Install AWS Cli -----
@@ -476,13 +480,19 @@ runCommand "${REGISTER_APP_CMD}" \
476480
# see documentation http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html
477481
# ----------------------
478482
DEPLOYMENT_DESCRIPTION="$AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION"
483+
DEPLOYMENT_FILE_EXISTS_BEHAVIOR="$AWS_CODE_DEPLOY_DEPLOYMENT_FILE_EXISTS_BEHAVIOR"
479484
h1 "Step 10: Creating Deployment"
480485
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"
481486

482487
if [ -n "$DEPLOYMENT_DESCRIPTION" ]; then
483488
DEPLOYMENT_CMD="$DEPLOYMENT_CMD --description \"$DEPLOYMENT_DESCRIPTION\""
484489
fi
485490

491+
if [ -z "$DEPLOYMENT_FILE_EXISTS_BEHAVIOR" ]; then
492+
DEPLOYMENT_FILE_EXISTS_BEHAVIOR="DISALLOW"
493+
fi
494+
DEPLOYMENT_CMD="$DEPLOYMENT_CMD --file-exists-behavior $DEPLOYMENT_FILE_EXISTS_BEHAVIOR"
495+
486496
DEPLOYMENT_OUTPUT=""
487497
runCommand "$DEPLOYMENT_CMD" \
488498
"Deployment of application \"$APPLICATION_NAME\" on deployment group \"$DEPLOYMENT_GROUP\" failed" \

0 commit comments

Comments
 (0)