Class: Engineyard::Jenkins::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/engineyard-jenkins/cli.rb

Instance Method Summary collapse

Instance Method Details

#install(project_path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/engineyard-jenkins/cli.rb', line 12

def install(project_path)
  host, port = host_port(options)
  unless host && port
    say "USAGE: ey-jenkins install . --host HOST --port PORT", :red
    say ""
    say "HOST:PORT default to current jenkins CLI host (set by 'jenkins list --host HOST')"
  else
    tmp_file   = File.join(Dir.tmpdir, "server_pub_key")
    user       = "deploy"
    `scp #{user}@#{host}:~/.ssh/id_rsa.pub #{tmp_file}` # stubbed in fixtures/bin/scp
    public_key = File.read(tmp_file)
  
    require 'engineyard-jenkins/cli/install_generator'
    Engineyard::Jenkins::InstallGenerator.start(ARGV.unshift(project_path, host, port, public_key))
  end
end

#install_server(project_path = nil) ⇒ Object

Generates a chef recipe cookbook, uploads it to AppCloud, and waits until Jenkins CI has launched



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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/engineyard-jenkins/cli.rb', line 34

def install_server(project_path=nil)
  environments = Engineyard::Jenkins::AppcloudEnv.new.find_environments(options)
  if environments.size == 0
    no_environments_discovered and return
  elsif environments.size > 1
    too_many_environments_discovered(environments) and return
  end
  
  env_name, , environment = environments.first
  if environment.instances.first
    public_hostname = environment.instances.first.public_hostname
    status          = environment.instances.first.status
  end
  
  temp_project_path = File.expand_path(project_path || File.join(Dir.tmpdir, "temp_jenkins_server"))
  shell.say "Temp installation dir: #{temp_project_path}" if options[:verbose]
  
  FileUtils.mkdir_p(temp_project_path)
  FileUtils.chdir(temp_project_path) do
    # 'install_server' generator
    require 'engineyard-jenkins/cli/install_server_generator'
    Engineyard::Jenkins::InstallServerGenerator.start(ARGV.unshift(temp_project_path))

    say ""
    say "Uploading to "; say "'#{env_name}' ", :yellow; say "environment on "; say "'#{}' ", :yellow; say "account..."
    require 'engineyard/cli/recipes'
    environment.tar_and_upload_recipes_in_cookbooks_dir

    if status == "running" || status == "error"
      say "Environment is rebuilding..."
      environment.run_custom_recipes
      watch_page_while public_hostname, 80, "/" do |req|
        req.body !~ /Please wait while Jenkins is getting ready to work/
      end

      say ""
      say "Jenkins is starting..."
      watch_page_while public_hostname, 80, "/" do |req|
        req.body =~ /Please wait while Jenkins is getting ready to work/
      end
      
      require 'jenkins'
      require 'jenkins/config'
      ::Jenkins::Config.config["base_uri"] = public_hostname
      ::Jenkins::Config.store!
      
      say ""
      say "Done! Jenkins CI hosted at "; say "http://#{public_hostname}", :green
    else
      say ""
      say "Almost there..."
      say "* Boot your environment via https://cloud.engineyard.com", :yellow
    end
  end
end

#versionObject



91
92
93
94
# File 'lib/engineyard-jenkins/cli.rb', line 91

def version
  require 'engineyard-jenkins/version'
  shell.say Engineyard::Jenkins::VERSION
end