Class: Ciborg::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ciborg/cli.rb

Instance Method Summary collapse

Instance Method Details

#add_build(name, repository, branch, command) ⇒ Object



95
96
97
98
99
100
# File 'lib/ciborg/cli.rb', line 95

def add_build(name, repository, branch, command)
  raise ciborg_config.errors.join(" and ") unless ciborg_config.valid?

  ciborg_config.add_build(name, repository, branch, command)
  ciborg_config.save
end

#bootstrapObject



77
78
79
80
81
82
# File 'lib/ciborg/cli.rb', line 77

def bootstrap
  sync_bootstrap_script
  master_server.system!("bash -l script/bootstrap_server.sh")
rescue Errno::ECONNRESET
  sleep 1
end

#certificateObject



72
73
74
# File 'lib/ciborg/cli.rb', line 72

def certificate
  say(keychain.fetch_remote_certificate("https://#{ciborg_config.master}"))
end

#chefObject



85
86
87
88
89
90
91
92
# File 'lib/ciborg/cli.rb', line 85

def chef
  sync_chef_recipes
  upload_soloist
  sync_github_ssh_key
  master_server.upload(File.expand_path('../../../templates/Gemfile-remote', __FILE__), 'Gemfile')
  master_server.system!("rvm autolibs enable; bash -l -c 'rvm use 1.9.3; bundle install; soloist'")    rescue Errno::ECONNRESET
  sleep 1
end

#configObject



67
68
69
# File 'lib/ciborg/cli.rb', line 67

def config
  say ciborg_config.display
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ciborg/cli.rb', line 24

def create
  server = amazon.with_key_pair(ciborg_config.server_ssh_pubkey) do |keypair_name|
    amazon.create_security_group(ciborg_config.security_group)
    amazon.open_port(ciborg_config.security_group, 22, 443)
    amazon.launch_server(keypair_name, ciborg_config.security_group, ciborg_config.instance_size, ciborg_config.availability_zone)
  end
  wait_for_server(server)

  say("Writing ip address for ec2: #{server.public_ip_address}")

  ciborg_config.update(master: server.public_ip_address, instance_id: server.id)
end

#create_vagrantObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ciborg/cli.rb', line 51

def create_vagrant
  spawn_env = {"CIBORG_SSH_KEY" => ciborg_config.server_ssh_pubkey_path,
               "VAGRANT_HOME" => File.expand_path("~")}
  spawn_options = {chdir: ciborg_root_path}

  pid = Process.spawn(spawn_env, "vagrant up", spawn_options)
  Process.wait(pid)

  vagrant_ip = "192.168.33.10"

  say("Writing ip address for vagrant: #{vagrant_ip}")

  ciborg_config.update(master: vagrant_ip)
end

#destroy_ec2Object



40
41
42
43
44
45
46
47
48
# File 'lib/ciborg/cli.rb', line 40

def destroy_ec2
  instance = (options['all'] ? :all : ciborg_config.instance_id)

  amazon.destroy_ec2(confirmation_proc(options['force']), instance) do |server|
    say("Clearing ip address for ec2: #{server.public_ip_address}")

    ciborg_config.update(master: nil, instance_id: nil)
  end
end

#openObject



19
20
21
# File 'lib/ciborg/cli.rb', line 19

def open
  exec("open #{ciborg_config.jenkins_url}/")
end

#sshObject



14
15
16
# File 'lib/ciborg/cli.rb', line 14

def ssh
  exec("ssh -i #{ciborg_config.server_ssh_key_path} ubuntu@#{ciborg_config.master} -p #{ciborg_config.ssh_port}")
end

#trust_certificateObject



103
104
105
106
# File 'lib/ciborg/cli.rb', line 103

def trust_certificate
  certificate_contents = keychain.fetch_remote_certificate("https://#{ciborg_config.master}/")
  keychain.add_certificate(certificate_contents)
end