ecs-formation is a tool for defining several Docker continers and clusters on Amazon EC2 Container Service(ECS).
- Define services on ECS cluster, and Task Definitions.
- Supports YAML definition like docker-compose. Be able to run ecs-formation if copy docker-compose.yml(formerly fig.yml).
- Manage ECS Services and Task Definitions by AWS API.
ecs-formation is written by Go. Please run go get
.
$ go get github.com/stormcat24/ecs-formation
ecs-formation requires environment variables to run, as follows.
- AWS_ACCESS_KEY: AWS access key
- AWS_SECRET_ACCESS_KEY: AWS secret access key
- AWS_REGION: Target AWS region name
Make working directory for ecs-formation. This working directory should be managed by Git.
$ mkdir -p path-to-path/test-ecs-formation
$ mkdir -p path-to-path/test-ecs-formation/task
$ mkdir -p path-to-path/test-ecs-formation/service
$ mkdir -p path-to-path/test-ecs-formation/bluegreen
You need to create ECS cluster in advance. And also, ECS instance must be join in ECS cluster.
Make Task Definitions file in task directory. This file name is used as ECS Task Definition name.
(path-to-path/test-ecs-formation/task) $ vim test-definition.yml
nginx:
image: nginx:latest
ports:
- 80:80
environment:
PARAM1: value1
PARAM2: value2
links:
- api
memory: 512
cpu_units: 512
essential: true
api:
image: your_namespace/your-api:latest
ports:
- 8080:8080
memory: 1024
cpu_units: 1024
essential: true
links:
- redis
redis:
image: redis:latest
ports:
- 6379:6379
memory: 512
cpu_units: 512
essential: true
Make Service Definition file in cluster directory. This file name must be equal ECS cluster name.
For example, if target cluster name is test-cluster
, you need to make test-cluster.yml
.
(path-to-path/test-ecs-formation/service) $ vim test-cluster.yml
test-service:
task_definition: test-definition
desired_count: 1
role: your-ecs-elb-role
load_balancers:
-
name: test-elb
container_name: nginx
container_port: 80
Show update plan.
(path-to-path/test-ecs-formation $ ecs-formation task plan
Apply definition.
(path-to-path/test-ecs-formation $ ecs-formation task apply
Show update plan.
(path-to-path/test-ecs-formation $ ecs-formation service plan
Apply definition.
(path-to-path/test-ecs-formation $ ecs-formation service apply
ecs-formation supports blue-green deployment.
- Requires two ECS cluster. Blue and Green.
- Requires two ELB. Primary ELB and Standby ELB.
- ECS cluster should be built by EC2 Autoscaling group.
Make management file of Blue Green Deployment file in bluegreen directory.
(path-to-path/test-ecs-formation/bluegreen) $ vim test-bluegreen.yml
blue:
cluster: test-blue
service: test-service
autoscaling_group: test-blue-asg
green:
cluster: test-green
service: test-service
autoscaling_group: test-green-asg
primary_elb: test-elb-primary
standby_elb: test-elb-standby
Show blue green deployment plan.
(path-to-path/test-ecs-formation $ ecs-formation bluegreen plan
Apply blue green deployment.
(path-to-path/test-ecs-formation $ ecs-formation bluegreen apply
if with --nodeploy
option, not update services. Only swap ELB on blue and green groups.
(path-to-path/test-ecs-formation $ ecs-formation bluegreen apply --nodeploy
If autoscaling group have several different ELB, you should specify array property of chain_elb
. ecs-formation can swap chain_elb
ELB group with main ELB group at the same time.
(path-to-path/test-ecs-formation/bluegreen) $ vim test-bluegreen.yml
blue:
cluster: test-blue
service: test-service
autoscaling_group: test-blue-asg
green:
cluster: test-green
service: test-service
autoscaling_group: test-green-asg
primary_elb: test-elb-primary
standby_elb: test-elb-standby
chain_elb:
- primary_elb: test-internal-elb-primary
standby_elb: test-internal-elb-standby
See LICENSE.
Copyright © Akinori Yamada(@stormcat24). All Rights Reserved.