class Conjure::Server

Public Class Methods

create(name_prefix, options = {}) click to toggle source
# File lib/conjure/server.rb, line 21
def self.create(name_prefix, options = {})
  new DigitalOcean::Droplet.new(droplet_options(name_prefix, options)).ip_address
end
droplet_options(name_prefix, options = {}) click to toggle source
# File lib/conjure/server.rb, line 25
def self.droplet_options(name_prefix, options = {})
  {
    image: "docker",
    key_data: key_data,
    name_prefix: name_prefix,
    region: "nyc3",
    size: (options[:instance_size] || "512mb"),
  }
end
key_data() click to toggle source
# File lib/conjure/server.rb, line 35
def self.key_data
  ssh_dir = File.expand_path "~/.ssh"
  raise "Error: ~/.ssh/id_rsa.pub must exist." unless File.exist?(ssh_dir) && File.exist?("#{ssh_dir}/id_rsa.pub")
  File.read "#{ssh_dir}/id_rsa.pub"
end
ssh_options() click to toggle source
# File lib/conjure/server.rb, line 13
def self.ssh_options
  "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR"
end

Public Instance Methods

quote_command(command) click to toggle source
# File lib/conjure/server.rb, line 17
def quote_command(command)
  "'" + command.gsub("'", "'\"'\"'") + "'"
end
run(command) click to toggle source
# File lib/conjure/server.rb, line 5
def run(command)
  `ssh #{self.class.ssh_options} root@#{ip_address} #{quote_command command}`
end
send_file(local_name, remote_name) click to toggle source
# File lib/conjure/server.rb, line 9
def send_file(local_name, remote_name)
  `scp #{self.class.ssh_options} #{local_name} root@#{ip_address}:#{remote_name}`
end