diff --git a/README.md b/README.md index 2ce69ac..4df8ada 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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" # ... diff --git a/bin/aws-code-deploy.sh b/bin/aws-code-deploy.sh index 42280b4..e897a59 100644 --- a/bin/aws-code-deploy.sh +++ b/bin/aws-code-deploy.sh @@ -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 ----- @@ -476,6 +480,7 @@ 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" @@ -483,6 +488,11 @@ 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" \