deus_ex 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: 5e90453d65142296451cb08da20fe1d7ca0375cc
4
- data.tar.gz: 71525b343f4570674a6c718dd27191cf4c130b19
3
+ metadata.gz: cb5caff6d219417b552cc49fd248b2c37469c02d
4
+ data.tar.gz: 76d50c97a3f9ef992c4ef81fca3c63aff2cd7064
5
5
  SHA512:
6
- metadata.gz: 258effc6cfdcf61c63d09d0e549e6f00df30d8d4e91e3e8910b131c5cfc810fc63a60bf38a9110c2d77e3c4579bd88af9df8877266ca13c76bf46a8fe5f883dd
7
- data.tar.gz: 56c40f0def41dc501d6ec593e017741a0cc0ccd3d77c1a5b9dfb68461616626469ff604b8d29943f7f135468f81fb454d62211c2edd023533641fb4a60fdd473
6
+ metadata.gz: 759476904690e49ca6d257d7c0c62389ebbd78be54fa8811ef7f2f8b8d9e980c9dc6328f37357eb1c4b3bfceca33b8c4f7ad2764717b52f1dcc489d505e477d6
7
+ data.tar.gz: 9f9ecc54ab7b1ee9a9b893f2874f9229eabb131fcf4463755cc4c2ba161e3314753a12e3bb4a0e024533f99b17ef8ac6dccdb043502fdeee201d544a6b6827eb
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # DeusEx
2
2
 
3
3
  GitHub DDOSings getting you down and stopping your deploys? GIT IS DISTRIBUTED, SUCKA. The deus_ex gem allows you to easily
4
- fire up an AWS instance, push your repo to it, and use that for your deploy until GitHub is back on its feet.
4
+ fire up cloud instance, push your repo to it, and use that for your deploy until GitHub is back on its feet.
5
5
 
6
6
  ## Installation
7
7
 
@@ -17,13 +17,41 @@ Or install it yourself as:
17
17
 
18
18
  $ gem install deus_ex
19
19
 
20
- The gem uses [fog](http://fog.io/) to manage the connection to AWS, so you'll need to put your AWS credentials into `~/.fog`, like so:
20
+ The gem uses [fog](http://fog.io/) to manage the connection to various cloud providers, so you'll need to put your credentials into `.machina.yml`, like so:
21
+
22
+ ---
23
+ :authentication:
24
+ :provider: 'aws'
25
+ :aws_access_key_id: my_access_key
26
+ :aws_secret_access_key: my_secret_access_key
27
+ :server_create:
28
+ :flavor_ref: 't1.micro'
29
+ :image_ref: 'ami-a9184ac0'
30
+ :key_name: 'bover'
31
+ :username: ubuntu
32
+ :private_key_path: /home/terry/.ssh/bover.pem
33
+
34
+ Here is an OpenStack example to get a better idea of all the options available:
35
+
36
+ ---
37
+ :authentication:
38
+ :provider: 'openstack'
39
+ :openstack_username: '***********'
40
+ :openstack_api_key: '*************'
41
+ :openstack_auth_url: 'https://cloud.example.com:35357/v2.0/tokens'
42
+ :openstack_tenant: 'tenant_name'
43
+ :openstack_region: 'region-b.geo-1'
44
+ :server_create:
45
+ :flavor_ref: '103'
46
+ :image_ref: '8c096c29-a666-4b82-99c4-c77dc70cfb40'
47
+ :key_name: 'bover'
48
+ :nics: [ 'net_id': '76abe0b1-581a-4698-b200-a2e890f4eb8d' ]
49
+ :floating_ip_create:
50
+ :floating_network_id: '7da74520-9d5e-427b-a508-213c84e69616'
51
+ :public_key_path: /home/terry/.ssh/bover.pub
52
+ :private_key_path: /home/terry/.ssh/bover.pem
53
+ :username: ubuntu
21
54
 
22
- default:
23
- aws_access_key_id: my_access_key
24
- aws_secret_access_key: my_secret_access_key
25
- public_key_path: ~/.ssh/id_rsa.pub
26
- private_key_path: ~/.ssh/id_rsa
27
55
 
28
56
  ## Usage
29
57
 
@@ -31,11 +59,18 @@ Once the gem's bundled, run the following to create your temporary instance:
31
59
 
32
60
  $ bundle exec deus_ex
33
61
 
34
- The gem will tell you what it's doing, and will give you the git URL for your new deploy-fromable repo. Use that for your deploy,
35
- then tear down your instance with
62
+ The gem will tell you what it's doing, and will give you the git URL for your new deploy-fromable repo. Use that for your deploy, then tear down your instance with
36
63
 
37
64
  $ bundle exec deus_ex cleanup
38
65
 
66
+ You can check to see if you have any active deus_ex instances running, as well:
67
+
68
+ $ bundle exec deus_ex status
69
+
70
+ ## Warning!
71
+
72
+ This may not work if your app has dependencies on GitHub beyond the deployment repository -- if you're using git URLs for gems, for instance.
73
+
39
74
  ## Contributing
40
75
 
41
76
  1. Fork it
data/TODO.md CHANGED
@@ -1,5 +1,4 @@
1
1
  ### GENERAL
2
- * Detect missing credentials
3
2
  * Specify SSH identity to use in the git push
4
3
 
5
4
  ### CAPISTRANO
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'deus_ex'))
3
3
 
