asteroid 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +44 -1
- data/bin/asteroid +4 -2
- data/generator/config/asteroid.rb +1 -1
- data/generator/secrets/config/providers.rb +2 -2
- data/lib/asteroid/config.rb +8 -0
- data/lib/asteroid/generator.rb +19 -1
- data/lib/asteroid/instance.rb +15 -2
- data/lib/asteroid/key_reference.rb +4 -0
- data/lib/asteroid/provider/abstract.rb +3 -0
- data/lib/asteroid/provider/digital_ocean.rb +2 -0
- data/lib/asteroid/server.rb +8 -1
- data/lib/asteroid/version.rb +1 -1
- data/test/helper.rb +2 -0
- data/test/unit/test_config.rb +14 -0
- data/test/unit/test_instance.rb +6 -0
- data/test/unit/test_server.rb +33 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01b1a83d9142f123465b81172dfb371e78c056b1
|
4
|
+
data.tar.gz: 904a539da5bfb209e53b2bf9a5ec26f4051433f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58f537411b43f906345f495b7eea178e45ede7ed4f84b0d9c49025e3d110ee44a919cc83fae441abbf0ec82dc6580fee97af3b1f60d4a29e7dd126a8e5d02352
|
7
|
+
data.tar.gz: 380772b7ea54f831fe0fc40b9c7477412d514ae9fcb1e5d3bb16c5b8bbd1b680db571eefa1a98cdee2aec43347f6efc7186ceda464e8243fbd9dac2c03915bb8
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -33,7 +33,7 @@ commands:
|
|
33
33
|
- configure
|
34
34
|
|
35
35
|
configure:
|
36
|
-
-
|
36
|
+
- exec apt-get upgrade
|
37
37
|
|
38
38
|
```
|
39
39
|
|
@@ -48,3 +48,46 @@ asteroid server create web
|
|
48
48
|
If everything is configured you should have a new server in the cloud.
|
49
49
|
|
50
50
|
|
51
|
+
## Environments
|
52
|
+
|
53
|
+
Environments are like Rails environments. They allow you to define different settings for your server files depending on what "environment" you are using. The default environment is development.
|
54
|
+
|
55
|
+
```yaml
|
56
|
+
name: web
|
57
|
+
|
58
|
+
environments:
|
59
|
+
|
60
|
+
development:
|
61
|
+
provider:
|
62
|
+
virtual_box:
|
63
|
+
|
64
|
+
# we may want to use VirtualBox locally to
|
65
|
+
# test our setup scripts
|
66
|
+
|
67
|
+
production:
|
68
|
+
provider:
|
69
|
+
digital_ocean:
|
70
|
+
size_id: 61 # DigitalOcean 1gb
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
## Namespaces
|
78
|
+
|
79
|
+
Namespaces are a way of using one DigitalOcean account to support multiple Asteroid projects. For instance, having a namespace of `client-1` would allow you use an Asteroid project for that client and not conflict with your other servers.
|
80
|
+
|
81
|
+
`config/asteroid.rb` should looks like this if you want to use a namespace:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
|
85
|
+
Asteroid::Config.configure(Asteroid.root) do |c|
|
86
|
+
# This line configures a namespace for your servers
|
87
|
+
c.namespace = "my-app"
|
88
|
+
end
|
89
|
+
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
|
data/bin/asteroid
CHANGED
@@ -3,16 +3,18 @@
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib/')
|
4
4
|
|
5
5
|
require 'asteroid'
|
6
|
-
|
6
|
+
|
7
7
|
|
8
8
|
boot_file = File.expand_path('./config/asteroid.rb')
|
9
9
|
if File.exists?(boot_file)
|
10
10
|
require boot_file
|
11
|
-
|
11
|
+
require 'asteroid/application'
|
12
|
+
|
12
13
|
# Existing Application
|
13
14
|
Asteroid::Application::CLI.start ARGV
|
14
15
|
|
15
16
|
else
|
17
|
+
require 'asteroid/application'
|
16
18
|
# new application
|
17
19
|
Asteroid::NewApplication.start ARGV
|
18
20
|
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
Asteroid::Config.providers << Asteroid::Provider::DigitalOcean.new(
|
5
|
-
client_id: Asteroid::Config.
|
6
|
-
api_key: Asteroid::Config.
|
5
|
+
client_id: Asteroid::Config.secret[:digitalocean_client_id],
|
6
|
+
api_key: Asteroid::Config.secret[:digitalocean_api_key]
|
7
7
|
)
|
data/lib/asteroid/config.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module Asteroid
|
2
2
|
|
3
|
+
def self.environment=(env)
|
4
|
+
@environment = env.to_sym
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.environment
|
8
|
+
@environment ||= ENV["ASTEROID_ENV"] || :development
|
9
|
+
end
|
3
10
|
|
4
11
|
def self.root=(root)
|
5
12
|
@root = root
|
@@ -55,6 +62,7 @@ module Asteroid
|
|
55
62
|
@template_engines ||= {}
|
56
63
|
end
|
57
64
|
|
65
|
+
attr_accessor :namespace
|
58
66
|
attr_accessor :asteroid_dir
|
59
67
|
attr_accessor :script_dir
|
60
68
|
attr_accessor :file_dir
|
data/lib/asteroid/generator.rb
CHANGED
@@ -35,7 +35,9 @@ module Asteroid
|
|
35
35
|
cp g('/asteroid/servers/default.yml'), c[:server_dir]
|
36
36
|
|
37
37
|
mkdir c[:config_dir]
|
38
|
-
|
38
|
+
cp_erb g('/config/asteroid.rb'), c[:config_dir], {
|
39
|
+
name: File.basename(@project_root)
|
40
|
+
}
|
39
41
|
|
40
42
|
mkdir c[:secret_dir]
|
41
43
|
touch File.join(c[:secret_dir], '.keep')
|
@@ -65,6 +67,22 @@ module Asteroid
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
70
|
+
def cp_erb(from, to, data)
|
71
|
+
if File.directory?(to)
|
72
|
+
to = File.join(to, File.basename(from))
|
73
|
+
end
|
74
|
+
if File.exists?(to)
|
75
|
+
puts "exists\t#{to}"
|
76
|
+
else
|
77
|
+
puts "add\t#{to}"
|
78
|
+
template_string = File.read from
|
79
|
+
template = Template.new(:erb, template_string)
|
80
|
+
File.open(to, 'w') do |f|
|
81
|
+
f.write template.render data
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
68
86
|
def cp(from, to)
|
69
87
|
if File.directory?(to)
|
70
88
|
to = File.join(to, File.basename(from))
|
data/lib/asteroid/instance.rb
CHANGED
@@ -27,7 +27,8 @@ module Asteroid
|
|
27
27
|
:type,
|
28
28
|
:id,
|
29
29
|
:name,
|
30
|
-
:ip_address
|
30
|
+
:ip_address,
|
31
|
+
:namespace
|
31
32
|
|
32
33
|
|
33
34
|
def initialize(options = {})
|
@@ -41,6 +42,10 @@ module Asteroid
|
|
41
42
|
@name = options.delete :name
|
42
43
|
@ip_address = options.delete :ip_address
|
43
44
|
|
45
|
+
if @name =~ /:/
|
46
|
+
@namespace, @name = @name.split(':', 2)
|
47
|
+
end
|
48
|
+
|
44
49
|
if @name && @type.nil?
|
45
50
|
@type = name.split('-').first.to_sym
|
46
51
|
end
|
@@ -70,9 +75,17 @@ module Asteroid
|
|
70
75
|
|
71
76
|
def self.all
|
72
77
|
instances = Provider.all.instances
|
73
|
-
instances.map do |info|
|
78
|
+
instances = instances.map do |info|
|
74
79
|
new info
|
75
80
|
end
|
81
|
+
|
82
|
+
if Config.namespace
|
83
|
+
instances = instances.delete_if do |i|
|
84
|
+
i.namespace != Config.namespace
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
instances
|
76
89
|
end
|
77
90
|
|
78
91
|
def self.first(type)
|
data/lib/asteroid/server.rb
CHANGED
@@ -37,6 +37,12 @@ module Asteroid
|
|
37
37
|
data = self.class.default_config
|
38
38
|
data.deep_merge! options
|
39
39
|
|
40
|
+
# Merge environment data
|
41
|
+
if env = data.delete(:environments)
|
42
|
+
env = env[Asteroid.environment] || {}
|
43
|
+
data.deep_merge! env
|
44
|
+
end
|
45
|
+
|
40
46
|
@name = data.delete(:name)
|
41
47
|
|
42
48
|
@provider = if data[:provider]
|
@@ -104,7 +110,8 @@ module Asteroid
|
|
104
110
|
end
|
105
111
|
|
106
112
|
def generate_instance_name
|
107
|
-
"#{
|
113
|
+
namespace = Config.namespace ? "#{Config.namespace}:" : ""
|
114
|
+
"#{namespace}#{self.name}-#{SecureRandom.hex(4)}"
|
108
115
|
end
|
109
116
|
|
110
117
|
def create_instance!
|
data/lib/asteroid/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -13,8 +13,10 @@ class TestCase < Minitest::Test
|
|
13
13
|
include Asteroid
|
14
14
|
|
15
15
|
def setup
|
16
|
+
Asteroid.environment = :development
|
16
17
|
Asteroid::Provider::Mock.clear!
|
17
18
|
Asteroid::Config.providers = [Asteroid::Provider::Mock.new]
|
19
|
+
Asteroid::Config.namespace = nil
|
18
20
|
end
|
19
21
|
|
20
22
|
def assert_not_nil o
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestConfig < TestCase
|
4
|
+
|
5
|
+
def test_default_environment
|
6
|
+
assert_equal Asteroid.environment, :development
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_default_namespace
|
10
|
+
n = Asteroid::Config.namespace
|
11
|
+
assert_equal nil, n
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/test/unit/test_instance.rb
CHANGED
data/test/unit/test_server.rb
CHANGED
@@ -22,6 +22,24 @@ class TestServer < TestCase
|
|
22
22
|
assert_respond_to(server.ssh_key, :public)
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_server_env_options
|
26
|
+
env = {
|
27
|
+
development: {
|
28
|
+
ssh_key: 'dev'
|
29
|
+
},
|
30
|
+
production: {
|
31
|
+
ssh_key: 'prod'
|
32
|
+
}
|
33
|
+
}
|
34
|
+
server = Server.new environments: env
|
35
|
+
assert_equal server.ssh_key.name, 'dev'
|
36
|
+
|
37
|
+
Asteroid.environment = :production
|
38
|
+
|
39
|
+
server = Server.new environments: env
|
40
|
+
assert_equal server.ssh_key.name, 'prod'
|
41
|
+
end
|
42
|
+
|
25
43
|
def test_instance_options
|
26
44
|
config = {
|
27
45
|
"whatever" => 123,
|
@@ -48,6 +66,21 @@ class TestServer < TestCase
|
|
48
66
|
assert_equal "4", instance.eval_command("add-two 2")
|
49
67
|
end
|
50
68
|
|
69
|
+
def test_generate_name
|
70
|
+
s = Server.new name: "hyperlinks"
|
71
|
+
|
72
|
+
Asteroid::Config.namespace = nil
|
73
|
+
name = s.generate_instance_name
|
74
|
+
assert_equal "hyperlinks", name.split('-').first
|
75
|
+
|
76
|
+
Asteroid::Config.namespace = "wowcool"
|
77
|
+
name = s.generate_instance_name
|
78
|
+
assert_equal "wowcool:hyperlinks", name.split('-').first
|
79
|
+
|
80
|
+
i = s.create_instance!
|
81
|
+
assert_equal "wowcool", i.namespace
|
82
|
+
end
|
83
|
+
|
51
84
|
def test_server_type
|
52
85
|
s = Server.new name: "web"
|
53
86
|
assert_equal :web, s.type
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asteroid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Murphy
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- sample/config/asteroid.rb
|
210
210
|
- test/helper.rb
|
211
211
|
- test/unit/test_application.rb
|
212
|
+
- test/unit/test_config.rb
|
212
213
|
- test/unit/test_file_reference.rb
|
213
214
|
- test/unit/test_instance.rb
|
214
215
|
- test/unit/test_script_reference.rb
|
@@ -241,6 +242,7 @@ summary: A server configuration framework
|
|
241
242
|
test_files:
|
242
243
|
- test/helper.rb
|
243
244
|
- test/unit/test_application.rb
|
245
|
+
- test/unit/test_config.rb
|
244
246
|
- test/unit/test_file_reference.rb
|
245
247
|
- test/unit/test_instance.rb
|
246
248
|
- test/unit/test_script_reference.rb
|