Skip to content

Commit 8121353

Browse files
Some fixes
Final fixes Cleanup (#1) * Cleanup * remove sensitive data
1 parent e5cebcb commit 8121353

File tree

5 files changed

+68
-31
lines changed

5 files changed

+68
-31
lines changed

.circleci/config.yml

Whitespace-only changes.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ RUN apk -uv add --no-cache groff jq less && \
77

88
ADD ecs-cf-deploy /usr/local/bin/
99

10-
CMD ["ecs-cf-deploy"]
10+
CMD sh

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2019 mycs GmbH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ecs-cf-deploy
2+
3+
> Dockerized script to deploy an ECS service based on cloudformation stacks.
4+
5+
It's meant to be used in a CI environment.
6+
7+
`ecs-cf-deploy -s $SERVICE -c $CLUSTER -a $ACCOUNT -ar $ROLE -r $AWS_DEFAULT_REGION`

ecs-cf-deploy

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
43
VERSION="0.1.0"
4+
VERBOSE=false
55
AWS_CLI=$(which aws)
66
AWS_ECS="$AWS_CLI --output json ecs"
77
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-eu-west-1}
@@ -11,22 +11,34 @@ AWS_ASSUME_ROLE=true
1111
function usage() {
1212
cat <<EOM
1313
-- ecs-cf-deploy --
14+
1415
Simple script to force a deployement of an ECS service based on a clouformation stack.
1516
1617
Required arguments:
17-
-c | --cluster-name Name of Name of cloudformation stack containing the ecs cluster to deploy
18-
-s | --service-name Name of cloudformation stack containing the service to deploy
19-
-k | --aws-access-key AWS Access Key ID. May also be set as environment variable AWS_ACCESS_KEY_ID
20-
-s | --aws-secret-key AWS Secret Access Key. May also be set as environment variable AWS_SECRET_ACCESS_KEY
21-
-r | --region AWS Region Name. May also be set as environment variable AWS_DEFAULT_REGION
22-
-p | --profile AWS Profile to use - If you set this aws-access-key, aws-secret-key and region are needed
18+
-c | --cluster-name Name of cloudformation stack containing the ecs cluster to deploy
19+
-s | --service-name Name of cloudformation stack containing the service to deploy
20+
-a | --account ID of the account to assume the role
21+
-ar | --assume-role-name Name of the role to assume
22+
23+
Optional arguments:
24+
-k | --aws-access-key AWS Access Key ID. May also be set as environment variable AWS_ACCESS_KEY_ID
25+
-s | --aws-secret-key AWS Secret Access Key. May also be set as environment variable AWS_SECRET_ACCESS_KEY
26+
-r | --region AWS Region Name. May also be set as environment variable AWS_DEFAULT_REGION or use the default `eu-west-1`
27+
-v | --verbose Display debugging information (basically each command)
2328
2429
Requirements:
2530
aws: AWS Command Line Interface
2631
jq: Command-line JSON processor
2732
28-
EOM
33+
Example:
34+
ecs-cf-deploy -s example-api -c example-cluster -a 1234465780 -ar assumeRoleName -r us-west-1
2935
36+
Author:
37+
Nicolas Ritouet <[email protected]>
38+
39+
License:
40+
MIT (check LICENSE.md)
41+
EOM
3042
exit 3
3143
}
3244

@@ -56,15 +68,15 @@ function assumeRoleClean() {
5668
}
5769