4
- if ARGV.length > 0 && ARGV[0] == 'cleanup'
5
- DeusEx.cleanup
4
+ if ARGV.length > 0
5
+ DeusEx.send(ARGV[0].to_s)
6
6
  else
7
7
  DeusEx.setup
8
8
  end
@@ -6,10 +6,10 @@ require 'deus_ex/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "deus_ex"
8
8
  spec.version = DeusEx::VERSION
9
- spec.authors = ["Ben Scofield"]
9
+ spec.authors = ["Ben Scofield", "Terry Howe"]
10
10
  spec.email = ["bscofield@gmail.com"]
11
- spec.description = %q{Easily manage just-in-time EC2 git repos}
12
- spec.summary = %q{Easily manage just-in-time EC2 git repos}
11
+ spec.description = %q{Easily manage just-in-time git repos}
12
+ spec.summary = %q{Easily manage just-in-time git repos}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -1,13 +1,17 @@
1
1
  require 'bundler/setup'
2
2
  require 'fog'
3
- require File.join(File.dirname(__FILE__), 'deus_ex', 'aws')
3
+ require File.join(File.dirname(__FILE__), 'deus_ex', 'machina')
4
4
 
5
5
  module DeusEx
6
6
  def self.setup
7
- DeusEx::AWS.setup
7
+ DeusEx::Machina.setup
8
8
  end
9
-
9
+
10
10
  def self.cleanup
11
- DeusEx::AWS.cleanup
11
+ DeusEx::Machina.cleanup
12
+ end
13
+
14
+ def self.status
15
+ DeusEx::Machina.status
12
16
  end
13
17
  end
