ecs_ship 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ecs_ship.gemspec +25 -0
- data/lib/ecs_ship.rb +5 -0
- data/lib/ecs_ship/deploy.rb +106 -0
- data/lib/ecs_ship/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d88c692cd4be6fbef6cd54127312bfa144aec563
|
4
|
+
data.tar.gz: a61739d15659e7661da5402a449dc8564dc213e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce90e8b7141410d89fb29d05191856fabe56248645434b7acd0f7b84584502059b658fb5b2c6711e3f017d6edc8f8c48152d0d4e8feb0b1502e4d58c7f1d402f
|
7
|
+
data.tar.gz: 7dadb7d5ce2cea40c48b35894451f7ecf9dc4ccc8b77dc6d46ae5ed468b3506dce34bcfbf141d0beb613cf603145b08b90240cf1e53e78aee72d8dd157641d87
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ritani
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# EcsShip
|
2
|
+
|
3
|
+
Provides a shipping script for AWS ECS dockerized apps.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
This requires the AWS CLI tools to be configured on the machine running the script. [Learn how](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile, probably in the `development` group:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ecs_ship'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ecs_ship
|
22
|
+
|
23
|
+
Create a script (probably in `bin/deploy`) similar to the following:
|
24
|
+
|
25
|
+
#!/usr/bin/env ruby
|
26
|
+
|
27
|
+
gem 'ecs_ship'
|
28
|
+
require 'ecs_ship/deploy'
|
29
|
+
|
30
|
+
args = [ARGV[0], 'example_aws_ecs_service_name', 'example_aws_ecs_task_name', 'example_docker_image_name', ARGV[1]].compact
|
31
|
+
EcsShip::Deploy.new(*args).deploy
|
32
|
+
|
33
|
+
## Usage examples
|
34
|
+
|
35
|
+
* `./bin/deploy help`
|
36
|
+
* `./bin/deploy my_cluster_name_for_this_app` (keeps same docker tag as current)
|
37
|
+
* `./bin/deploy my_cluster_name_for_this_app` `latest`
|
38
|
+
* `./bin/deploy my_cluster_name_for_this_app` `new_docker_tag`
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/NEWECX/ecs_ship.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ecs_ship"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/ecs_ship.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ecs_ship/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ecs_ship"
|
8
|
+
spec.version = EcsShip::VERSION
|
9
|
+
spec.authors = ["Seth Ringling"]
|
10
|
+
spec.email = ["sethr@ritani.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides a shipping script for AWS ECS dockerized applications}
|
13
|
+
spec.description = %q{EZ-Deployment of a dockerized app in AWS!}
|
14
|
+
spec.homepage = "https://github.com/NEWECX/ecs_ship"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
data/lib/ecs_ship.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module EcsShip
|
4
|
+
class Deploy
|
5
|
+
def initialize(cluster_name, service_name, task_name, docker_image_name, docker_tag = 'latest')
|
6
|
+
@cluster_name = cluster_name
|
7
|
+
@docker_tag = docker_tag
|
8
|
+
@service_name = service_name
|
9
|
+
@task_name = task_name
|
10
|
+
@docker_image_name = docker_image_name
|
11
|
+
|
12
|
+
raise "Invalid cluster name, valid clusters are: #{cluster_names}" unless cluster_names.any?{|available_name| available_name == cluster_name}
|
13
|
+
end
|
14
|
+
|
15
|
+
def deploy
|
16
|
+
stop_existing_task
|
17
|
+
rev_task_version
|
18
|
+
start_updated_task
|
19
|
+
|
20
|
+
puts "Shipped! #{@service_name} should now be running #{versioned_task_name}"
|
21
|
+
|
22
|
+
rescue StandardError => e
|
23
|
+
syntax
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop_existing_task
|
28
|
+
puts 'Stopping existing task... yes this is a downtime deployment'
|
29
|
+
|
30
|
+
running_task_arns = JSON.parse(`aws ecs list-tasks --cluster #{@cluster_name} --family #{@task_name} --desired-status RUNNING`)['taskArns']
|
31
|
+
running_task_arns.each do |task_arn|
|
32
|
+
system("aws ecs stop-task --cluster #{@cluster_name} --task #{task_arn}")
|
33
|
+
end
|
34
|
+
|
35
|
+
success = system("aws ecs update-service --cluster #{@cluster_name} --service #{@service_name} --desired-count 0")
|
36
|
+
unless success
|
37
|
+
raise 'Failed to stop existing task'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def rev_task_version
|
42
|
+
begin
|
43
|
+
puts 'Creating new task definition with updated version number'
|
44
|
+
|
45
|
+
task_definition = JSON.parse(`aws ecs describe-task-definition --task-definition #{@task_name}`)['taskDefinition']
|
46
|
+
|
47
|
+
@revision = task_definition['revision'] + 1
|
48
|
+
|
49
|
+
registerable_params = [:family, :taskRoleArn, :networkMode, :containerDefinitions, :volumes, :placementConstraints]
|
50
|
+
|
51
|
+
task_definition['containerDefinitions'].map! do |container_definition|
|
52
|
+
if container_definition['image'].include?(@docker_image_name)
|
53
|
+
container_definition['image'] = "#{@docker_image_name}:#{@docker_tag}"
|
54
|
+
end
|
55
|
+
container_definition
|
56
|
+
end
|
57
|
+
|
58
|
+
File.open(temp_definition_path, 'w') do |file|
|
59
|
+
file.write(task_definition.select{|k, v| registerable_params.include?(k.to_sym)}.to_json)
|
60
|
+
end
|
61
|
+
|
62
|
+
success = system("aws ecs register-task-definition --family #{@task_name} --cli-input-json file://#{temp_definition_path}")
|
63
|
+
unless success
|
64
|
+
raise 'Failed to rev task version'
|
65
|
+
end
|
66
|
+
ensure
|
67
|
+
File.delete(temp_definition_path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def temp_definition_path
|
72
|
+
'temp_definition_delete_me.json'
|
73
|
+
end
|
74
|
+
|
75
|
+
def start_updated_task
|
76
|
+
puts 'Starting service back up with newly created task definition'
|
77
|
+
|
78
|
+
success = system("aws ecs update-service --cluster #{@cluster_name} --service #{@service_name} --desired-count 1 --task-definition #{versioned_task_name}")
|
79
|
+
unless success
|
80
|
+
raise 'Failed to start back up the updated service'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def versioned_task_name
|
85
|
+
"#{@task_name}:#{@revision}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def all_clusters
|
89
|
+
@all_clusters ||= JSON.parse(`aws ecs describe-clusters --clusters #{cluster_arns.join(' ')}`)['clusters']
|
90
|
+
end
|
91
|
+
|
92
|
+
def cluster_arns
|
93
|
+
JSON.parse(`aws ecs list-clusters`)['clusterArns']
|
94
|
+
end
|
95
|
+
|
96
|
+
def cluster_names
|
97
|
+
all_clusters.map{|c| c['clusterName']}
|
98
|
+
end
|
99
|
+
|
100
|
+
def syntax
|
101
|
+
puts "Arguments: #{method(:initialize).parameters.map{|p| "#{p.last} (#{p.first})"}.join(' ')}"
|
102
|
+
puts "\n"
|
103
|
+
puts "Valid stacks: #{cluster_names}}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecs_ship
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Ringling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: EZ-Deployment of a dockerized app in AWS!
|
56
|
+
email:
|
57
|
+
- sethr@ritani.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- ecs_ship.gemspec
|
70
|
+
- lib/ecs_ship.rb
|
71
|
+
- lib/ecs_ship/deploy.rb
|
72
|
+
- lib/ecs_ship/version.rb
|
73
|
+
homepage: https://github.com/NEWECX/ecs_ship
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.12
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Provides a shipping script for AWS ECS dockerized applications
|
97
|
+
test_files: []
|