|
| 1 | +[](https://travis-ci.org/monade/ecs-deploy-cli) |
| 2 | + |
| 3 | +# ECS Deploy CLI |
| 4 | + |
| 5 | +A CLI + DSL to simplify deployments on ECS. |
| 6 | + |
| 7 | +It's partial, incomplete and unstable, DON'T use yet. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Simply add the gem to your Gemfile |
| 12 | + |
| 13 | +```ruby |
| 14 | + gem 'ecs-deploy-cli', github: 'monade/ecs-deploy-cli' |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +First, define a ECSFile in your project, to design your ECS cluster. |
| 20 | + |
| 21 | +**The cluster and the service must be already there!** |
| 22 | + |
| 23 | +Example of a Rails app on ECS: |
| 24 | +```ruby |
| 25 | +aws_profile_id ENV['AWS_PROFILE_ID'] |
| 26 | +aws_region ENV['AWS_REGION'] |
| 27 | + |
| 28 | +repository ENV['REPO_URL'] |
| 29 | +version ENV['CURRENT_VERSION'] |
| 30 | + |
| 31 | +cluster '' |
| 32 | + |
| 33 | +# This is used as a template for the next two containers, it will not be used inside a task |
| 34 | +container :base_container do |
| 35 | + load_envs 'envs/base.yml' |
| 36 | + load_envs 'envs/production.yml' |
| 37 | + secret key: 'RAILS_MASTER_KEY', value: 'railsMasterKey' # Taking the secret from AWS System Manager |
| 38 | + working_directory '/app' |
| 39 | + cloudwatch 'yourproject' # Configuring cloudwatch logs |
| 40 | +end |
| 41 | + |
| 42 | +# The rails web application |
| 43 | +container :web, extends: :base_container do |
| 44 | + cpu 512 |
| 45 | + memory limit: 3584, reservation: 3584 |
| 46 | + command 'bundle', 'exec', 'puma', '-C', 'config/puma.rb' |
| 47 | + |
| 48 | + expose host_port: 0, protocol: 'tcp', container_port: 3000 |
| 49 | +end |
| 50 | + |
| 51 | +# The rails job worker |
| 52 | +container :worker, extends: :base_container do |
| 53 | + cpu 1536 |
| 54 | + memory limit: 3584, reservation: 3584 |
| 55 | + command 'bundle', 'exec', 'shoryuken', '-C', 'config/shoryuken.yml', '-R' |
| 56 | +end |
| 57 | + |
| 58 | +# A container to exec cron jobs |
| 59 | +container :cron, extends: :base_container do |
| 60 | + command 'rails', 'runner' |
| 61 | +end |
| 62 | + |
| 63 | +# The main task, having two containers |
| 64 | +task :yourproject do |
| 65 | + containers :web, :worker |
| 66 | + cpu 2048 |
| 67 | + memory 3584 |
| 68 | + |
| 69 | + tag 'product', 'yourproject' |
| 70 | +end |
| 71 | + |
| 72 | +# The main service |
| 73 | +service :'yourproject-service' do |
| 74 | + task :yourproject |
| 75 | +end |
| 76 | + |
| 77 | +# A task for cron jobs |
| 78 | +task :'yourproject-cron' do |
| 79 | + containers :cron |
| 80 | + cpu 256 |
| 81 | + memory 1024 |
| 82 | + |
| 83 | + tag 'product', 'yourproject' |
| 84 | +end |
| 85 | + |
| 86 | +# Scheduled tasks using Cloudwatch Events / Eventbridge |
| 87 | +cron :scheduled_emails do |
| 88 | + task :'yourproject-cron' do |
| 89 | + # Overrides |
| 90 | + container :web do |
| 91 | + command 'rails', 'cron:exec' |
| 92 | + end |
| 93 | + end |
| 94 | + # Examples: |
| 95 | + # every 1.hour |
| 96 | + run_at '0 * * * ? *' |
| 97 | +end |
| 98 | +``` |
| 99 | + |
| 100 | +Now create your deploy script: |
| 101 | +```ruby |
| 102 | +require 'ecs_deploy_cli' |
| 103 | + |
| 104 | +configuration = EcsDeployCli::FileParser.load('ECSFile') |
| 105 | +# This will update all your services and tasks to fit the new configuration |
| 106 | +configuration.apply! |
| 107 | +``` |
| 108 | + |
| 109 | +### TODOs |
| 110 | + |
| 111 | +- Scheduled tasks implementation |
| 112 | +- More configuration options |
| 113 | +- Create the service if not present |
| 114 | +- An actual CLI using Thor |
| 115 | +- Specs |
0 commit comments