Skip to content

Commit c83a25c

Browse files
author
Nicolas Huray
committed
Set version 0.0.16
1 parent 15e85c0 commit c83a25c

File tree

4 files changed

+177
-54
lines changed

4 files changed

+177
-54
lines changed

README.md

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,82 @@
11
Wercker step for AWS Code Deploy
22
=======================
33

4+
[![wercker status](https://app.wercker.com/status/3810984a0833d6af679f0609bd3e18be/m "wercker status")](https://app.wercker.com/project/bykey/3810984a0833d6af679f0609bd3e18be)
5+
46
This wercker step allows to deploy applications with [AWS Code Deploy](http://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html) service.
57

68
Please read the [AWS Code Deploy](http://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html) documentation and [API](http://docs.aws.amazon.com/cli/latest/reference/deploy/index.html) before using this step.
79

8-
This step use the [AWS Cli](http://docs.aws.amazon.com/cli/latest/reference/), so you have to use this step with a box where AWS Cli is already installed
9-
or install AWS Cli with this Wercker step : [EdgecaseInc/wercker-step-install-aws-cli](https://github.com/EdgecaseInc/wercker-step-install-aws-cli).
10-
1110
## AWS Code Deploy workflow
1211

1312
To deploy an application with AWS Code Deploy, the Wercker step follow this steps :
1413

15-
#### Step 1 : [Defining Application](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-application.html)
14+
#### Step 1 : [Configuring AWS](http://docs.aws.amazon.com/cli/latest/reference/configure/index.html)
15+
16+
This initial step consists on configuring AWS.
17+
18+
The following configuration allows to setup this step :
19+
20+
* `key` (required): AWS Access Key ID
21+
* `secret` (required): AWS Secret Access Key
22+
* `region` (optional): Default region name
23+
24+
#### Step 2 : [Defining Application](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-application.html)
1625

17-
This first step consists on defining the application. If the application does not exists this step create the application in Code Deploy.
26+
This second step consists on defining the application. If the application does not exists this step create the application in Code Deploy.
1827

19-
The following configuration allows to configure this step :
28+
The following configuration allows to setup this step :
2029

21-
* `application-name` (required) Name of the application to deploy
22-
* `application-version` (optional) Version of the application to deploy. By default: Short commit id _(eg. fec8f4a)_
30+
* `application-name` (required): Name of the application to deploy
31+
* `application-version` (optional): Version of the application to deploy. By default: Short commit id _(eg. fec8f4a)_
2332

24-
#### Step 2 : [Defining Deployment Config](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-config.html) (optional)
33+
#### Step 3 : [Defining Deployment Config](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-config.html) (optional)
2534

26-
The second step consists on creating a deployment config. This step is totally *optional* because you can use the deployment strategy already defined in Code Deploy.
35+
This step consists on creating a deployment config. This step is totally *optional* because you can use the deployment strategy already defined in Code Deploy.
2736

28-
The following configuration allows to configure this step :
37+
The following configuration allows to setup this step :
2938

30-
* `deployment-config-name` (optional) Deployment config name. By default : _CodeDeployDefault.OneAtATime_
31-
* `minimum-healthy-hosts` (optional) The minimum number of healthy instances during deployment. By default : _type=FLEET_PERCENT,value=75_
39+
* `deployment-config-name` (optional): Deployment config name. By default : _CodeDeployDefault.OneAtATime_
40+
* `minimum-healthy-hosts` (optional): The minimum number of healthy instances during deployment. By default : _type=FLEET_PERCENT,value=75_
3241

33-
#### Step 3 : [Defining Deployment Group](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html)
42+
#### Step 4 : [Defining Deployment Group](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html)
3443

35-
The third step consists on defining a deployment group. If the deployment group provided does not exists this step create a deployment group in Code Deploy.
44+
This step consists on defining a deployment group. If the deployment group provided does not exists this step create a deployment group in Code Deploy.
3645

37-
The following configuration allows to configure this step :
46+
The following configuration allows to setup this step :
3847

39-
* `deployment-group-name` (required) Deployment group name
40-
* `service-role-arn` (optional) Service role arn giving permissions to use Code Deploy when creating a deployment group
41-
* `ec2-tag-filters` (optional) EC2 tags to filter on when creating a deployment group
42-
* `auto-scaling-groups` (optional) Auto Scaling groups when creating a deployment group
48+
* `deployment-group-name` (required): Deployment group name
49+
* `service-role-arn` (optional): Service role arn giving permissions to use Code Deploy when creating a deployment group
50+
* `ec2-tag-filters` (optional): EC2 tags to filter on when creating a deployment group
51+
* `auto-scaling-groups` (optional): Auto Scaling groups when creating a deployment group
4352

44-
#### Step 4 : [Pushing to S3](http://docs.aws.amazon.com/cli/latest/reference/deploy/push.html)
53+
#### Step 5 : [Pushing to S3](http://docs.aws.amazon.com/cli/latest/reference/deploy/push.html)
4554

4655
This step consists to push the application to S3.
4756

48-
The following configuration allows to configure this step :
57+
The following configuration allows to setup this step :
4958

50-
* `s3-bucket` (required) S3 Bucket
51-
* `s3-source` (optional) S3 Source. By default : _._
52-
* `s3-key` (optional) S3 Key. By default: _{application-name}_
59+
* `s3-bucket` (required): S3 Bucket
60+
* `s3-source` (optional): S3 Source. By default : _._
61+
* `s3-key` (optional): S3 Key. By default: _{application-name}_
5362

54-
#### Step 5 : [Registering Revision](http://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html)
63+
#### Step 6 : [Registering Revision](http://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html)
5564

5665
This step consists to register the revision in Code Deploy.
5766

58-
The following configuration allows to configure this step :
67+
The following configuration allows to setup this step :
5968

60-
* `revision` (optional) Revision of the application to deploy. By default: _{application-name}-{application-version}.zip_
61-
* `revision-description` (optional) Description of the revision of the application to deploy
69+
* `revision` (optional): Revision of the application to deploy. By default: _{application-name}-{application-version}.zip_
70+
* `revision-description` (optional): Description of the revision of the application to deploy
6271

63-
#### Step 6 : [Creating Deployment](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html)
72+
#### Step 7 : [Creating Deployment](http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html)
6473

6574
This final step consists to create the deployment in Code Deploy.
6675

67-
The following configuration allows to configure this step :
76+
The following configuration allows to setup this step :
6877

69-
* `deployment-description` (optional) Description of the deployment
70-
* `deployment-overview` (optional) Visualize the deployment. By default : _true_
78+
* `deployment-description` (optional): Description of the deployment
79+
* `deployment-overview` (optional): Visualize the deployment. By default : _true_
7180

7281
## Example
7382

@@ -77,10 +86,12 @@ The following example deploy an `hello` application on the deployment group `dev
7786
deploy:
7887
steps:
7988
- nhuray/aws-code-deploy:
89+
key: aws_access_key_id
90+
secret: aws_access_secret_id
8091
application-name: hello
8192
application-version: 1.1.0
8293
deployment-group-name: development
83-
s3-bucket: apps.mycompany.com
8494
service-role-arn: arn:aws:iam::89862646$091:role/CodeDeploy
8595
ec2-tag-filters: Key=app,Value=hello,Type=KEY_AND_VALUE Key=environment,Value=development,Type=KEY_AND_VALUE
96+
s3-bucket: apps.mycompany.com
8697
```

run.sh

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,24 @@ bold() { printf "${bold}%s${reset}\n" "$@"
4242
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@"
4343
}
4444

45-
46-
type_exists() {
47-
if [ $(type -P $1) ]; then
48-
return 0
49-
fi
50-
return 1
51-
}
52-
5345
jsonValue() {
5446
key=$1
5547
num=$2
5648
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$key'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
5749
}
5850

59-
# Check AWS is installed
60-
if ! type_exists 'aws'; then
61-
error 'AWS Cli is not installed on this box.'
62-
note 'Please install AWS Cli : https://github.com/EdgecaseInc/wercker-step-install-aws-cli'
51+
52+
# Check variables
53+
if [ -n "$WERCKER_AWS_CODE_DEPLOY_KEY" ]; then
54+
error "Please set the 'key' variable"
6355
exit 1
6456
fi
6557

58+
if [ -n "$WERCKER_AWS_CODE_DEPLOY_SECRET" ]; then
59+
error "Please set the 'secret' variable"
60+
exit 1
61+
fi
6662

67-
# Check variables
6863
if [ -z "$WERCKER_AWS_CODE_DEPLOY_APPLICATION_NAME" ]; then
6964
error "Please set the 'application-name' variable"
7065
exit 1
@@ -80,6 +75,48 @@ if [ -z "$WERCKER_AWS_CODE_DEPLOY_S3_BUCKET" ]; then
8075
exit 1
8176
fi
8277

78+
# ----- Install AWS Cli -----
79+
# see documentation : http://docs.aws.amazon.com/cli/latest/userguide/installing.html
80+
# ---------------------------
81+
set -e
82+
h1 "Installing AWS CLI"
83+
84+
sudo apt-get install unzip -y 2>&1
85+
86+
h2 'Downloading AWS CLI'
87+
wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip 2>&1 > /dev/null
88+
unzip awscli-bundle.zip 2>&1 > /dev/null
89+
success "Downloading AWS CLI succeeded"
90+
91+
h2 "Installing AWS CLI"
92+
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws 2>&1 > /dev/null
93+
rm -rf awscli-bundle*
94+
success "Installing AWS CLI (`aws --version`) ID succeeded"
95+
96+
set +e
97+
# ----- Configure -----
98+
# see documentation :
99+
# http://docs.aws.amazon.com/cli/latest/reference/configure/index.html
100+
# ----------------------
101+
set -e
102+
103+
h1 "Step 1: Configuring AWS"
104+
105+
h2 "Configuring AWS Access Key ID"
106+
CONFIGURE_KEY_OUTPUT=$(aws configure set aws_access_key_id $WERCKER_AWS_CODE_DEPLOY_KEY 2>&1)
107+
success "Configuring AWS Access Key ID succeeded"
108+
109+
h2 "Configuring AWS Access Key ID"
110+
CONFIGURE_SECRET_OUTPUT=$(aws configure set aws_secret_access_key $WERCKER_AWS_CODE_DEPLOY_SECRET 2>&1)
111+
success "Configuring AWS Secret Access Key succeeded"
112+
113+
if [ -n "$WERCKER_AWS_CODE_DEPLOY_REGION" ]; then
114+
h2 "Configuring AWS default region"
115+
CONFIGURE_REGION_OUTPUT=$(aws configure set default.region $WERCKER_AWS_CODE_DEPLOY_REGION 2>&1)
116+
success "Configuring AWS default region succeeded"
117+
fi
118+
119+
set +e
83120

84121
# ----- Application -----
85122
# see documentation :
@@ -91,7 +128,7 @@ APPLICATION_NAME="$WERCKER_AWS_CODE_DEPLOY_APPLICATION_NAME"
91128
APPLICATION_VERSION=${WERCKER_AWS_CODE_DEPLOY_APPLICATION_VERSION:-${WERCKER_GIT_COMMIT:0:7}}
92129

93130
# Check application exists
94-
h1 "Step 1: Defining application"
131+
h1 "Step 2: Defining application"
95132
h2 "Checking application '$APPLICATION_NAME' exists"
96133

97134
APPLICATION_EXISTS="aws deploy get-application --application-name $APPLICATION_NAME"
@@ -126,7 +163,7 @@ DEPLOYMENT_CONFIG_NAME=${WERCKER_AWS_CODE_DEPLOY_DEPLOYMENT_CONFIG_NAME:-CodeDep
126163
MINIMUM_HEALTHY_HOSTS=${WERCKER_AWS_CODE_DEPLOY_MINIMUM_HEALTHY_HOSTS:-type=FLEET_PERCENT,value=75}
127164

128165
# Ckeck deployment config exists
129-
h1 "Step 2: Defining deployment config"
166+
h1 "Step 3: Defining deployment config"
130167
h2 "Checking deployment config '$DEPLOYMENT_CONFIG_NAME' exists"
131168

132169
DEPLOYMENT_CONFIG_EXISTS="aws deploy get-deployment-config --deployment-config-name $DEPLOYMENT_CONFIG_NAME"
@@ -163,7 +200,7 @@ EC2_TAG_FILTERS="$WERCKER_AWS_CODE_DEPLOY_EC2_TAG_FILTERS"
163200
SERVICE_ROLE_ARN="$WERCKER_AWS_CODE_DEPLOY_SERVICE_ROLE_ARN"
164201

165202
# Ckeck deployment group exists
166-
h1 "Step 3: Defining deployment group"
203+
h1 "Step 4: Defining deployment group"
167204
h2 "Checking deployment group '$DEPLOYMENT_GROUP' exists for application '$APPLICATION_NAME'"
168205

169206
DEPLOYMENT_GROUP_EXISTS="aws deploy get-deployment-group --application-name $APPLICATION_NAME --deployment-group-name $DEPLOYMENT_GROUP"
@@ -217,7 +254,7 @@ if [ -n "$S3_KEY" ]; then
217254
fi
218255
S3_LOCATION="$S3_LOCATION/$REVISION"
219256

220-
h1 "Step 4: Pushing to S3"
257+
h1 "Step 5: Pushing to S3"
221258
PUSH_S3="aws deploy push --application-name $APPLICATION_NAME --s3-location $S3_LOCATION --source $S3_SOURCE"
222259
if [ -n "$REVISION_DESCRIPTION" ]; then
223260
PUSH_S3="$PUSH_S3 --description '$REVISION_DESCRIPTION'"
@@ -237,7 +274,7 @@ success "Pushing revision '$REVISION' to S3 succeeded"
237274
# ----- Register revision -----
238275
# see documentation : http://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html
239276
# ----------------------
240-
h1 "Step 5: Registering revision"
277+
h1 "Step 6: Registering revision"
241278

242279
# Build S3 Location
243280
BUNDLE_TYPE=${REVISION##*.}
@@ -272,7 +309,7 @@ success "Registering revision '$REVISION' succeeded"
272309
DEPLOYMENT_DESCRIPTION="$WERCKER_AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION"
273310
DEPLOYMENT_OVERVIEW=${WERCKER_AWS_CODE_DEPLOY_DEPLOYMENT_OVERVIEW:-true}
274311

275-
h1 "Step 6: Creating deployment"
312+
h1 "Step 7: Creating deployment"
276313
DEPLOYMENT="aws deploy create-deployment --application-name $APPLICATION_NAME --deployment-config-name $DEPLOYMENT_CONFIG_NAME --deployment-group-name $DEPLOYMENT_GROUP --s3-location $S3_LOCATION"
277314

278315
if [ -n "$DEPLOYMENT_DESCRIPTION" ]; then

wercker-step.yml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
name: aws-code-deploy
2-
version: 0.0.14
2+
version: 0.0.17
33
description: Deploy applications with AWS Code Deploy
4+
keywords:
5+
- aws
6+
- code-deploy
7+
properties:
8+
# Step 1: Configuring AWS
9+
key:
10+
type: string
11+
required: true
12+
secret:
13+
type: string
14+
required: true
15+
region:
16+
type: string
17+
required: false
18+
19+
# Step 2: Defining application
20+
application-name:
21+
type: string
22+
required: true
23+
application-version:
24+
type: string
25+
required: false
26+
27+
# Step 3 : Defining Deployment Config
28+
deployment-config-name:
29+
type: string
30+
required: false
31+
minimum-healthy-hosts:
32+
type: string
33+
required: false
34+
35+
# Step 4 : Defining Deployment Group
36+
deployment-group-name:
37+
type: string
38+
required: true
39+
service-role-arn:
40+
type: string
41+
required: false
42+
ec2-tag-filters:
43+
type: string
44+
required: false
45+
auto-scaling-groups:
46+
type: string
47+
required: false
48+
49+
# Step 5 : Pushing to S3
50+
s3-bucket:
51+
type: string
52+
required: true
53+
s3-source:
54+
type: string
55+
required: false
56+
s3-key:
57+
type: string
58+
required: false
59+
60+
# Step 6 : Registering Revision
61+
revision:
62+
type: string
63+
required: false
64+
revision-description:
65+
type: string
66+
required: false
67+
68+
# Step 7 : Creating Deployment
69+
deployment-description:
70+
type: string
71+
required: false
72+
deployment-overview:
73+
type: boolean
74+
required: false

wercker.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
box: wercker/default
2+
build:
3+
steps:
4+
- validate-wercker-step

0 commit comments

Comments
 (0)