skyed 0.1.7 → 0.1.8
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 +4 -4
- data/lib/skyed.rb +3 -0
- data/lib/skyed/aws.rb +122 -0
- data/lib/skyed/commands.rb +73 -11
- data/lib/skyed/create.rb +26 -0
- data/lib/skyed/deploy.rb +2 -1
- data/lib/skyed/destroy.rb +9 -30
- data/lib/skyed/git.rb +21 -0
- data/lib/skyed/init.rb +18 -33
- data/lib/skyed/list.rb +22 -0
- data/lib/skyed/run.rb +17 -6
- data/lib/skyed/settings.rb +4 -0
- data/lib/skyed/utils.rb +20 -0
- data/templates/ssh-git.erb +7 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9135fef3c347f9bd2ffcc03c6a9621aaa8429f5f
|
4
|
+
data.tar.gz: ae7793935198775b5bc8afad4378b29cf337495b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0219be28bd5d5fd6612e01f6f0b5cd2f55123fe0d6ae141ad3df5fcd16dc09b7bd744f403513c237b0940d72ba5687232c42cf881e726429f90f3520a2737144
|
7
|
+
data.tar.gz: d0decb2b5c243ae2059bd753b18282447875a5bc3387d7b484e14120d72f16ac0ceb0df3b031f97b688b148933a31fa2f1e158f09471b0a0606163b2671aa894
|
data/lib/skyed.rb
CHANGED
data/lib/skyed/aws.rb
CHANGED
@@ -38,6 +38,100 @@ module Skyed
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# This module encapsulates all the RDS related functions.
|
42
|
+
module RDS
|
43
|
+
class << self
|
44
|
+
def create_instance_from_snapshot(
|
45
|
+
instance_name,
|
46
|
+
snapshot,
|
47
|
+
_options,
|
48
|
+
rds = nil)
|
49
|
+
rds = login if rds.nil?
|
50
|
+
rds.restore_db_instance_from_db_snapshot(
|
51
|
+
db_instance_identifier: instance_name,
|
52
|
+
db_snapshot_identifier: snapshot)[:db_instance]
|
53
|
+
db_instance = wait_for_instance(instance_name, 'available', 0, rds)
|
54
|
+
"#{db_instance[:endpoint][:address]}:#{db_instance[:endpoint][:port]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def list_snapshots(_options, args, rds = nil)
|
58
|
+
rds = login if rds.nil?
|
59
|
+
request = {}
|
60
|
+
request[:db_instance_identifier] = args.first unless args.nil?
|
61
|
+
response = rds.describe_db_snapshots(request)
|
62
|
+
response.db_snapshots
|
63
|
+
end
|
64
|
+
|
65
|
+
def destroy_instance(instance_name, options, rds = nil)
|
66
|
+
rds = login if rds.nil?
|
67
|
+
rds.delete_db_instance(
|
68
|
+
generate_params(instance_name, options))[:db_instance]
|
69
|
+
end
|
70
|
+
|
71
|
+
def generate_delete_params(instance_name, options)
|
72
|
+
snapshot = !options[:final_snapshot_name].empty?
|
73
|
+
params = {
|
74
|
+
db_instance_identifier: instance_name,
|
75
|
+
skip_final_snapshot: !snapshot
|
76
|
+
}
|
77
|
+
params[
|
78
|
+
:final_snapshot_name] = options[:final_snapshot_name] if snapshot
|
79
|
+
params
|
80
|
+
end
|
81
|
+
|
82
|
+
def generate_create_params(instance_name, options)
|
83
|
+
{
|
84
|
+
db_instance_identifier: instance_name,
|
85
|
+
allocated_storage: options[:size],
|
86
|
+
db_instance_class: "db.#{options[:type]}",
|
87
|
+
engine: 'postgres',
|
88
|
+
master_username: options[:user],
|
89
|
+
master_user_password: options[:password],
|
90
|
+
db_security_groups: [options[:db_security_group]],
|
91
|
+
db_parameter_group_name: options[:db_parameters_group]
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def wait_for_instance(instance_name, status, wait = 0, rds = nil)
|
96
|
+
rds = login if rds.nil?
|
97
|
+
instance = rds.describe_db_instances(
|
98
|
+
db_instance_identifier: instance_name)[:db_instances][0]
|
99
|
+
while instance[:db_instance_status] != status
|
100
|
+
sleep(wait)
|
101
|
+
instance = rds.describe_db_instances(
|
102
|
+
db_instance_identifier: instance_name)[:db_instances][0]
|
103
|
+
end
|
104
|
+
instance
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_params(instance_name, options)
|
108
|
+
params = generate_delete_params(
|
109
|
+
instance_name, options) if options.key? :final_snapshot_name
|
110
|
+
params = generate_create_params(
|
111
|
+
instance_name, options) if options.key? :user
|
112
|
+
params
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_instance(instance_name, options, rds = nil)
|
116
|
+
rds = login if rds.nil?
|
117
|
+
rds.create_db_instance(
|
118
|
+
generate_params(instance_name, options))[:db_instance]
|
119
|
+
db_instance = wait_for_instance(instance_name, 'available', 0, rds)
|
120
|
+
"#{db_instance[:endpoint][:address]}:#{db_instance[:endpoint][:port]}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def login(
|
124
|
+
access = Skyed::Settings.access_key,
|
125
|
+
secret = Skyed::Settings.secret_key,
|
126
|
+
region = Skyed::AWS.region)
|
127
|
+
Aws::RDS::Client.new(
|
128
|
+
access_key_id: access,
|
129
|
+
secret_access_key: secret,
|
130
|
+
region: region)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
41
135
|
# This module encapsulates all the OpsWorks related functions.
|
42
136
|
module OpsWorks
|
43
137
|
STACK = {
|
@@ -66,6 +160,33 @@ module Skyed
|
|
66
160
|
}
|
67
161
|
|
68
162
|
class << self
|
163
|
+
def deregister_instance(hostname, opsworks)
|
164
|
+
instance = instance_by_name(
|
165
|
+
hostname, Skyed::Settings.stack_id, opsworks)
|
166
|
+
opsworks.deregister_instance(
|
167
|
+
instance_id: instance.instance_id) unless instance.nil?
|
168
|
+
wait_for_instance(
|
169
|
+
hostname, Skyed::Settings.stack_id, 'terminated', opsworks)
|
170
|
+
end
|
171
|
+
|
172
|
+
def delete_user(opsworks)
|
173
|
+
stack = opsworks.describe_stacks(
|
174
|
+
stack_ids: [Skyed::Settings.stack_id])[:stacks][0][:name]
|
175
|
+
layer = opsworks.describe_layers(
|
176
|
+
layer_ids: [Skyed::Settings.layer_id])[:layers][0][:name]
|
177
|
+
Skyed::AWS::IAM.delete_user "OpsWorks-#{stack}-#{layer}"
|
178
|
+
end
|
179
|
+
|
180
|
+
def wait_for_instance(instance_name, stack_id, status, opsworks)
|
181
|
+
instance = Skyed::AWS::OpsWorks.instance_by_name(
|
182
|
+
instance_name, stack_id, opsworks)
|
183
|
+
until instance.nil? || instance.status == status
|
184
|
+
sleep(0)
|
185
|
+
instance = Skyed::AWS::OpsWorks.instance_by_name(
|
186
|
+
instance_name, stack_id, opsworks)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
69
190
|
def stack(stack_criteria, opsworks)
|
70
191
|
stack_by_name(
|
71
192
|
stack_criteria,
|
@@ -239,6 +360,7 @@ module Skyed
|
|
239
360
|
|
240
361
|
def generate_stack_params(options)
|
241
362
|
params = basic_stack_params
|
363
|
+
params[:custom_json] = options[:custom_json] || ''
|
242
364
|
params[:custom_cookbooks_source] = custom_cookbooks_source(
|
243
365
|
STACK[:custom_cookbooks_source])
|
244
366
|
params[:configuration_manager] = configuration_manager(
|
data/lib/skyed/commands.rb
CHANGED
@@ -2,12 +2,22 @@ desc 'Initialize skyed'
|
|
2
2
|
long_desc 'Sets up skyed configuration for a repository'
|
3
3
|
|
4
4
|
command :init do |cmd|
|
5
|
-
cmd.flag :remote, default_value: nil,
|
5
|
+
cmd.flag [:remote], default_value: nil,
|
6
|
+
type: String,
|
7
|
+
desc: 'Remote to use in OpsWorks'
|
8
|
+
cmd.flag [:repo], default_value: '.',
|
6
9
|
type: String,
|
7
|
-
desc: '
|
8
|
-
cmd.flag :
|
9
|
-
|
10
|
-
|
10
|
+
desc: 'OpsWorks repository location'
|
11
|
+
cmd.flag [:repo_key, 'repo-key'], default_value: nil,
|
12
|
+
type: String,
|
13
|
+
desc: 'Key to use with repo'
|
14
|
+
cmd.flag [:j, :custom_json, 'custom-json'], default_value: '',
|
15
|
+
type: String,
|
16
|
+
desc: 'Custom JSON to pass to OW'
|
17
|
+
desc = 'Chef version to use in OpsWorks'
|
18
|
+
cmd.flag [:chef_version, 'chef-version'], default_value: '11.10',
|
19
|
+
type: String,
|
20
|
+
desc: desc
|
11
21
|
cmd.action do |global_options, options|
|
12
22
|
Skyed::Init.execute(global_options, options)
|
13
23
|
end
|
@@ -34,12 +44,13 @@ command :run do |cmd|
|
|
34
44
|
cmd.flag [:l, :layer], default_value: nil,
|
35
45
|
type: String,
|
36
46
|
desc: layer_desc
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
desc = 'Time to wait for AWS responses'
|
48
|
+
cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
|
49
|
+
type: Integer,
|
50
|
+
desc: desc
|
51
|
+
cmd.flag [:j, :custom_json, 'custom-json'], default_value: '',
|
52
|
+
type: String,
|
53
|
+
desc: 'Custom JSON to pass to OW'
|
43
54
|
cmd.action do |global_options, options, args|
|
44
55
|
Skyed::Run.execute(global_options, options, args)
|
45
56
|
end
|
@@ -49,7 +60,58 @@ desc 'Destroy instance'
|
|
49
60
|
long_desc 'Destroy instance'
|
50
61
|
|
51
62
|
command :destroy do |cmd|
|
63
|
+
cmd.switch [:rds], default_value: false,
|
64
|
+
desc: 'Destroys RDS instance'
|
65
|
+
desc = 'Final snapshot name. Ommit to skip'
|
66
|
+
cmd.flag [:final_snapshot_name, 'final-snapshot-name'], default_value: '',
|
67
|
+
type: String,
|
68
|
+
desc: desc
|
52
69
|
cmd.action do |global_options, options, args|
|
53
70
|
Skyed::Destroy.execute(global_options, options, args)
|
54
71
|
end
|
55
72
|
end
|
73
|
+
|
74
|
+
desc 'Create instance'
|
75
|
+
long_desc 'Create instance'
|
76
|
+
|
77
|
+
command :create do |cmd|
|
78
|
+
cmd.switch [:rds], default_value: false,
|
79
|
+
desc: 'Creates RDS instance'
|
80
|
+
cmd.flag [:size], default_value: 100,
|
81
|
+
type: Integer,
|
82
|
+
desc: 'Size of the RDS instance'
|
83
|
+
cmd.flag [:type], default_value: 'm1.large',
|
84
|
+
type: String,
|
85
|
+
desc: 'Type of the RDS instance'
|
86
|
+
cmd.flag [:user], default_value: 'root',
|
87
|
+
type: String,
|
88
|
+
desc: 'Master user of the RDS instance'
|
89
|
+
cmd.flag [:password], default_value: 'password',
|
90
|
+
type: String,
|
91
|
+
desc: 'Master password of the RDS instance'
|
92
|
+
defval = 'rds-launch-wizard'
|
93
|
+
desc = 'Name of the DB Security Group'
|
94
|
+
cmd.flag [:db_security_group, 'db-security-group'], default_value: defval,
|
95
|
+
type: String,
|
96
|
+
desc: desc
|
97
|
+
defval = 'default'
|
98
|
+
desc = 'Name of the DB Parameter Group'
|
99
|
+
cmd.flag [:db_parameters_group, 'db-parameters-group'], default_value: defval,
|
100
|
+
type: String,
|
101
|
+
desc: desc
|
102
|
+
cmd.action do |global_options, options, args|
|
103
|
+
Skyed::Create.execute(global_options, options, args)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
desc 'List objects'
|
108
|
+
long_desc 'List objects'
|
109
|
+
|
110
|
+
command :list do |cmd|
|
111
|
+
cmd.switch [:rds], default_value: false,
|
112
|
+
desc: 'Lists RDS objects'
|
113
|
+
|
114
|
+
cmd.action do |global_options, options, args|
|
115
|
+
Skyed::List.execute(global_options, options, args)
|
116
|
+
end
|
117
|
+
end
|
data/lib/skyed/create.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Skyed
|
2
|
+
# This module encapsulates all the create command steps.
|
3
|
+
module Create
|
4
|
+
class << self
|
5
|
+
def execute(_global_options, options, args)
|
6
|
+
Skyed::Init.credentials if Skyed::Settings.empty?
|
7
|
+
endpoint = create_new(options, args) if args.length == 1
|
8
|
+
endpoint = restore_new(options, args) if args.length == 2
|
9
|
+
puts endpoint
|
10
|
+
end
|
11
|
+
|
12
|
+
def restore_new(options, args)
|
13
|
+
Skyed::AWS::RDS.create_instance_from_snapshot(
|
14
|
+
args[0],
|
15
|
+
args[1],
|
16
|
+
options.select { |k| k != :rds })
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_new(options, args)
|
20
|
+
Skyed::AWS::RDS.create_instance(
|
21
|
+
args[0],
|
22
|
+
options.select { |k| k != :rds })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/skyed/deploy.rb
CHANGED
@@ -4,6 +4,7 @@ module Skyed
|
|
4
4
|
class << self
|
5
5
|
def execute(global_options)
|
6
6
|
fail 'Not initialized, please run skyed init' if Skyed::Settings.empty?
|
7
|
+
Skyed::Utils.export_credentials
|
7
8
|
push_devel_branch(global_options)
|
8
9
|
output = `cd #{Skyed::Settings.repo} && vagrant up`
|
9
10
|
fail output unless $CHILD_STATUS.success?
|
@@ -11,7 +12,7 @@ module Skyed
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def push_devel_branch(_global_options)
|
14
|
-
repo = Git.open(Skyed::Settings.repo)
|
15
|
+
repo = ::Git.open(Skyed::Settings.repo)
|
15
16
|
repo.push(Skyed::Settings.remote_name, Skyed::Settings.branch)
|
16
17
|
end
|
17
18
|
end
|
data/lib/skyed/destroy.rb
CHANGED
@@ -2,40 +2,19 @@ module Skyed
|
|
2
2
|
# This module encapsulates all the destroy command steps.
|
3
3
|
module Destroy
|
4
4
|
class << self
|
5
|
-
def execute(
|
5
|
+
def execute(global_options, options, args)
|
6
|
+
Skyed::Init.credentials if Skyed::Settings.empty?
|
7
|
+
destroy_vagrant(global_options, options, args) unless options[:rds]
|
8
|
+
Skyed::AWS::RDS.destroy_instance(args[0], options) if options[:rds]
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy_vagrant(_global_options, _options, _args)
|
6
12
|
repo_path = Skyed::Settings.repo
|
7
13
|
hostname = `cd #{repo_path} && vagrant ssh -c hostname`.strip
|
8
14
|
`cd #{repo_path} && vagrant destroy -f`
|
9
15
|
ow = Skyed::AWS::OpsWorks.login
|
10
|
-
deregister_instance hostname, ow
|
11
|
-
delete_user ow
|
12
|
-
end
|
13
|
-
|
14
|
-
def deregister_instance(hostname, ow)
|
15
|
-
instance = Skyed::AWS::OpsWorks.instance_by_name(
|
16
|
-
hostname, Skyed::Settings.stack_id, ow)
|
17
|
-
ow.deregister_instance(
|
18
|
-
instance_id: instance.instance_id) unless instance.nil?
|
19
|
-
wait_for_instance(
|
20
|
-
hostname, Skyed::Settings.stack_id, ow)
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete_user(ow)
|
24
|
-
stack = ow.describe_stacks(
|
25
|
-
stack_ids: [Skyed::Settings.stack_id])[:stacks][0][:name]
|
26
|
-
layer = ow.describe_layers(
|
27
|
-
layer_ids: [Skyed::Settings.layer_id])[:layers][0][:name]
|
28
|
-
Skyed::AWS::IAM.delete_user "OpsWorks-#{stack}-#{layer}"
|
29
|
-
end
|
30
|
-
|
31
|
-
def wait_for_instance(hostname, stack_id, opsworks)
|
32
|
-
instance = Skyed::AWS::OpsWorks.instance_by_name(
|
33
|
-
hostname, stack_id, opsworks)
|
34
|
-
until instance.nil? || instance.status == 'terminated'
|
35
|
-
sleep(0)
|
36
|
-
instance = Skyed::AWS::OpsWorks.instance_by_name(
|
37
|
-
hostname, stack_id, opsworks)
|
38
|
-
end
|
16
|
+
Skyed::AWS::OpsWorks.deregister_instance hostname, ow
|
17
|
+
Skyed::AWS::OpsWorks.delete_user ow
|
39
18
|
end
|
40
19
|
end
|
41
20
|
end
|
data/lib/skyed/git.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Skyed
|
5
|
+
# This module encapsulates all the Git features.
|
6
|
+
module Git
|
7
|
+
class << self
|
8
|
+
def clone_stack_remote(stack)
|
9
|
+
Skyed::Init.opsworks_git_key unless Skyed::Settings.current_stack?(
|
10
|
+
stack[:stack_id])
|
11
|
+
ENV['PKEY'] = Skyed::Settings.opsworks_git_key
|
12
|
+
Skyed::Utils.create_template('/tmp', 'ssh-git', 'ssh-git.erb')
|
13
|
+
File.chmod(0755, '/tmp/ssh-git')
|
14
|
+
ENV['GIT_SSH'] = '/tmp/ssh-git'
|
15
|
+
path = "/tmp/skyed.#{SecureRandom.hex}"
|
16
|
+
::Git.clone(stack[:custom_cookbooks_source][:url], path)
|
17
|
+
path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/skyed/init.rb
CHANGED
@@ -12,10 +12,10 @@ module Skyed
|
|
12
12
|
class << self
|
13
13
|
def execute(global_options, options)
|
14
14
|
fail 'Already initialized' unless Skyed::Settings.empty?
|
15
|
-
Skyed::Settings.repo = repo_path(get_repo).to_s
|
15
|
+
Skyed::Settings.repo = repo_path(get_repo(options[:repo])).to_s
|
16
16
|
branch global_options, options
|
17
17
|
credentials
|
18
|
-
opsworks_git_key
|
18
|
+
opsworks_git_key options
|
19
19
|
opsworks options
|
20
20
|
vagrant
|
21
21
|
Skyed::Settings.save
|
@@ -44,13 +44,13 @@ module Skyed
|
|
44
44
|
provisioning_path = File.join(Skyed::Settings.repo, '.provisioning')
|
45
45
|
tasks_path = File.join(provisioning_path, 'tasks')
|
46
46
|
aws_path = File.join(provisioning_path, 'templates', 'aws')
|
47
|
-
create_template(Skyed::Settings.repo, 'Vagrantfile',
|
48
|
-
|
49
|
-
create_template(tasks_path, 'ow-on-premise.yml',
|
50
|
-
|
51
|
-
create_template(aws_path, 'config.j2', '
|
52
|
-
create_template(aws_path, 'credentials.j2',
|
53
|
-
|
47
|
+
Skyed::Utils.create_template(Skyed::Settings.repo, 'Vagrantfile',
|
48
|
+
'Vagrantfile.erb')
|
49
|
+
Skyed::Utils.create_template(tasks_path, 'ow-on-premise.yml',
|
50
|
+
'ow-on-premise.yml.erb')
|
51
|
+
Skyed::Utils.create_template(aws_path, 'config.j2', 'config.j2.erb')
|
52
|
+
Skyed::Utils.create_template(aws_path, 'credentials.j2',
|
53
|
+
'credentials.j2.erb')
|
54
54
|
end
|
55
55
|
|
56
56
|
def vagrant
|
@@ -61,19 +61,6 @@ module Skyed
|
|
61
61
|
create_vagrant_files
|
62
62
|
end
|
63
63
|
|
64
|
-
def create_template(base, subpath, template_file)
|
65
|
-
b = binding
|
66
|
-
folders = subpath.split('/')
|
67
|
-
template = ERB.new(
|
68
|
-
File.read(
|
69
|
-
File.join(
|
70
|
-
File.dirname(File.dirname(File.dirname(__FILE__))),
|
71
|
-
template_file)))
|
72
|
-
File.open(File.join(base, folders), 'w') do |f|
|
73
|
-
f.write(template.result b)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
64
|
def create_directory(base, subpath)
|
78
65
|
folders = subpath.split('/')
|
79
66
|
new_dir = File.join(base, folders)
|
@@ -129,9 +116,9 @@ module Skyed
|
|
129
116
|
ask(question + remotes_names.to_s)
|
130
117
|
end
|
131
118
|
|
132
|
-
def opsworks_git_key
|
119
|
+
def opsworks_git_key(options)
|
133
120
|
question = 'Which ssh key should be used for the git repository? '
|
134
|
-
Skyed::Settings.opsworks_git_key = ask(question)
|
121
|
+
Skyed::Settings.opsworks_git_key = options[:repo_key] || ask(question)
|
135
122
|
end
|
136
123
|
|
137
124
|
def credentials(
|
@@ -149,21 +136,19 @@ module Skyed
|
|
149
136
|
Pathname.new(repo.repo.path).dirname
|
150
137
|
end
|
151
138
|
|
152
|
-
def get_repo(path = '.'
|
139
|
+
def get_repo(path = '.')
|
153
140
|
question = 'Which is your CM repository? '
|
141
|
+
force_ask = path == '.'
|
154
142
|
repo = repo?(path)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
repo = get_repo(
|
160
|
-
ask(question) { |q| q.default = repo_path(repo).to_s }, false)
|
161
|
-
end
|
143
|
+
say("ERROR: #{path} is not a repository") unless repo
|
144
|
+
repo = get_repo(
|
145
|
+
ask(question) { |q| q.default = repo_path(repo).to_s }
|
146
|
+
) if !repo || force_ask
|
162
147
|
repo
|
163
148
|
end
|
164
149
|
|
165
150
|
def repo?(path)
|
166
|
-
Git.open(path)
|
151
|
+
::Git.open(path)
|
167
152
|
rescue ArgumentError
|
168
153
|
return false
|
169
154
|
end
|
data/lib/skyed/list.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Skyed
|
2
|
+
# This module encapsulates all the list command steps.
|
3
|
+
module List
|
4
|
+
class << self
|
5
|
+
def execute(global_options, options, args)
|
6
|
+
db_snapshots(global_options, options, args[1..args.length])
|
7
|
+
end
|
8
|
+
|
9
|
+
def db_snapshots(_global_options, options, args)
|
10
|
+
Skyed::Init.credentials if Skyed::Settings.empty?
|
11
|
+
snapshots = Skyed::AWS::RDS.list_snapshots(
|
12
|
+
options,
|
13
|
+
args)
|
14
|
+
snapshots.each do |snapshot|
|
15
|
+
msg = "#{snapshot.db_snapshot_identifier}"
|
16
|
+
msg += " #{snapshot.db_instance_identifier} #{snapshot.snapshot_type}"
|
17
|
+
puts msg
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/skyed/run.rb
CHANGED
@@ -3,10 +3,10 @@ module Skyed
|
|
3
3
|
module Run
|
4
4
|
class << self
|
5
5
|
def execute(global_options, options, args)
|
6
|
+
recipes = check_recipes_exist(options, args)
|
6
7
|
if !options.nil? && options.key?(:stack) && !options[:stack].nil?
|
7
|
-
run(global_options, options,
|
8
|
+
run(global_options, options, recipes)
|
8
9
|
else
|
9
|
-
recipes = check_recipes_exist(args)
|
10
10
|
check_vagrant
|
11
11
|
execute_recipes(Skyed::AWS::OpsWorks.login, recipes)
|
12
12
|
end
|
@@ -67,8 +67,12 @@ module Skyed
|
|
67
67
|
fail msg unless output =~ /running/
|
68
68
|
end
|
69
69
|
|
70
|
-
def check_recipes_exist(args)
|
71
|
-
|
70
|
+
def check_recipes_exist(options, args)
|
71
|
+
if !options.nil? && options.key?(:stack) && !options[:stack].nil?
|
72
|
+
recipes = args.select { |recipe| recipe_in_remote(options, recipe) }
|
73
|
+
else
|
74
|
+
recipes = args.select { |recipe| recipe_in_cookbook(recipe) }
|
75
|
+
end
|
72
76
|
msg = "Couldn't found #{args - recipes} recipes in repository"
|
73
77
|
fail msg unless recipes == args
|
74
78
|
recipes
|
@@ -87,16 +91,23 @@ module Skyed
|
|
87
91
|
fail 'Deployment failed' unless status[0] == 'successful'
|
88
92
|
end
|
89
93
|
|
90
|
-
def recipe_in_cookbook(recipe)
|
94
|
+
def recipe_in_cookbook(recipe, path = nil)
|
95
|
+
path ||= Skyed::Settings.repo
|
91
96
|
cookbook, recipe = recipe.split('::')
|
92
97
|
recipe = 'default' if recipe.nil?
|
93
98
|
File.exist?(
|
94
99
|
File.join(
|
95
|
-
|
100
|
+
path,
|
96
101
|
cookbook,
|
97
102
|
'recipes',
|
98
103
|
"#{recipe}.rb"))
|
99
104
|
end
|
105
|
+
|
106
|
+
def recipe_in_remote(options, recipe)
|
107
|
+
clone = Skyed::Git.clone_stack_remote(
|
108
|
+
Skyed::AWS::OpsWorks.stack(options[:stack], login))
|
109
|
+
recipe_in_cookbook(recipe, clone)
|
110
|
+
end
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
data/lib/skyed/settings.rb
CHANGED
@@ -6,6 +6,10 @@ module Skyed
|
|
6
6
|
attr_accessor :_settings
|
7
7
|
|
8
8
|
class << self
|
9
|
+
def current_stack?(stack_id)
|
10
|
+
!Skyed::Settings.empty? && Skyed::Settings.stack_id == stack_id
|
11
|
+
end
|
12
|
+
|
9
13
|
def load!(filename = CONFIG_FILE)
|
10
14
|
newsets = {}
|
11
15
|
newsets = YAML.load_file(filename) if File.file? filename
|
data/lib/skyed/utils.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
1
3
|
module Skyed
|
2
4
|
# This module encapsulates some generic utility functions.
|
3
5
|
module Utils
|
4
6
|
class << self
|
7
|
+
def export_credentials
|
8
|
+
ENV['AWS_ACCESS_KEY'] = Skyed::Settings.access_key
|
9
|
+
ENV['AWS_SECRET_KEY'] = Skyed::Settings.secret_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_template(base, subpath, template_file)
|
13
|
+
b = binding
|
14
|
+
folders = subpath.split('/')
|
15
|
+
template = ERB.new(
|
16
|
+
File.read(File.join(
|
17
|
+
File.dirname(File.dirname(File.dirname(__FILE__))),
|
18
|
+
'templates',
|
19
|
+
template_file)))
|
20
|
+
File.open(File.join(base, folders), 'w') do |f|
|
21
|
+
f.write(template.result b)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
def read_key_file(key_file)
|
6
26
|
File.open(key_file, 'rb').read
|
7
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skyed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignasi Fosch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -77,9 +77,12 @@ files:
|
|
77
77
|
- lib/skyed.rb
|
78
78
|
- lib/skyed/aws.rb
|
79
79
|
- lib/skyed/commands.rb
|
80
|
+
- lib/skyed/create.rb
|
80
81
|
- lib/skyed/deploy.rb
|
81
82
|
- lib/skyed/destroy.rb
|
83
|
+
- lib/skyed/git.rb
|
82
84
|
- lib/skyed/init.rb
|
85
|
+
- lib/skyed/list.rb
|
83
86
|
- lib/skyed/run.rb
|
84
87
|
- lib/skyed/settings.rb
|
85
88
|
- lib/skyed/utils.rb
|
@@ -87,6 +90,7 @@ files:
|
|
87
90
|
- templates/config.j2.erb
|
88
91
|
- templates/credentials.j2.erb
|
89
92
|
- templates/ow-on-premise.yml.erb
|
93
|
+
- templates/ssh-git.erb
|
90
94
|
homepage: http://rubygems.org/gems/skyed
|
91
95
|
licenses:
|
92
96
|
- MIT
|