- Notifications
You must be signed in to change notification settings - Fork12
Tool to build Docker cluster composition for Amazon EC2 Container Service(ECS)
License
openfresh/ecs-formation
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ecs-formation is a tool for defining several Docker continers and clusters onAmazon 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.
- Support ELB(Classic Load Balancer) and ALB(Application Load Balancer)
- Service Auto Scaling
- Task Placement Policy
ecs-formation is written by Go. Please rungo get
.
$ go get github.com/openfresh/ecs-formation
ecs-formation usecobra. It supports yaml configuration.
Prepare~/.ecs-formation.yaml
for project configuration.
project_dir: ~/your_project_dir/aws_region:us-east-1
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.ymlnginx: image: nginx:latest ports: - 80:80 environment: PARAM1: value1 PARAM2: value2 links: - api memory_reservation: 256 cpu_units: 512 essential:trueapi: image: your_namespace/your-api:latest ports: - 8080:8080 memory: 1024 cpu_units: 1024 essential:true links: - redisredis: 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 istest-cluster
, you need to maketest-cluster.yml
.
(path-to-path/test-ecs-formation/service) $ vim test-cluster.ymltest-service: task_definition: test-definition desired_count: 1 role: your-ecs-elb-role load_balancers: - name: test-elb container_name: nginx container_port: 80 autoscaling: target: min_capacity: 0 max_capacity: 1 role: arn:aws:iam::your_account_id:role/ecsAutoscaleRole
In case of ALB, you should specifytarget_group_arn
.
(path-to-path/test-ecs-formation/service) $ vim test-cluster.ymltest-service: task_definition: test-definition desired_count: 1 role: your-ecs-elb-role load_balancers: - target_group_arn: test-target-group-arn container_name: nginx container_port: 80
If you modify value ofdesired_count
by AWS Management Console or aws-cli, you'll fear override value ofdesired_count
by ecs-formation. This value should be flexibly changed in the operation.
Ifkeep_desired_count
istrue
, keep currentdesired_count
at updating service.
(path-to-path/test-ecs-formation/service) $ vim test-cluster.ymltest-service: task_definition: test-definition desired_count: 1 keep_desired_count:true
Supportsplacement_constraints
andplacement_strategy
. If you update these options, it's necessary to rebuild service once.
(path-to-path/test-ecs-formation/service) $ vim test-cluster.ymltest-service: task_definition: test-definition desired_count: 1 keep_desired_count:true placement_constraints: - type: memberOf expression:"attribute:ecs.instance-type =~ t2.*" placement_strategy: - type: spread field:"attribute:ecs.availability-zone"
Show update plan.
(path-to-path/test-ecs-formation $ ecs-formation task plan --all(path-to-path/test-ecs-formation $ ecs-formation task plan -t test_definition
Apply all definition.
(path-to-path/test-ecs-formation $ ecs-formation task apply --all(path-to-path/test-ecs-formation $ ecs-formation task apply -t test_definition
Show update plan. Required cluster.
(path-to-path/test-ecs-formation $ ecs-formation service plan -c test-cluster --all
Apply all services.
(path-to-path/test-ecs-formation $ ecs-formation service apply -c test-cluster --all
Specify cluster and service.
(path-to-path/test-ecs-formation $ ecs-formation service apply -c test-cluster -s test-service
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.ymlblue: cluster: test-blue service: test-service autoscaling_group: test-blue-asggreen: cluster: test-green service: test-service autoscaling_group: test-green-asgprimary_elb: test-elb-primarystandby_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 -g test-bluegreen
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 -g test-bluegreen
If autoscaling group have several different classic ELB, you should specify array property ofchain_elb
. ecs-formation can swapchain_elb
ELB group with main ELB group at the same time.
(path-to-path/test-ecs-formation/bluegreen) $vimtest-bluegreen.ymlblue:cluster:test-blueservice:test-serviceautoscaling_group:test-blue-asggreen:cluster:test-greenservice:test-serviceautoscaling_group:test-green-asgprimary_elb:test-elb-primarystandby_elb:test-elb-standbychain_elb: -primary_elb:test-internal-elb-primarystandby_elb:test-internal-elb-standby
In case of ALB(Application Load Balancer), as follows.
(path-to-path/test-ecs-formation/bluegreen) $vimtest-bluegreen.ymlblue:cluster:test-blueservice:test-serviceautoscaling_group:test-blue-asggreen:cluster:test-greenservice:test-serviceautoscaling_group:test-green-asgelbv2:target_groups: -primary_group:test-internal-primarystandby_group:test-internal-default
You can use custom parameters. Define parameters in yaml file(task, service, bluegreen) as follows.
nginx:image:openfresh/nginx:${NGINX_VERSION}ports: -80:${NGINX_PORT}
You can set value for these parameters by using-p
option.
ecs-formation task -p NGINX_VERSION=1.0 -p NGINX_PORT=80 plan -t your-web-task
Also, support default parameter value.
nginx:image:openfresh/nginx:${NGINX_VERSION|latest}ports: -80:${NGINX_PORT|80}
You can useenv_file
like docker-compose.https://docs.docker.com/compose/compose-file/#env-file
nginx:image:openfresh/nginx:${NGINX_VERSION}ports: -80:${NGINX_PORT}env_file: -./test1.env - ../test2.env
SeeLICENSE.
Copyright © FRESH!. All Rights Reserved.
About
Tool to build Docker cluster composition for Amazon EC2 Container Service(ECS)