cloudstrap 0.46.7.pre → 0.47.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloudstrap/agent.rb +16 -12
- data/lib/cloudstrap/cache.rb +47 -0
- data/lib/cloudstrap/config.rb +10 -0
- data/lib/cloudstrap/hook.rb +80 -0
- data/lib/cloudstrap/hooks.rb +26 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd656a1fb5421724af841dca0ff457b082811bab
|
4
|
+
data.tar.gz: 5b961f7ca2cd65e7d732500fd750578f5e91ab74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100e5c75a79d96f8a4ed7e1132f6df54fc063dab809c76a2ec242be892362015662b203b0205bee559af075f65ccce2d8f37f8d49fe4bb0c7878a933dda83544
|
7
|
+
data.tar.gz: c1009f7862b4a7c7220887eaefa6736a98f09face46d97d9ee7de30e1b2b61193e67fc3c07abb401adfa58eac5fce8426524e094c8067367c8fd39598a8aa4fc
|
data/lib/cloudstrap/agent.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative 'amazon'
|
|
6
6
|
require_relative 'config'
|
7
7
|
require_relative 'errors'
|
8
8
|
require_relative 'hcp/bootstrap_properties'
|
9
|
+
require_relative 'hooks'
|
9
10
|
require_relative 'network'
|
10
11
|
require_relative 'ssh'
|
11
12
|
|
@@ -13,6 +14,7 @@ module Cloudstrap
|
|
13
14
|
class Agent
|
14
15
|
include ::Contracts::Core
|
15
16
|
include ::Contracts::Builtin
|
17
|
+
include Hooks
|
16
18
|
|
17
19
|
Contract None => Agent
|
18
20
|
def initialize
|
@@ -435,20 +437,22 @@ module Cloudstrap
|
|
435
437
|
properties = bootstrap_properties.file
|
436
438
|
package = config.hcp_package_url
|
437
439
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
440
|
+
hooking(:setup) do
|
441
|
+
ssh.to(jumpbox_ip) do
|
442
|
+
'/home/ubuntu/.ssh/id_rsa'.tap do |target|
|
443
|
+
execute :rm, '-f', target
|
444
|
+
upload! private_key, target
|
445
|
+
execute :chmod, '-w', target
|
446
|
+
end
|
444
447
|
|
445
|
-
|
448
|
+
upload! properties, '/home/ubuntu/bootstrap.properties'
|
446
449
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
450
|
+
as :root do
|
451
|
+
execute :apt, *%w(install --assume-yes genisoimage aria2)
|
452
|
+
execute :rm, '-f', '/opt/bootstrap.deb'
|
453
|
+
execute :aria2c, '--continue=true', '--dir=/opt', '--out=bootstrap.deb', package
|
454
|
+
execute :dpkg, *%w(--install /opt/bootstrap.deb)
|
455
|
+
end
|
452
456
|
end
|
453
457
|
end
|
454
458
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'moneta'
|
3
|
+
|
4
|
+
require_relative 'config'
|
5
|
+
|
6
|
+
module Cloudstrap
|
7
|
+
class Cache
|
8
|
+
include ::Contracts::Core
|
9
|
+
include ::Contracts::Builtin
|
10
|
+
|
11
|
+
Contract RespondTo[:to_s], Maybe[RespondTo[:call]] => Maybe[Any]
|
12
|
+
def get(key)
|
13
|
+
persistence.fetch(key.to_s) do
|
14
|
+
# TODO: Remove symbol fallback for 1.0
|
15
|
+
persistence.fetch(key.to_s.to_sym) do
|
16
|
+
yield if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Contract RespondTo[:to_s], Any => Any
|
22
|
+
def set(key, value)
|
23
|
+
persistence.store key.to_s, value
|
24
|
+
end
|
25
|
+
|
26
|
+
Contract RespondTo[:to_s] => Maybe[Any]
|
27
|
+
def delete(key)
|
28
|
+
#TODO: Remove symbol fallback for 1.0
|
29
|
+
persistence.delete(key.to_s) || persistence.delete(key.to_s.to_sym)
|
30
|
+
end
|
31
|
+
|
32
|
+
Contract RespondTo[:to_s], Maybe[RespondTo[:call]] => Maybe[Any]
|
33
|
+
def call(key)
|
34
|
+
get(key) { set key, yield if block_given? }
|
35
|
+
end
|
36
|
+
|
37
|
+
Contract None => ::Moneta::Proxy
|
38
|
+
def persistence
|
39
|
+
@persistence ||= ::Moneta.new :File, dir: config.cache_path
|
40
|
+
end
|
41
|
+
|
42
|
+
Contract None => Config
|
43
|
+
def config
|
44
|
+
@config ||= Config.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/cloudstrap/config.rb
CHANGED
@@ -232,6 +232,16 @@ module Cloudstrap
|
|
232
232
|
required :domain_name
|
233
233
|
end
|
234
234
|
|
235
|
+
Contract None => String
|
236
|
+
def hooks_dir
|
237
|
+
lookup(:hooks_dir) { [workdir, 'hooks'].join('/') }
|
238
|
+
end
|
239
|
+
|
240
|
+
Contract None => String
|
241
|
+
def remote_hooks_dir
|
242
|
+
lookup(:remote_hooks_dir) { '.cloudstrap/hooks' }
|
243
|
+
end
|
244
|
+
|
235
245
|
private
|
236
246
|
|
237
247
|
Contract None => ::Pastel::Delegator
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative 'cache'
|
2
|
+
require_relative 'config'
|
3
|
+
require_relative 'ssh/client'
|
4
|
+
|
5
|
+
module Cloudstrap
|
6
|
+
class Hook
|
7
|
+
def initialize(name, **options)
|
8
|
+
@name = name
|
9
|
+
@options = options
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :name
|
14
|
+
|
15
|
+
alias to_s name
|
16
|
+
alias to_str to_s
|
17
|
+
|
18
|
+
def local
|
19
|
+
"#{config.hooks_dir}/#{name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def remote
|
23
|
+
"#{config.remote_hooks_dir}/#{name}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def exists?
|
27
|
+
File.exist? local
|
28
|
+
end
|
29
|
+
|
30
|
+
def enabled?
|
31
|
+
File.executable? local
|
32
|
+
end
|
33
|
+
|
34
|
+
def disabled?
|
35
|
+
!enabled?
|
36
|
+
end
|
37
|
+
|
38
|
+
def upload!
|
39
|
+
return false unless exists?
|
40
|
+
|
41
|
+
[local, remote].tap do |local_file, remote_file|
|
42
|
+
ssh.to(host) {
|
43
|
+
execute :mkdir, '-p', File.dirname(remote_file)
|
44
|
+
upload! local_file, remote_file }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute!
|
49
|
+
return true unless enabled?
|
50
|
+
|
51
|
+
remote.tap { |hook| ssh.to(host) { execute hook } }
|
52
|
+
end
|
53
|
+
|
54
|
+
def call
|
55
|
+
upload! && execute!
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def ssh
|
61
|
+
@ssh ||= SSH::Client.new key
|
62
|
+
end
|
63
|
+
|
64
|
+
def key
|
65
|
+
@options.fetch(:key)
|
66
|
+
end
|
67
|
+
|
68
|
+
def host
|
69
|
+
@options.fetch(:host)
|
70
|
+
end
|
71
|
+
|
72
|
+
def cache
|
73
|
+
@cache ||= Cache.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def config
|
77
|
+
@config ||= Config.new
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'hook'
|
2
|
+
|
3
|
+
module Cloudstrap
|
4
|
+
module Hooks
|
5
|
+
def hooks
|
6
|
+
return [] unless Dir.exist? config.hooks_dir
|
7
|
+
|
8
|
+
Dir
|
9
|
+
.entries(config.hooks_dir)
|
10
|
+
.reject { |entry| %w(. ..).include? entry }
|
11
|
+
.map { |entry| Hook.new entry, host: jumpbox_ip, key: ssh_key.private_file }
|
12
|
+
end
|
13
|
+
|
14
|
+
def hook(name)
|
15
|
+
hook = hooks.find { |h| h.name == name }
|
16
|
+
return unless hook
|
17
|
+
hook.call
|
18
|
+
end
|
19
|
+
|
20
|
+
def hooking(event)
|
21
|
+
return unless block_given?
|
22
|
+
hook "pre-#{event}"
|
23
|
+
yield.tap { hook "post-#{event}" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.47.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Olstrom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -362,10 +362,13 @@ files:
|
|
362
362
|
- lib/cloudstrap/amazon/service.rb
|
363
363
|
- lib/cloudstrap/amazon/support/rate_limit_handler.rb
|
364
364
|
- lib/cloudstrap/bootstrap_agent.rb
|
365
|
+
- lib/cloudstrap/cache.rb
|
365
366
|
- lib/cloudstrap/component_versions.rb
|
366
367
|
- lib/cloudstrap/config.rb
|
367
368
|
- lib/cloudstrap/errors.rb
|
368
369
|
- lib/cloudstrap/hcp/bootstrap_properties.rb
|
370
|
+
- lib/cloudstrap/hook.rb
|
371
|
+
- lib/cloudstrap/hooks.rb
|
369
372
|
- lib/cloudstrap/network.rb
|
370
373
|
- lib/cloudstrap/seed_properties.rb
|
371
374
|
- lib/cloudstrap/ssh.rb
|