asteroid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +9 -0
- data/Rakefile +11 -0
- data/asteroid.gemspec +33 -0
- data/bin/asteroid +17 -0
- data/generator/README.md +1 -0
- data/generator/Rakefile +0 -0
- data/generator/asteroid/servers/default.yml +3 -0
- data/generator/config/asteroid.rb +9 -0
- data/generator/gitignore +2 -0
- data/generator/secrets/.keep +0 -0
- data/generator/secrets/config/providers.rb +7 -0
- data/generator/secrets/config/secrets.yml +5 -0
- data/lib/asteroid.rb +22 -0
- data/lib/asteroid/application.rb +32 -0
- data/lib/asteroid/config.rb +103 -0
- data/lib/asteroid/config_file.rb +46 -0
- data/lib/asteroid/generator.rb +96 -0
- data/lib/asteroid/instance.rb +113 -0
- data/lib/asteroid/instance/aster.rb +0 -0
- data/lib/asteroid/instance/command.rb +146 -0
- data/lib/asteroid/instance/scp.rb +17 -0
- data/lib/asteroid/instance/ssh.rb +29 -0
- data/lib/asteroid/instance/vars.rb +45 -0
- data/lib/asteroid/provider.rb +36 -0
- data/lib/asteroid/provider/abstract.rb +37 -0
- data/lib/asteroid/provider/digital_ocean.rb +66 -0
- data/lib/asteroid/provider/mock.rb +51 -0
- data/lib/asteroid/provider/virtual_box.rb +43 -0
- data/lib/asteroid/script.rb +64 -0
- data/lib/asteroid/server.rb +96 -0
- data/lib/asteroid/ssh_key.rb +41 -0
- data/lib/asteroid/template.rb +25 -0
- data/lib/asteroid/version.rb +3 -0
- data/test/helper.rb +8 -0
- data/test/unit/test_instance.rb +18 -0
- data/test/unit/test_server.rb +19 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3ce3e8c2c0efe5635f743569fa70a6cc709b52e
|
4
|
+
data.tar.gz: 1f50a63fb78232511d1765201d82eb5225e7b682
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 916902671568e85392e6faac6ee8cc499013360377a47e0cf9ebac7751902394f5a6f9e338a255e80abde8456a753b5ddb6e197ae27bae6b28fd856f4cda18e2
|
7
|
+
data.tar.gz: d3656731753ee60ac60a2f8bbdb779d2fb7baca091e53370b22adf8a9a5ec2fc9dbe16ae43ee9f3676d8e0b03b8e995153022136342fb1db65cbfc6cc72eb4a3
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
world.yml
|
24
|
+
asdf/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sam Murphy
|
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
data/Rakefile
ADDED
data/asteroid.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'asteroid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "asteroid"
|
8
|
+
spec.version = Asteroid::VERSION
|
9
|
+
spec.authors = ["Sam Murphy"]
|
10
|
+
spec.email = ["sam.murphy@gmail.com"]
|
11
|
+
spec.summary = %q{A server configuration framework}
|
12
|
+
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "net-ssh"
|
22
|
+
spec.add_dependency "net-scp"
|
23
|
+
spec.add_dependency "activesupport"
|
24
|
+
spec.add_dependency "aster"
|
25
|
+
spec.add_dependency "digitalocean"
|
26
|
+
spec.add_dependency "thor"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "minitest"
|
32
|
+
spec.add_development_dependency "autotest"
|
33
|
+
end
|
data/bin/asteroid
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/asteroid'
|
4
|
+
require 'asteroid/application'
|
5
|
+
|
6
|
+
boot_file = File.expand_path('./config/asteroid.rb')
|
7
|
+
if File.exists?(boot_file)
|
8
|
+
require boot_file
|
9
|
+
|
10
|
+
# Existing Application
|
11
|
+
Asteroid::Application.start ARGV
|
12
|
+
|
13
|
+
else
|
14
|
+
# new application
|
15
|
+
Asteroid::NewApplication.start ARGV
|
16
|
+
|
17
|
+
end
|
data/generator/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Change me
|
data/generator/Rakefile
ADDED
File without changes
|
data/generator/gitignore
ADDED
File without changes
|
data/lib/asteroid.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'pry'
|
5
|
+
require 'yaml'
|
6
|
+
require 'digitalocean'
|
7
|
+
require 'aster'
|
8
|
+
|
9
|
+
|
10
|
+
require_relative './asteroid/version.rb'
|
11
|
+
require_relative './asteroid/provider.rb'
|
12
|
+
require_relative './asteroid/config.rb'
|
13
|
+
require_relative './asteroid/script.rb'
|
14
|
+
require_relative './asteroid/config_file.rb'
|
15
|
+
require_relative './asteroid/server.rb'
|
16
|
+
require_relative './asteroid/ssh_key.rb'
|
17
|
+
require_relative './asteroid/instance.rb'
|
18
|
+
require_relative './asteroid/template.rb'
|
19
|
+
|
20
|
+
module Asteroid
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require 'asteroid/generator'
|
4
|
+
|
5
|
+
module Asteroid
|
6
|
+
|
7
|
+
class Application < Thor
|
8
|
+
desc "instances [type]", "create a asteroid application at NAME"
|
9
|
+
option :type
|
10
|
+
def instances()
|
11
|
+
i = Instance.all
|
12
|
+
binding.pry
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NewApplication < Thor
|
18
|
+
|
19
|
+
desc "new NAME", "create a asteroid application at NAME"
|
20
|
+
option :from
|
21
|
+
def new(name)
|
22
|
+
project_root = File.expand_path name
|
23
|
+
|
24
|
+
generator = Asteroid::Generator.new project_root
|
25
|
+
generator.generate!
|
26
|
+
|
27
|
+
#puts "from: #{options[:from]}" if options[:from]
|
28
|
+
binding.pry
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Asteroid
|
2
|
+
|
3
|
+
def self.initialize!
|
4
|
+
if File.exists?(Config.initializer)
|
5
|
+
eval File.read(Config.initializer)
|
6
|
+
else
|
7
|
+
puts "No initializer"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.root=(root)
|
12
|
+
@root = root
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.root
|
16
|
+
@root
|
17
|
+
end
|
18
|
+
|
19
|
+
class Config
|
20
|
+
|
21
|
+
class << self
|
22
|
+
|
23
|
+
def configure(root, options = {}, &block)
|
24
|
+
options = default_config(root)
|
25
|
+
options.merge! options
|
26
|
+
options.each do |key, value|
|
27
|
+
self.send "#{key}=", value
|
28
|
+
end
|
29
|
+
|
30
|
+
yield self if block_given?
|
31
|
+
|
32
|
+
if File.exists? self.secret_config_file
|
33
|
+
@secrets = YAML::load_file self.secret_config_file || {}
|
34
|
+
else
|
35
|
+
@secrets = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def secret
|
41
|
+
@secrets
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_accessor :asteroid_dir
|
45
|
+
attr_accessor :script_dir
|
46
|
+
attr_accessor :file_dir
|
47
|
+
attr_accessor :server_dir
|
48
|
+
attr_accessor :config_dir
|
49
|
+
attr_accessor :secret_dir
|
50
|
+
attr_accessor :secret_file
|
51
|
+
attr_accessor :secret_config_dir
|
52
|
+
attr_accessor :secret_config_file
|
53
|
+
attr_accessor :secret_provider_file
|
54
|
+
attr_accessor :secret_script_dir
|
55
|
+
attr_accessor :secret_file_dir
|
56
|
+
attr_accessor :secret_key_dir
|
57
|
+
attr_accessor :secret_instance_dir
|
58
|
+
|
59
|
+
def default_config(root)
|
60
|
+
asteroid_dir = File.join(root, '/asteroid')
|
61
|
+
config_dir = File.join(root, '/config')
|
62
|
+
secret_dir = File.join(root, '/sercrets')
|
63
|
+
|
64
|
+
{
|
65
|
+
asteroid_dir: asteroid_dir,
|
66
|
+
script_dir: File.join(asteroid_dir, '/scripts'),
|
67
|
+
file_dir: File.join(asteroid_dir, '/files'),
|
68
|
+
server_dir: File.join(asteroid_dir, '/servers'),
|
69
|
+
config_dir: config_dir,
|
70
|
+
secret_dir: secret_dir,
|
71
|
+
secret_config_dir: File.join(secret_dir, '/config'),
|
72
|
+
secret_config_file: File.join(secret_dir, '/config', '/secrets.yml'),
|
73
|
+
secret_provider_file: File.join(secret_dir, '/config', '/providers.rb'),
|
74
|
+
secret_script_dir: File.join(secret_dir, '/scripts'),
|
75
|
+
secret_file_dir: File.join(secret_dir, '/files'),
|
76
|
+
secret_key_dir: File.join(secret_dir, '/keys'),
|
77
|
+
secret_instance_dir: File.join(secret_dir, '/instances')
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# self.domain = "example.com"
|
88
|
+
# self.base_dir = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
89
|
+
# self.config_dir = File.join(base_dir, '/config')
|
90
|
+
# self.initializer = File.join(config_dir, '/initializer.rb')
|
91
|
+
# self.script_dir = File.join(config_dir, 'scripts')
|
92
|
+
# self.file_dir = File.join(config_dir, 'files')
|
93
|
+
# self.secrets_dir = File.join(base_dir, '/secrets')
|
94
|
+
# self.ssh_key_dir = File.join(secrets_dir, '/ssh-keys')
|
95
|
+
# self.password_dir = File.join(secrets_dir, '/passwords')
|
96
|
+
# self.config_data_dir = File.join(secrets_dir, '/config')
|
97
|
+
# self.secret_file_dir = File.join(secrets_dir, '/files')
|
98
|
+
# self.secret_script_dir = File.join(secrets_dir, '/scripts')
|
99
|
+
# self.instance_config_dir = File.join(secrets_dir, '/instance-config')
|
100
|
+
# self.server_dir = File.join(config_dir, 'servers')
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Asteroid
|
5
|
+
class ConfigFile
|
6
|
+
def initialize(fname)
|
7
|
+
@filename = if Pathname.new(fname).absolute?
|
8
|
+
fname
|
9
|
+
elsif File.exists?(f = File.join(Asteroid::Config.file_dir, '/', fname))
|
10
|
+
f
|
11
|
+
elsif File.exists?(f = File.join(Asteroid::Config.secret_file_dir, '/', fname))
|
12
|
+
f
|
13
|
+
else
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def template?
|
19
|
+
@filename.split('.').last == "erb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def filename
|
23
|
+
if template?
|
24
|
+
@rendered_filename ||= begin
|
25
|
+
file_data = File.read @filename
|
26
|
+
file = Tempfile.new('config')
|
27
|
+
rendered_template = Template.new(:erb).render(file_data, data)
|
28
|
+
file.write rendered_template
|
29
|
+
file.rewind
|
30
|
+
file.path
|
31
|
+
end
|
32
|
+
else
|
33
|
+
@filename
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_data(d)
|
38
|
+
@data = d
|
39
|
+
end
|
40
|
+
|
41
|
+
def data
|
42
|
+
@data ||= {}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Asteroid
|
4
|
+
|
5
|
+
class Generator
|
6
|
+
|
7
|
+
def g(*paths)
|
8
|
+
@gen_root ||= File.expand_path File.join File.dirname(__FILE__), '../../generator'
|
9
|
+
File.join *([@gen_root] + paths)
|
10
|
+
end
|
11
|
+
|
12
|
+
def p(*paths)
|
13
|
+
File.join *([@project_root] + paths)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(project_root)
|
17
|
+
@project_root = File.expand_path project_root
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate!
|
21
|
+
|
22
|
+
c = Asteroid::Config.default_config(@project_root)
|
23
|
+
c[:asteroid_dir]
|
24
|
+
|
25
|
+
mkdir p
|
26
|
+
cp g('/README.md'), p
|
27
|
+
cp g('/gitignore'), p('/.gitignore')
|
28
|
+
cp g('/Rakefile'), p
|
29
|
+
|
30
|
+
mkdir c[:asteroid_dir]
|
31
|
+
|
32
|
+
mkdir c[:file_dir]
|
33
|
+
mkdir c[:script_dir]
|
34
|
+
mkdir c[:server_dir]
|
35
|
+
cp g('/asteroid/servers/default.yml'), c[:server_dir]
|
36
|
+
|
37
|
+
mkdir c[:config_dir]
|
38
|
+
cp g('/config/asteroid.rb'), c[:config_dir]
|
39
|
+
|
40
|
+
mkdir c[:secret_dir]
|
41
|
+
touch File.join(c[:secret_dir], '.keep')
|
42
|
+
|
43
|
+
mkdir c[:secret_config_dir]
|
44
|
+
touch File.join(c[:secret_config_dir], '.keep')
|
45
|
+
cp g('/secrets/config/providers.rb'), c[:secret_provider_file]
|
46
|
+
cp g('/secrets/config/secrets.yml'), c[:secret_config_file]
|
47
|
+
|
48
|
+
mkdir c[:secret_file_dir]
|
49
|
+
touch File.join(c[:secret_file_dir], '.keep')
|
50
|
+
|
51
|
+
mkdir c[:secret_script_dir]
|
52
|
+
touch File.join(c[:secret_script_dir], '.keep')
|
53
|
+
|
54
|
+
mkdir c[:secret_key_dir]
|
55
|
+
touch File.join(c[:secret_key_dir], '.keep')
|
56
|
+
|
57
|
+
|
58
|
+
binding.pry
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def mkdir(directory)
|
64
|
+
if File.directory?(directory)
|
65
|
+
puts "exists\t#{directory}"
|
66
|
+
else
|
67
|
+
puts "mkdir\t#{directory}"
|
68
|
+
FileUtils.mkdir directory
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def cp(from, to)
|
73
|
+
if File.directory?(to)
|
74
|
+
to = File.join(to, File.basename(from))
|
75
|
+
end
|
76
|
+
if File.exists?(to)
|
77
|
+
puts "exists\t#{to}"
|
78
|
+
else
|
79
|
+
puts "add\t#{to}"
|
80
|
+
FileUtils.cp from, to
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def touch(file)
|
85
|
+
if File.exists?(file)
|
86
|
+
puts "exists\t#{file}"
|
87
|
+
else
|
88
|
+
puts "touch\t#{file}"
|
89
|
+
FileUtils.touch file
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|