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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c5cc037af98984058dd5b4f265e016566f8f3f
4
- data.tar.gz: f63bd8fd4eb00c4ae7fc2b081c6c132ff8910040
3
+ metadata.gz: 01b1a83d9142f123465b81172dfb371e78c056b1
4
+ data.tar.gz: 904a539da5bfb209e53b2bf9a5ec26f4051433f7
5
5
  SHA512:
6
- metadata.gz: 5b3a7534a6668e92a89ac8c605502017e5bbafe4fa930a856bfc5e6c037bae2eedcd7fe83bbc4c92482bdfd83df1ffb9aa536d656f76b55dbe7912e1d0d3d27d
7
- data.tar.gz: 3d79c608d88e060845516c5424bd1374d04769014acec7961a701ca64de60274c8ce061cb0d6e080776c29f0476556e1710d879345ed680ce90801fcf19a0d20
6
+ metadata.gz: 58f537411b43f906345f495b7eea178e45ede7ed4f84b0d9c49025e3d110ee44a919cc83fae441abbf0ec82dc6580fee97af3b1f60d4a29e7dd126a8e5d02352
7
+ data.tar.gz: 380772b7ea54f831fe0fc40b9c7477412d514ae9fcb1e5d3bb16c5b8bbd1b680db571eefa1a98cdee2aec43347f6efc7186ceda464e8243fbd9dac2c03915bb8
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # gem "aster", path: "/Users/sam/Documents/Projects/aster"
3
+ gem "aster", path: "/Users/sam/Documents/Projects/aster"
4
4
  # Specify your gem's dependencies in asteroid.gemspec
5
5
  gemspec
data/README.md CHANGED
@@ -33,7 +33,7 @@ commands:
33
33
  - configure
34
34
 
35
35
  configure:
36
- - run apt-get upgrade
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
+
@@ -3,16 +3,18 @@
3
3
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib/')
4
4
 
5
5
  require 'asteroid'
6
- require 'asteroid/application'
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
 
@@ -4,6 +4,6 @@ Asteroid.root = File.expand_path(File.join(File.dirname(__FILE__), '../'))
4
4
 
5
5
  Asteroid::Config.configure(Asteroid.root) do |c|
6
6
 
7
-
7
+ c.namespace = "<%= name %>";
8
8
 
9
9
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
 
4
4
  Asteroid::Config.providers << Asteroid::Provider::DigitalOcean.new(
5
- client_id: Asteroid::Config.secrets[:digitalocean_client_id],
6
- api_key: Asteroid::Config.secrets[:digitalocean_api_key]
5
+ client_id: Asteroid::Config.secret[:digitalocean_client_id],
6
+ api_key: Asteroid::Config.secret[:digitalocean_api_key]
7
7
  )
@@ -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
@@ -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
- cp g('/config/asteroid.rb'), c[:config_dir]
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))
@@ -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)
@@ -9,6 +9,10 @@ module Asteroid
9
9
  end
10
10
  end
11
11
 
12
+ def name
13
+ @name
14
+ end
15
+
12
16
  def initialize(name)
13
17
  @name = name
14
18
 
@@ -9,6 +9,9 @@
9
9
  # :status=>"active",
10
10
  # :created_at=>"2014-04-12T20:44:53Z"}
11
11
 
12
+ require 'active_support/concern'
13
+
14
+
12
15
  module Asteroid
13
16
  module Provider
14
17
  class Abstract
@@ -1,5 +1,7 @@
1
+
1
2
  module Asteroid
2
3
  module Provider
4
+
3
5
  class DigitalOcean < Abstract
4
6
 
5
7
  def initialize(config = {})
@@ -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
- "#{self.name}-#{SecureRandom.hex(4)}"
113
+ namespace = Config.namespace ? "#{Config.namespace}:" : ""
114
+ "#{namespace}#{self.name}-#{SecureRandom.hex(4)}"
108
115
  end
109
116
 
110
117
  def create_instance!
@@ -1,3 +1,3 @@
1
1
  module Asteroid
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -30,5 +30,11 @@ class TestInstance < TestCase
30
30
  assert_equal "1234", i["ssh.port"]
31
31
  end
32
32
 
33
+ def test_instance_namespace
34
+ i = Instance.new name: "name:web-23423423"
35
+ assert_equal :web, i.server.type
36
+ assert_equal "name", i.namespace
37
+ end
38
+
33
39
 
34
40
  end
@@ -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.2
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