Class: Ober::Installer
- Inherits:
-
Object
- Object
- Ober::Installer
- Defined in:
- lib/ober/installer.rb
Instance Method Summary collapse
- #git_clone(app, source, version) ⇒ Object
-
#initialize(environment) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #install_app(app) ⇒ Object
- #runner ⇒ Object
- #validate_app(app) ⇒ Object
Constructor Details
#initialize(environment) ⇒ Installer
Returns a new instance of Installer.
10 11 12 |
# File 'lib/ober/installer.rb', line 10 def initialize environment @environment = environment end |
Instance Method Details
#git_clone(app, source, version) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ober/installer.rb', line 66 def git_clone app, source, version opts = { user: app.user, cwd: app.root } runner.run "git clone #{source} .", opts do |ex| raise ex unless ex.to_s.match(%r(fatal: destination path '.' already exists)) "Already exists, error ignored." end runner.run "git fetch #{source}", opts runner.run "git reset --hard #{version}", opts end |
#install ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ober/installer.rb', line 14 def install @environment.apps.each do |app| puts "Installing app #{app.name}..." install_app app end end |
#install_app(app) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ober/installer.rb', line 25 def install_app app validate_app app # This rather nasty trick ensures that other users can use our # ssh agent forwarding too. Allows for git checkouts but also take # over of all your base. if ENV['SSH_CONNECTION'] && ENV['SSH_AUTH_SOCK'] puts "Opening up your ssh connection forwarding to all users on this machine." puts "WARNING: This is a bad thing on multi user machines. Don't use this tool" puts "in such an environment." puts ssh_auth_sock = ENV['SSH_AUTH_SOCK'] FileUtils.chmod(0777, File.dirname(ssh_auth_sock)) FileUtils.chmod(0666, ssh_auth_sock) end # Makes sure the directory exists root = Pathname.new(app.root) unless root.directory? FileUtils.mkdir_p(root) FileUtils.chown(app.user, nil, root) if app.user end # Installs the git source code and resets to the given version if app.git url, = app.git git_clone app, url, [:version] || 'master' end # If we need to use RVM, create another object that takes care of # running things for us. r = runner if app.rvm r = Runner::RVM.new(app.rvm) end # Makes sure all the gems are installed r.run 'bundle install --deployment', cwd: app.root, user: app.user end |
#runner ⇒ Object
21 22 23 |
# File 'lib/ober/installer.rb', line 21 def runner Runner.new end |
#validate_app(app) ⇒ Object
77 78 79 80 |
# File 'lib/ober/installer.rb', line 77 def validate_app app fail 'Application has no root. Please set one: root "some/path"' unless app.root end |