@@ -0,0 +1,171 @@
1
+ require 'logger'
2
+ require 'yaml'
3
+
4
+ module DeusEx
5
+ class Machina
6
+ NAME = 'deus_ex'
7
+ DEPLOY_PROJECT = 'deus_ex_project'
8
+ GIT_REMOTE_NAME = 'deus-ex'
9
+
10
+ def self.setup
11
+ machina = new
12
+ machina.config_read
13
+ machina.setup_server
14
+ machina.setup_repository
15
+ machina.setup_git_remote
16
+ rescue Exception => e
17
+ if e.is_a?(SystemExit)
18
+ machina.log "Exiting"
19
+ else
20
+ machina.log "error: #{e.inspect}"
21
+ machina.clean_up
22
+ raise e
23
+ end
24
+ end
25
+
26
+ def self.cleanup
27
+ machina = new
28
+ machina.config_read
29
+ machina.clean_up
30
+ rescue Exception => e
31
+ if e.is_a?(SystemExit)
32
+ machina.log "Exiting"
33
+ else
34
+ machina.log "error: #{e.inspect}"
35
+ machina.clean_up
36
+ raise e
37
+ end
38
+ end
39
+
40
+ def self.status
41
+ machina = new
42
+ machina.config_read
43
+ machina.status
44
+ rescue Exception => e
45
+ if e.is_a?(SystemExit)
46
+ machina.log "Exiting"
47
+ else
48
+ machina.log "error: #{e.inspect}"
49
+ machina.clean_up
50
+ raise e
51
+ end
52
+ end
53
+
54
+ def compute
55
+ connection = ::Fog::Compute.new(@config[:authentication].dup)
56
+ log "connection established"
57
+ connection
58
+ end
59
+
60
+ def network
61
+ authentication = @config[:authentication].dup
62
+ authentication.delete(:version)
63
+ ::Fog::Network.new(authentication)
64
+ end
65
+
66
+ def config_read
67
+ @config = YAML.load_file('.machina.yml') if @config.nil?
68
+ end
69
+
70
+ def setup_server
71
+ log "creating server (this may take a couple of minutes)"
72
+ server_config = @config[:server_create].dup
73
+ server_config[:name] = NAME
74
+ @server = compute.servers.create(server_config)
75
+ log "server created"
76
+ @server.wait_for { print '.'; ready? }
77
+ log "server ready"
78
+ if @config[:floating_ip_create].nil?
79
+ @ip = @server.public_ip_address
80
+ else
81
+ create_floating_ip
82
+ end
83
+ log "server ip " + @ip
84
+ end
85
+
86
+ def create_floating_ip
87
+ floater = network.floating_ips.create(@config[:floating_ip_create])
88
+ floating_id = floater.id
89
+ @ip = floater.floating_ip_address
90
+ @port = 22
91
+ port = network.ports(:filters => { :device_id => @server.id }).first
92
+ network.associate_floating_ip(floating_id, port.id)
93
+ end
94
+
95
+ def test_ssh
96
+ socket = TCPSocket.new(@ip, @port)
97
+ IO.select([socket], nil, nil, 5)
98
+ rescue SocketError, Errno::ECONNREFUSED,
99
+ Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError
100
+ sleep 2
101
+ false
102
+ rescue Errno::EPERM, Errno::ETIMEDOUT
103
+ false
104
+ ensure
105
+ socket && socket.close
106
+ end
107
+
108
+ def setup_repository
109
+ log "initializing git repo"
110
+ @server.private_key_path = @config[:private_key_path]
111
+ ssh_options = {
112
+ :port => @port,
113
+ :key_data => [File.read(@config[:private_key_path])],
114
+ :auth_methods => ["publickey"]
115
+ }
116
+ log "." until test_ssh
117
+ Fog::SSH.new(@ip, @config[:username], ssh_options).run([
118
+ "mkdir #{DEPLOY_PROJECT}.git",
119
+ "cd #{DEPLOY_PROJECT}.git && git init --bare"
120
+ ])
121
+ log "git repo initialized"
122
+ end
123
+
124
+ def setup_git_remote
125
+ if system('git rev-parse')
126
+ log "adding local git remote"
127
+ system "git remote add #{GIT_REMOTE_NAME} #{git_remote}"
128
+
129
+ log "pushing to remote"
130
+ system "ssh-agent bash -c 'ssh-add #{@config[:private_key_path]}; git push #{GIT_REMOTE_NAME} master'"
131
+
132
+ log "removing local git remote"
133
+ system "git remote rm #{GIT_REMOTE_NAME}"
134
+
135
+ log ""
136
+ log "you can now deploy from #{git_remote}"
137
+ else
138
+ warn "not in a git repo"
139
+ end
140
+ end
141
+
142
+ def clean_up
143
+ destroyed = servers.map(&:destroy).count
144
+ log "#{destroyed} server#{'s' if destroyed != 1} destroyed"
145
+ end
146
+
147
+ def status
148
+ log "#{servers.count} server#{'s' if servers.count != 1} found"
149
+ end
150
+
151
+ def servers
152
+ @server ? [@server] : compute.servers.select { |s| s.name == NAME }
153
+ end
154
+
155
+ def git_remote
156
+ "#{@config[:username]}@#{@server.public_ip_address}:#{DEPLOY_PROJECT}.git"
157
+ end
158
+
159
+ def log(message, level = :info, logger = Logger.new($stdout))
160
+ logger.formatter = proc do |severity, datetime, progname, msg|
161
+ "[DEUS EX] #{msg}\n"
162
+ end
163
+
164
+ logger.send(level, message)
165
+ end
166
+
167
+ def warn(message)
168
+ log message, :warn
169
+ end
170
+ end
171
+ end
@@ -1,3 +1,3 @@
1
1
  module DeusEx
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deus_ex
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
  - Ben Scofield
