Class: DeusEx::AWS
- Inherits:
-
Object
- Object
- DeusEx::AWS
- Defined in:
- lib/deus_ex/aws.rb
Constant Summary collapse
- IMAGE_ID =
'ami-3679e75f'- DEPLOY_PROJECT =
'deus_ex_project'- REMOTE_USER =
'ubuntu'- GIT_REMOTE_NAME =
'deus-ex'
Class Method Summary collapse
Instance Method Summary collapse
- #clean_up ⇒ Object
- #git_remote ⇒ Object
- #log(message, level = :info, logger = Logger.new($stdout)) ⇒ Object
- #setup_connection ⇒ Object
- #setup_git_remote ⇒ Object
- #setup_repository ⇒ Object
- #setup_server ⇒ Object
- #warn(message) ⇒ Object
Class Method Details
.cleanup ⇒ Object
22 23 24 25 26 |
# File 'lib/deus_ex/aws.rb', line 22 def self.cleanup aws = new aws.setup_connection aws.clean_up end |
.setup ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/deus_ex/aws.rb', line 10 def self.setup aws = new aws.setup_connection aws.setup_server aws.setup_repository aws.setup_git_remote rescue Exception => e aws.log "error: #{e.inspect}" aws.clean_up raise e end |
Instance Method Details
#clean_up ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/deus_ex/aws.rb', line 72 def clean_up if @server @server.destroy else @connection.servers.select {|s| s.image_id == IMAGE_ID}.map(&:destroy) end log "server destroyed" end |
#git_remote ⇒ Object
81 82 83 |
# File 'lib/deus_ex/aws.rb', line 81 def git_remote "#{REMOTE_USER}@#{@server.dns_name}:#{DEPLOY_PROJECT}.git" end |
#log(message, level = :info, logger = Logger.new($stdout)) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/deus_ex/aws.rb', line 85 def log(, level = :info, logger = Logger.new($stdout)) logger.formatter = proc do |severity, datetime, progname, msg| "[DEUS EX] #{msg}\n" end logger.send(level, ) end |
#setup_connection ⇒ Object
28 29 30 31 32 33 |
# File 'lib/deus_ex/aws.rb', line 28 def setup_connection @connection = Fog::Compute.new({ :provider => 'AWS' }) log "connection established" end |
#setup_git_remote ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/deus_ex/aws.rb', line 54 def setup_git_remote if system('git rev-parse') log "adding local git remote" system "git remote add #{GIT_REMOTE_NAME} #{git_remote}" log "pushing to remote" system "git push #{GIT_REMOTE_NAME} master" log "removing local git remote" system "git remote rm #{GIT_REMOTE_NAME}" log "" log "you can now deploy from #{git_remote}" else warn "not in a git repo" end end |
#setup_repository ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/deus_ex/aws.rb', line 44 def setup_repository log "initializing git repo" @server.ssh([ "mkdir #{DEPLOY_PROJECT}.git", "cd #{DEPLOY_PROJECT}.git && git init --bare" ]) log "git repo initialized" end |
#setup_server ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/deus_ex/aws.rb', line 35 def setup_server log "creating server (this may take a couple of minutes)" @server = @connection.servers.bootstrap({ :image_id => IMAGE_ID, :username => REMOTE_USER }) log "server created" end |
#warn(message) ⇒ Object
93 94 95 |
# File 'lib/deus_ex/aws.rb', line 93 def warn() log , :warn end |