eb-docker-deployer 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/bin/ebd +5 -0
- data/eb-docker-deployer.gemspec +30 -0
- data/lib/deploy.rb +16 -0
- data/lib/deploy/checks.rb +26 -0
- data/lib/deploy/commands.rb +54 -0
- data/lib/deploy/output.rb +53 -0
- data/lib/deploy/runner.rb +83 -0
- data/lib/deploy/utility.rb +9 -0
- data/lib/deploy/version.rb +3 -0
- data/lib/deploy/versions.rb +24 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa45d2cf4d764e1b5699e607560d83abd3343a25
|
4
|
+
data.tar.gz: 9f47d29b33594203ec4571e52772c14820815128
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae26631bcfe92e32aa7ca4260b80507a97fd110447081c651ddf7378d7bd3cb523a664dbb16726d42bfc93d495edd9c53433c023f07615152498baad73523745
|
7
|
+
data.tar.gz: e630180943cca2a2436fcd5648555d81726b32780e0cb64401251a69f63a6a85f5406b3ad83849f17699a601d584177d12b379024cd7e787deaf09688e40288e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Tim
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
Add this line to your application's Gemfile:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'eb-docker-deployer'
|
7
|
+
```
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install eb-docker-deployer
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
`ebd deploy (add options)`
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( https://github.com/thogg4/eb-docker-deployer/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/ebd
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eb-docker-deployer"
|
8
|
+
spec.version = Deploy::VERSION
|
9
|
+
spec.authors = ["Tim"]
|
10
|
+
spec.email = ["thogg4@gmail.com"]
|
11
|
+
spec.summary = 'deploy with docker and aws eb'
|
12
|
+
spec.description = 'deploy with docker and aws eb'
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ['ebd']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency 'thor'
|
25
|
+
spec.add_dependency 'highline'
|
26
|
+
|
27
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
28
|
+
|
29
|
+
spec.add_dependency 'slack-notifier'
|
30
|
+
end
|
data/lib/deploy.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'highline/import'
|
3
|
+
require 'slack-notifier'
|
4
|
+
require 'aws-sdk'
|
5
|
+
|
6
|
+
require 'deploy/output'
|
7
|
+
require 'deploy/commands'
|
8
|
+
require 'deploy/checks'
|
9
|
+
require 'deploy/versions'
|
10
|
+
require 'deploy/utility'
|
11
|
+
|
12
|
+
require 'deploy/runner'
|
13
|
+
|
14
|
+
module Deploy
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'deploy/utility'
|
2
|
+
|
3
|
+
module Deploy
|
4
|
+
module Checks
|
5
|
+
include Deploy::Utility
|
6
|
+
|
7
|
+
def check_setup
|
8
|
+
(shout('docker not installed'); exit(1)) unless command?('docker')
|
9
|
+
(shout('eb command not installed'); exit(1)) unless command?('eb')
|
10
|
+
(shout('elasticbeanstalk not configured for this project. run "eb init".'); exit(1)) unless File.exist?('.elasticbeanstalk')
|
11
|
+
(shout('AWS credentials not configured.'); exit(1)) unless ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION']
|
12
|
+
(shout('ENV DOCKER_REPO not set'); exit(1)) unless ENV['DOCKER_REPO']
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_rollback_version(version, environment)
|
16
|
+
check_version(version, environment)
|
17
|
+
(shout('You can only rollback to a previous version'); exit(1)) unless application_versions_array.include?(version)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_version(version, environment)
|
21
|
+
(shout('You must pass a version with -v'); exit(1)) unless version
|
22
|
+
(shout('You are currently on that version'); exit(1)) if current_version_for_environment(environment) == version
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'deploy/utility'
|
2
|
+
|
3
|
+
module Deploy
|
4
|
+
module Commands
|
5
|
+
include Deploy::Utility
|
6
|
+
|
7
|
+
def build_image(repo, tag)
|
8
|
+
shout "Building Docker Image: #{repo}:#{tag}"
|
9
|
+
command = "docker build -t #{repo}:#{tag} ."
|
10
|
+
exit(1) unless system(command)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_deploy_zip_file
|
14
|
+
# to create the archive correctly we must set up a fake git user
|
15
|
+
shout "Creating fake local git user"
|
16
|
+
system "git config user.name 'deploy'; git config user.email 'deploy'"
|
17
|
+
|
18
|
+
shout "Creating deploy.zip"
|
19
|
+
command = "uploadStash=`git stash create`; git archive -o deploy.zip ${uploadStash:-HEAD}"
|
20
|
+
exit(1) unless system(command)
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_tag_in_dockerrun(repo, tag)
|
24
|
+
shout "Changing Dockerrun.aws.json to contain latest tag"
|
25
|
+
command = "sed 's/<TAG>/#{tag}/' < Dockerrun.aws.json.template > Dockerrun.aws.json"
|
26
|
+
exit(1) unless system(command)
|
27
|
+
end
|
28
|
+
|
29
|
+
def push_image(repo, tag)
|
30
|
+
shout "Pushing Docker Image: #{repo}:#{tag}"
|
31
|
+
command = "docker push #{repo}:#{tag}"
|
32
|
+
exit(1) unless system(command)
|
33
|
+
end
|
34
|
+
|
35
|
+
def pull_image(repo, tag)
|
36
|
+
shout "Pulling Docker Image: #{repo}:#{tag}"
|
37
|
+
command = "docker pull #{repo}:#{tag}"
|
38
|
+
exit(1) unless system(command)
|
39
|
+
end
|
40
|
+
|
41
|
+
def run_deploy(version, environment)
|
42
|
+
command = "eb deploy #{environment} --label #{version}"
|
43
|
+
shout "deploying #{version} to elastic beanstalk with command: #{command}"
|
44
|
+
exit(1) unless system(command)
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_rollback(version, environment)
|
48
|
+
command = "eb deploy #{environment} --version #{version}"
|
49
|
+
shout "deploying #{version} to elastic beanstalk with command: #{command}"
|
50
|
+
exit(1) unless system(command)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Deploy
|
2
|
+
module Output
|
3
|
+
|
4
|
+
def announce(attachments)
|
5
|
+
shout("#{attachments[:title]} - #{attachments[:text]}")
|
6
|
+
notifier('', attachments)
|
7
|
+
end
|
8
|
+
|
9
|
+
def notifier(message, attachments)
|
10
|
+
if ENV['SLACK_WEBHOOK']
|
11
|
+
@notifier ||= Slack::Notifier.new(ENV['SLACK_WEBHOOK'])
|
12
|
+
@notifier.ping(message, {
|
13
|
+
attachments: [attachments]
|
14
|
+
})
|
15
|
+
else
|
16
|
+
shout 'You can send deployment notifications if you set the SLACK_WEBHOOK environment variable.'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def shout(message)
|
21
|
+
message_size = message.size
|
22
|
+
if message_size < 77
|
23
|
+
# lines are always 80 characters
|
24
|
+
stars = '*' * (77 - message_size)
|
25
|
+
puts(red("+ ") + "#{message} #{red(stars)}")
|
26
|
+
else
|
27
|
+
puts(red('+ ') + message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def red(message)
|
32
|
+
colorize(31, message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def green(message)
|
36
|
+
colorize(32, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def yellow(message)
|
40
|
+
colorize(33, message)
|
41
|
+
end
|
42
|
+
|
43
|
+
def pink(message)
|
44
|
+
colorize(35, message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def colorize(color_code, message)
|
48
|
+
"\e[#{color_code}m#{message}\e[0m"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Deploy
|
2
|
+
class Runner < Thor
|
3
|
+
include Deploy::Output
|
4
|
+
include Deploy::Commands
|
5
|
+
include Deploy::Checks
|
6
|
+
include Deploy::Versions
|
7
|
+
include Deploy::Utility
|
8
|
+
|
9
|
+
method_option :version, aliases: '-v', desc: 'Version', type: :string, required: true
|
10
|
+
method_option :environment, aliases: '-e', desc: 'Environment', type: :string, required: true
|
11
|
+
method_option :build, aliases: '-b', desc: 'Build Image', type: :boolean, default: true
|
12
|
+
desc 'deploy', 'deploy'
|
13
|
+
def deploy
|
14
|
+
check_setup
|
15
|
+
|
16
|
+
environment = options[:environment]
|
17
|
+
build = options[:build]
|
18
|
+
|
19
|
+
version = options[:version]
|
20
|
+
check_version(version, environment)
|
21
|
+
|
22
|
+
repo = ENV['DOCKER_REPO']
|
23
|
+
|
24
|
+
use_tag_in_dockerrun(repo, version)
|
25
|
+
create_deploy_zip_file
|
26
|
+
|
27
|
+
if build && !version_exists?(version)
|
28
|
+
announce_title = "Deployment started with an image that was just built"
|
29
|
+
build_image(repo, version)
|
30
|
+
push_image(repo, version)
|
31
|
+
else
|
32
|
+
announce_title = "Deployment started with an image that was already built"
|
33
|
+
end
|
34
|
+
|
35
|
+
announce({ color: '#6080C0', title: announce_title, text: "Deploying version #{version} to #{environment}" })
|
36
|
+
run_deploy(version, environment)
|
37
|
+
announce({ color: 'good', title: 'Deployment Succeeded!!', text: "The current version of #{environment} is #{version}" })
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'send test notification', 'send test notification'
|
41
|
+
def test_slack
|
42
|
+
notifier('', { color: 'good', title: 'This is a test notification from eb-docker-deploy.' })
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'list versions', 'list all application versions'
|
46
|
+
def versions
|
47
|
+
check_setup
|
48
|
+
|
49
|
+
application_versions_array.each do |version|
|
50
|
+
shout version
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
method_option :environment, aliases: '-e', desc: 'Environment', required: true
|
55
|
+
desc 'show version', 'show environment version'
|
56
|
+
def version
|
57
|
+
check_setup
|
58
|
+
|
59
|
+
shout current_version_for_environment(options[:environment])
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'setup config', 'setup config'
|
63
|
+
def setup
|
64
|
+
(shout('AWS creds already configured in ~/.bashrc'); exit(1)) if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION']
|
65
|
+
|
66
|
+
key = ask('Enter AWS Key:')
|
67
|
+
secret = ask('Enter AWS Secret:')
|
68
|
+
region = ask('Enter AWS Region:', default: 'us-west-2')
|
69
|
+
|
70
|
+
File.open(File.expand_path('~/.bashrc'), 'a') do |f|
|
71
|
+
f.puts ''
|
72
|
+
f.puts '# Variables defined by eb-docker-deploy:'
|
73
|
+
f.puts "export AWS_ACCESS_KEY_ID=#{key}"
|
74
|
+
f.puts "export AWS_SECRET_ACCESS_KEY=#{secret}"
|
75
|
+
f.puts "export AWS_REGION=#{region}"
|
76
|
+
end
|
77
|
+
|
78
|
+
shout('AWS creds successfully configured at ~/.bashrc.')
|
79
|
+
shout('You must now run "source ~/.bashrc"')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'deploy/utility'
|
2
|
+
|
3
|
+
module Deploy
|
4
|
+
module Versions
|
5
|
+
include Deploy::Utility
|
6
|
+
|
7
|
+
def eb
|
8
|
+
Aws::ElasticBeanstalk::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def version_exists?(version)
|
12
|
+
application_versions_array.include?(version)
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_version_for_environment(environment)
|
16
|
+
eb.describe_environments(environment_names: [environment]).environments.first.version_label
|
17
|
+
end
|
18
|
+
|
19
|
+
def application_versions_array
|
20
|
+
@array ||= eb.describe_application_versions.application_versions.reverse.map(&:version_label)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eb-docker-deployer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-31 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: slack-notifier
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: deploy with docker and aws eb
|
98
|
+
email:
|
99
|
+
- thogg4@gmail.com
|
100
|
+
executables:
|
101
|
+
- ebd
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/ebd
|
111
|
+
- eb-docker-deployer.gemspec
|
112
|
+
- lib/deploy.rb
|
113
|
+
- lib/deploy/checks.rb
|
114
|
+
- lib/deploy/commands.rb
|
115
|
+
- lib/deploy/output.rb
|
116
|
+
- lib/deploy/runner.rb
|
117
|
+
- lib/deploy/utility.rb
|
118
|
+
- lib/deploy/version.rb
|
119
|
+
- lib/deploy/versions.rb
|
120
|
+
homepage: ''
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: deploy with docker and aws eb
|
144
|
+
test_files: []
|