8
+ - Terry Howe
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
12
+ date: 2013-10-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -66,7 +67,7 @@ dependencies:
66
67
  - - '>='
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
- description: Easily manage just-in-time EC2 git repos
70
+ description: Easily manage just-in-time git repos
70
71
  email:
71
72
  - bscofield@gmail.com
72
73
  executables:
@@ -83,7 +84,7 @@ files:
83
84
  - bin/deus_ex
84
85
  - deus_ex.gemspec
85
86
  - lib/deus_ex.rb
86
- - lib/deus_ex/aws.rb
87
+ - lib/deus_ex/machina.rb
87
88
  - lib/deus_ex/version.rb
88
89
  homepage: ''
89
90
  licenses:
@@ -105,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  requirements: []
107
108
  rubyforge_project:
108
- rubygems_version: 2.0.7
109
+ rubygems_version: 2.1.3
109
110
  signing_key:
110
111
  specification_version: 4
111
- summary: Easily manage just-in-time EC2 git repos
112
+ summary: Easily manage just-in-time git repos
112
113
  test_files: []
@@ -1,97 +0,0 @@
1
- require 'logger'
2
-
3
- module DeusEx
4
- class AWS
5
- IMAGE_ID = 'ami-3679e75f'
6
- DEPLOY_PROJECT = 'deus_ex_project'
7
- REMOTE_USER = 'ubuntu'
8
- GIT_REMOTE_NAME = 'deus-ex'
9
-
10
- def self.setup
11
- aws = new
12
- aws.setup_connection
13
- aws.setup_server
14
- aws.setup_repository
15
- aws.setup_git_remote
16
- rescue Exception => e
17
- aws.log "error: #{e.inspect}"
18
- aws.clean_up
19
- raise e
20
- end
21
-
22
- def self.cleanup
23
- aws = new
24
- aws.setup_connection
25
- aws.clean_up
26
- end
27
-
28
- def setup_connection
29
- @connection = Fog::Compute.new({
30
- :provider => 'AWS'
31
- })
32
- log "connection established"
33
- end
34
-
35
- def setup_server
36
- log "creating server (this may take a couple of minutes)"
37
- @server = @connection.servers.bootstrap({
38
- :image_id => IMAGE_ID,
39
- :username => REMOTE_USER
40
- })
41
- log "server created"
42
- end
43
-
44
- def setup_repository
45
- log "initializing git repo"
46
- @server.ssh([
47
- "mkdir #{DEPLOY_PROJECT}.git",
48
- "cd #{DEPLOY_PROJECT}.git && git init --bare"
49
- ])
50
-
51
- log "git repo initialized"
52
- end
53
-
54
- def setup_git_remote
55
- if system('git rev-parse')
56
- log "adding local git remote"
57
- system "git remote add #{GIT_REMOTE_NAME} #{git_remote}"
58
-
59
- log "pushing to remote"
60
- system "git push #{GIT_REMOTE_NAME} master"
61
-
62
- log "removing local git remote"
63
- system "git remote rm #{GIT_REMOTE_NAME}"
64
-
65
- log ""
66
- log "you can now deploy from #{git_remote}"
67
- else
68
- warn "not in a git repo"
69
- end
70
- end
71
-
72
- def clean_up
73
- if @server
74
- @server.destroy
75
- else
76
- @connection.servers.select {|s| s.image_id == IMAGE_ID}.map(&:destroy)
77
- end
78
- log "server destroyed"
79
- end
80
-
81
- def git_remote
82
- "#{REMOTE_USER}@#{@server.dns_name}:#{DEPLOY_PROJECT}.git"
83
- end
84
-
85
- def log(message, level = :info, logger = Logger.new($stdout))
86
- logger.formatter = proc do |severity, datetime, progname, msg|
87
- "[DEUS EX] #{msg}\n"
88
- end
89
-
90
- logger.send(level, message)
91
- end
92
-
93
- def warn(message)
94
- log message, :warn
95
- end
96
- end
97
- end