5870
function getClusterName() {
59-
export CLUSTER=$($AWS_CLI cloudformation describe-stacks \
71+
export ECS_CLUSTER_NAME=$($AWS_CLI cloudformation describe-stacks \
6072
--stack-name ${ECS_CLUSTER_STACK} \
6173
--query 'Stacks[0].Outputs[?OutputKey==`Cluster`].OutputValue' \
6274
--output text --region ${AWS_DEFAULT_REGION}
6375
)
6476
}
6577

6678
function getServiceName() {
67-
export SERVICE=$($AWS_CLI cloudformation describe-stacks \
79+
export ECS_SERVICE_NAME=$($AWS_CLI cloudformation describe-stacks \
6880
--stack-name ${ECS_SERVICE_STACK} \
6981
--query 'Stacks[0].Outputs[?OutputKey==`Service`].OutputValue' \
7082
--output text --region ${AWS_DEFAULT_REGION}
@@ -73,8 +85,10 @@ function getServiceName() {
7385

7486

7587
function updateService() {
76-
echo "Deploying on cluster $CLUSTER service $SERVICE"
77-
`$AWS_ECS update-service --cluster $CLUSTER --service $SERVICE --force-new-deployment`
88+
if [ $VERBOSE == true ]; then
89+
echo "Deploying on cluster '$ECS_CLUSTER_NAME' service '$ECS_SERVICE_NAME'";
90+
fi
91+
$AWS_ECS update-service --cluster $ECS_CLUSTER_NAME --service $ECS_SERVICE_NAME --force-new-deployment
7892
}
7993

8094

@@ -97,14 +111,18 @@ function assertRequiredArgumentsSet() {
97111
AWS_ECS="$AWS_ECS --profile $AWS_PROFILE"
98112
fi
99113

100-
if [ $ECS_SERVICE_STACK == false ]; then
114+
if [ -z "${ECS_SERVICE_STACK:-}" ]; then
101115
echo "SERVICE is required. You can pass the value using -s or --service-name"
102116
exit 5
103117
fi
104-
if [ $ECS_SERVICE_STACK != false ] && [ $ECS_CLUSTER_STACK == false ]; then
118+
if [ ! -z "${ECS_SERVICE_STACK:-}" ] && [ -z "${ECS_CLUSTER_STACK:-}" ]; then
105119
echo "CLUSTER is required. You can pass the value using -c or --cluster"
106120
exit 6
107121
fi
122+
if [ -z "${ACCOUNT_ID:-}" ]; then
123+
echo "ACCOUNT is required. You can pass the value using -a or --account"
124+
exit 6
125+
fi
108126

109127
}
110128

@@ -130,32 +148,32 @@ do
130148
key="$1"
131149

132150
case $key in
133-
-k|--aws-access-key)
134-
AWS_ACCESS_KEY_ID="$2"
151+
-c|--cluster-name)
152+
ECS_CLUSTER_STACK="$2"
135153
shift # past argument
136154
;;
137-
-s|--aws-secret-key)
138-
AWS_SECRET_ACCESS_KEY="$2"
155+
-s|--service-name)
156+
ECS_SERVICE_STACK="$2"
139157
shift # past argument
140158
;;
141-
-r|--region)
142-
AWS_DEFAULT_REGION="$2"
159+
-ar|--assume-role-name)
160+
CROSS_ACCOUNT_ROLE="$2"
143161
shift # past argument
144162
;;
145-
-p|--profile)
146-
AWS_PROFILE="$2"
163+
-a|--account)
164+
ACCOUNT_ID="$2"
147165
shift # past argument
148166
;;
149-
--aws-instance-profile)
150-
echo "--aws-instance-profile is not yet in use"
151-
AWS_IAM_ROLE=true
167+
-k|--aws-access-key)
168+
AWS_ACCESS_KEY_ID="$2"
169+
shift # past argument
152170
;;
153-
-c|--cluster-name)
154-
ECS_CLUSTER_STACK="$2"
155-
shift
171+
-s|--aws-secret-key)
172+
AWS_SECRET_ACCESS_KEY="$2"
173+
shift # past argument
156174
;;
157-
-s|--service-name)
158-
ECS_SERVICE_STACK="$2"
175+
-r|--region)
176+
AWS_DEFAULT_REGION="$2"
159177
shift # past argument
160178
;;
161179
-v|--verbose)
@@ -166,6 +184,7 @@ do
166184
exit 0
167185
;;
168186
*)
187+
echo "Found nothing, will display usage and exit"
169188
usage
170189
exit 2
171190
;;
@@ -184,6 +203,8 @@ if [[ "$AWS_ASSUME_ROLE" != false ]]; then
184203
assumeRole
185204
fi
186205

206+
getClusterName
207+
getServiceName
187208
updateService
188209

189210

0 commit comments

Comments
 (0)