f2y_aws_tool 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/f2y-aws-tool +25 -0
- data/bin/setup +8 -0
- data/f2y_aws_tool.gemspec +44 -0
- data/lib/f2y_aws_tool/deploy.rb +93 -0
- data/lib/f2y_aws_tool/version.rb +3 -0
- data/lib/f2y_aws_tool.rb +26 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f753a1fc4e46ce65847a33d6fa7f9bd314e6516d
|
4
|
+
data.tar.gz: 15fe26d034b7290811c465522d3e4e2001e5ffcb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f704467ca490c147a0daa41fde3c032ad59d47c8bc211c9cbd1e1ad6e519881c498228155aa85edfd152b51fb414514ca78c9a0989de4edc421515d7ece3d57f
|
7
|
+
data.tar.gz: 8cf91b18a2053acc8f101e1650d9e05bf702bcc982147f59e9b63aaf1406de0047bab9f02f079f8b981aef00d510982da81bd039567fb1a85c4da5d92b5040f0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 nakedmoon
|
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,40 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/fit2you/f2y_aws_tool.svg?branch=master)](https://travis-ci.org/fit2you/f2y_aws_tool)
|
2
|
+
|
3
|
+
# F2yAwsTool
|
4
|
+
|
5
|
+
AWS OpsWorks Stack Deployment CLI
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'f2y_aws_tool'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install f2y_aws_tool
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
$ ./bin/f2y-aws-tool help
|
27
|
+
|
28
|
+
## Test
|
29
|
+
|
30
|
+
$ bundle exec rspec
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nakedmoon/f2y_aws_tool.
|
35
|
+
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "f2y_aws_tool"
|
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(__FILE__)
|
data/bin/f2y-aws-tool
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "f2y_aws_tool"
|
5
|
+
require 'thor'
|
6
|
+
|
7
|
+
class F2yAwsToolCli < Thor
|
8
|
+
method_option :stack_id, aliases: "-s", desc: "Opsworks stack Id", required: true, type: :string
|
9
|
+
method_option :app_id, aliases: "-a", desc: "Opsworks app Id", required: true, type: :string
|
10
|
+
method_option :wait, aliases: "-w", desc: "Wait until deploy is completed", type: :boolean, default: true
|
11
|
+
method_option :migrate, aliases: "-m", desc: "Migrate database", type: :boolean, default: true
|
12
|
+
method_option :access_key_id, aliases: "-k", desc: "Access Key Id", type: :string, default: ENV['AWS_ACCESS_KEY_ID']
|
13
|
+
method_option :secret_access_key, aliases: "-p", desc: "Secret Access Key", type: :string, default: ENV['AWS_SECRET_ACCESS_KEY']
|
14
|
+
method_option :log_level, aliases: "-l", desc: "Log level", type: :string, default: 'INFO', enum: ['DEBUG', 'INFO', 'ERROR']
|
15
|
+
method_option :log_aws, aliases: "-s", type: :boolean, default: false
|
16
|
+
|
17
|
+
desc "deploy", "Deploy Opsworks App"
|
18
|
+
def deploy
|
19
|
+
deploy_run = F2yAwsTool::Deploy.new(options).run
|
20
|
+
exit(1) unless [:running, :successful].include?(deploy_run.fetch(:status))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
F2yAwsToolCli::start
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'f2y_aws_tool/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "f2y_aws_tool"
|
8
|
+
spec.version = F2yAwsTool::VERSION
|
9
|
+
spec.authors = ["nakedmoon"]
|
10
|
+
spec.email = ["tore.andrea@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{F2Y Aws Tool.}
|
13
|
+
spec.description = %q{Fit2You Amazon Web Services Tool.}
|
14
|
+
spec.homepage = "http://www.fit2you.it"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
|
36
|
+
# Custom gemspecs
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
38
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
39
|
+
spec.add_runtime_dependency "log4r", "~> 1.1"
|
40
|
+
spec.add_runtime_dependency "thor", "~> 0.19"
|
41
|
+
spec.add_runtime_dependency "aws-sdk", "~> 2.7"
|
42
|
+
spec.executables << "f2y-aws-tool"
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module F2yAwsTool
|
2
|
+
class Deploy
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
deploy_id = create_deployment.deployment_id
|
10
|
+
deployed_app = describe_deployment(deploy_id)
|
11
|
+
log.info(sprintf("ID: %s, STATUS: %s", deploy_id, deployed_app.status))
|
12
|
+
if wait?
|
13
|
+
client.wait_until(:deployment_successful, deployment_ids: [deploy_id])
|
14
|
+
deployed_app = describe_deployment(deploy_id)
|
15
|
+
log.info(sprintf("ID: %s, STATUS: %s, DURATION: %s", deploy_id, deployed_app.status, Time.at(deployed_app.duration).utc.strftime("%H:%M:%S")))
|
16
|
+
end
|
17
|
+
return {deployment_id: deploy_id, status: deployed_app.status.to_sym}
|
18
|
+
end
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= Aws::OpsWorks::Client.new(
|
22
|
+
access_key_id: access_key_id,
|
23
|
+
secret_access_key: secret_access_key,
|
24
|
+
logger: aws_logger,
|
25
|
+
log_level: aws_log_level
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def describe_deployment(deploy_id)
|
32
|
+
client.describe_deployments({deployment_ids: [deploy_id]}).deployments.first
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def access_key_id
|
37
|
+
@access_key_id ||= @options.fetch(:access_key_id){ENV.fetch('AWS_ACCESS_KEY_ID')}
|
38
|
+
end
|
39
|
+
|
40
|
+
def secret_access_key
|
41
|
+
@secret_access_key ||= @options.fetch(:secret_access_key){ENV.fetch('AWS_SECRET_ACCESS_KEY')}
|
42
|
+
end
|
43
|
+
|
44
|
+
def stack_id
|
45
|
+
@stack_id ||= @options.fetch(:stack_id)
|
46
|
+
end
|
47
|
+
|
48
|
+
def app_id
|
49
|
+
@app_id ||= @options.fetch(:app_id)
|
50
|
+
end
|
51
|
+
|
52
|
+
def migrate?
|
53
|
+
@migrate ||= @options.fetch(:migrate)
|
54
|
+
end
|
55
|
+
|
56
|
+
def wait?
|
57
|
+
@wait ||= @options.fetch(:wait)
|
58
|
+
end
|
59
|
+
|
60
|
+
def log_level
|
61
|
+
@log_level ||= @options.fetch(:log_level)
|
62
|
+
end
|
63
|
+
|
64
|
+
def aws_logger
|
65
|
+
@log_aws ||= @options.fetch(:log_aws) ? log : nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def aws_log_level
|
69
|
+
@aws_log_level ||= log_level.downcase.to_sym
|
70
|
+
end
|
71
|
+
|
72
|
+
def log
|
73
|
+
@log ||= F2yAwsTool.log(log_level)
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_deployment
|
77
|
+
client.create_deployment(
|
78
|
+
{
|
79
|
+
stack_id: stack_id,
|
80
|
+
app_id: app_id,
|
81
|
+
command: {
|
82
|
+
name: "deploy",
|
83
|
+
args: {"migrate" => ["#{migrate?}"]},
|
84
|
+
},
|
85
|
+
comment: "CodeShip Deploy"
|
86
|
+
}
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/f2y_aws_tool.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'byebug'
|
3
|
+
require 'yaml'
|
4
|
+
require 'log4r'
|
5
|
+
|
6
|
+
require "f2y_aws_tool/version"
|
7
|
+
require "f2y_aws_tool/deploy"
|
8
|
+
|
9
|
+
module F2yAwsTool
|
10
|
+
extend self
|
11
|
+
|
12
|
+
include Log4r
|
13
|
+
|
14
|
+
def log(level)
|
15
|
+
@log = Logger.new 'F2Y-AWS-TOOL'
|
16
|
+
@log.level = Log4r.const_get(level)
|
17
|
+
@log.add(Log4r::StdoutOutputter.new("F2Y-AWS-TOOL-STDOUT", {formatter: log_format}))
|
18
|
+
@log
|
19
|
+
end
|
20
|
+
|
21
|
+
def log_format
|
22
|
+
@log_format ||= Log4r::PatternFormatter.new(:pattern => "[%l] %d :: %m", :date_pattern => "%a %d %b %H:%M %p %Y")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Your code goes here...
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: f2y_aws_tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nakedmoon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-12 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '9.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '9.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: log4r
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.19'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.19'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: aws-sdk
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.7'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.7'
|
111
|
+
description: Fit2You Amazon Web Services Tool.
|
112
|
+
email:
|
113
|
+
- tore.andrea@gmail.com
|
114
|
+
executables:
|
115
|
+
- f2y-aws-tool
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/f2y-aws-tool
|
128
|
+
- bin/setup
|
129
|
+
- f2y_aws_tool.gemspec
|
130
|
+
- lib/f2y_aws_tool.rb
|
131
|
+
- lib/f2y_aws_tool/deploy.rb
|
132
|
+
- lib/f2y_aws_tool/version.rb
|
133
|
+
homepage: http://www.fit2you.it
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata:
|
137
|
+
allowed_push_host: https://rubygems.org
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.5.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: F2Y Aws Tool.
|
158
|
+
test_files: []
|