/ecs_deployer

This package provides service deployment function of ECS.

Primary LanguageRubyMIT LicenseMIT

EcsDeployer

Gem Version Test Coverage Code Climate CircleCI

Description

Deploy Docker container on AWS ECS..

Installation

Add this line to your application's Gemfile:

gem 'ecs_deployer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ecs_deployer

Task definition

Write task definition in YAML format. For available parameters see Task Definition Parameters.

container_definitions:
- name: wordpress
  links:
  - mysql
  image: wordpress
  essential: true
  port_mappings:
  - container_port: 80
    hostPort: 80
  memory: 512
  cpu: 10
- environment:
  - name: MYSQL_ROOT_PASSWORD
    value: password
  name: mysql
  image: mysql
  cpu: 10
  memory: 512
  essential: true
family: hello_world

Encrypt of environment variables

environment parameter supports KMS encrypted values. Encrypted values must be enclosed in ${XXX}.

- environment:
  - name: MYSQL_ROOT_PASSWORD
    value: ${fiSAIfIFxd...}

Values are decrypted when task is created.

Usage

API

This sample file is in spec/fixtures/task.yml.

deployer = EcsDeployer::Client.new
deployer.register_task('development.yml')
deployer.update_service('cluster', 'development')

{{xxx}} parameter is construed variable.

container_definitions:
- name: wordpress
  image: wordpress:{{tag}}
deployer.register_task('development.yml', tag: 'latest')

CLI

Register new task

$ bundle exec ecs_deployer task-register --path=spec/fixtures/task.yml --replace-variables=tag:latest
Registered task: arn:aws:ecs:ap-northeast-1:xxx:task-definition/hello_world:latest

Encrypt environment value

$ bundle exec ecs_deployer encrypt --master-key=master --value='test'
Encrypted value: ${xxx}

Decrypt environment value

$ bundle exec ecs_deployer decrypt --value='${xxx}'
Decrypted value: xxx

Update service

$ bundle exec ecs_deployer update-service --cluster=xxx --service=xxx --wait --timeout=600
Start deploying...
Deploying... [0/1] (20 seconds elapsed)
New task: arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:68
------------------------------------------------------------------------------------------------
  arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:67 [RUNNING]
------------------------------------------------------------------------------------------------
You can stop process with Ctrl+C. Deployment will continue.

Deploying... [1/2] (40 seconds elapsed)
New task: arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:68
------------------------------------------------------------------------------------------------
  arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:68 [RUNNING]
  arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:67 [RUNNING]
------------------------------------------------------------------------------------------------
You can stop process with Ctrl+C. Deployment will continue.

Service update succeeded. [1/1]
New task definition: arn:aws:ecs:ap-northeast-1:xxxx:task-definition/sandbox-development:68
Update service: arn:aws:ecs:ap-northeast-1:xxxx:service/development

License

MIT