engineyard-jenkins 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- engineyard-jenkins (0.4.0)
4
+ engineyard-jenkins (0.5.0)
5
5
  engineyard (~> 1.3.17)
6
- jenkins (~> 0.6.2)
6
+ jenkins (~> 0.6.4)
7
7
  thor (~> 0.14.6)
8
8
 
9
9
  GEM
@@ -39,10 +39,11 @@ GEM
39
39
  hpricot (0.8.4)
40
40
  httparty (0.6.1)
41
41
  crack (= 0.1.8)
42
- jenkins (0.6.2)
43
- builder (>= 2.1.2)
42
+ jenkins (0.6.4)
43
+ builder (~> 2.1.2)
44
44
  hpricot
45
45
  httparty (~> 0.6.1)
46
+ json_pure (>= 1.5.1)
46
47
  term-ansicolor (>= 1.0.4)
47
48
  thor (~> 0.14.2)
48
49
  json (1.4.6)
data/History.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # History
2
2
 
3
+ ## 0.5.0 - 2011-4-13
4
+
5
+ Command 'install':
6
+
7
+ * Can specify alternate host or use default from "jenkins" CLI
8
+ * Pulls master public key via scp
9
+
3
10
  ## 0.4.0 - 2011-4-11
4
11
 
5
12
  * Rename to engineyard-jenkins
data/README.md CHANGED
@@ -20,9 +20,9 @@ This will also install the `jenkins` CLI to interact with your Jenkins CI from t
20
20
 
21
21
  ## Hosting on Engine Yard AppCloud
22
22
 
23
- Using Engine Yard AppCloud "Quick Start" wizard, create an application with Git Repo `git://github.com/engineyard/jenkins_server.git` (options: rails 3, passenger), and add your own SSH keys. This will create an environment called `jenkins_server_production`. Boot the environment as a Single instance (or Custom cluster with a single instance).
23
+ Using Engine Yard AppCloud "Quick Start" wizard, create an application with Git Repo `git://github.com/engineyard/jenkins_holding_page.git` (options: rails 3, passenger), and add your own SSH keys. This will create an environment called `jenkins_server_production`. Boot the environment as a Single instance (or Custom cluster with a single instance).
24
24
 
25
- Optionally, though it is quite pretty, deploy/ship the jenkins_server application and visit the HTTP link to see the remaining "Almost there..." instructions.
25
+ Optionally, though it is quite pretty, deploy/ship the `jenkins_holding_page` application and visit the HTTP link to see the remaining "Almost there..." instructions.
26
26
 
27
27
  Finally, install Jenkins CI and rebuild the environment:
28
28
 
@@ -4,4 +4,14 @@ $:.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
4
  require 'engineyard-jenkins'
5
5
  require 'engineyard-jenkins/cli'
6
6
 
7
- Engineyard::Jenkins::CLI.start
7
+ begin
8
+ Engineyard::Jenkins::CLI.start
9
+ rescue EY::Error => e
10
+ EY.ui.print_exception(e)
11
+ exit(1)
12
+ rescue Interrupt => e
13
+ puts
14
+ EY.ui.print_exception(e)
15
+ EY.ui.say("Quitting...")
16
+ exit(1)
17
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "engineyard-jenkins"
5
- s.version = '0.4.0'
5
+ s.version = '0.5.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Dr Nic Williams"]
8
8
  s.email = ["drnicwilliams@gmail.com"]
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency("thor", ["~> 0.14.6"])
21
21
  s.add_dependency("engineyard", ["~> 1.3.17"])
22
- s.add_dependency("jenkins", ["~> 0.6.2"])
22
+ s.add_dependency("jenkins", ["~> 0.6.4"])
23
23
 
24
24
  s.add_development_dependency("rake", ["~> 0.8.7"])
25
25
  s.add_development_dependency("cucumber", ["~> 0.9.4"])
@@ -1,13 +1,25 @@
1
1
  Feature: Managing a rails project as a Jenkins CI job on AppCloud
2
2
  I want to build/test my project in the same environment I run in Engine Yard AppCloud
3
+
4
+ Scenario: Fail to setup Jenkins slave if no default Jenkins server
5
+ Given I am in the "rails" project folder
6
+ When I run local executable "ey-jenkins" with arguments "install ."
7
+ Then I should see exactly
8
+ """
9
+ USAGE: ey-jenkins install . --host HOST --port PORT
10
+
11
+ HOST:PORT default to current jenkins CLI host (set by 'jenkins list --host HOST')
12
+ """
3
13
 
4
14
  Scenario: Setup first project as a slave for Jenkins
5
15
  Given I am in the "rails" project folder
6
- When I run local executable "ey-jenkins" with arguments "install ."
16
+ And I have public key "PUBLIC_KEY" on host "ci.mycompany.com"
17
+ When I run local executable "ey-jenkins" with arguments "install . --host ci.mycompany.com"
7
18
  Then file "cookbooks/jenkins_slave/attributes/default.rb" is created
8
19
  And file "cookbooks/jenkins_slave/recipes/default.rb" is created
9
20
  And file "cookbooks/main/recipes/default.rb" is created
10
21
  And file "cookbooks/main/libraries/ruby_block.rb" is created
22
+ And file "cookbooks/jenkins_slave/attributes/default.rb" contains "ci.mycompany.com"
11
23
  And I should see exactly
12
24
  """
13
25
  create cookbooks
@@ -29,12 +41,15 @@ Feature: Managing a rails project as a Jenkins CI job on AppCloud
29
41
 
30
42
  Scenario: Setup project with existing cookbooks as a slave for Jenkins
31
43
  Given I am in the "rails" project folder
44
+ And I set "ci.mycompany.com" as the default Jenkins server
45
+ And I have public key "PUBLIC_KEY" on host "ci.mycompany.com"
32
46
  And I already have cookbooks installed
33
47
  When I run local executable "ey-jenkins" with arguments "install ."
34
48
  Then file "cookbooks/jenkins_slave/attributes/default.rb" is created
35
49
  And file "cookbooks/jenkins_slave/recipes/default.rb" is created
36
50
  And file "cookbooks/main/recipes/default.rb" is created
37
51
  And file "cookbooks/redis/recipes/default.rb" is created
52
+ And file "cookbooks/jenkins_slave/attributes/default.rb" contains "ci.mycompany.com"
38
53
  And I should see exactly
39
54
  """
40
55
  create cookbooks/jenkins_slave/attributes/default.rb
@@ -10,7 +10,7 @@ Feature: Managing ey jenkins server
10
10
  When I run local executable "ey-jenkins" with arguments "install_server . --account account_2 --environment giblets"
11
11
  Then file "cookbooks/main/recipes/default.rb" is created
12
12
  And file "cookbooks/jenkins_master/recipes/default.rb" is created
13
- And file "cookbooks/jenkins_master/attributes/default.rb" contains ":plugins => %w[git github rake ruby greenballs envfile]"
13
+ And file "cookbooks/jenkins_master/attributes/default.rb" contains ":plugins => %w[git-1.1.6 github-0.4 rake-1.7.6 ruby-1.2 greenballs-1.10 envfile-1.1]"
14
14
  And I should see exactly
15
15
  """
16
16
  create cookbooks
@@ -36,10 +36,10 @@ Feature: Managing ey jenkins server
36
36
 
37
37
  @wip
38
38
  Scenario: Install Jenkins CI server with additional Jenkins plugins
39
- When I run local executable "ey-jenkins" with arguments "install_server . -p ' chucknorris , googleanalytics ' -c account_2 -e giblets"
39
+ When I run local executable "ey-jenkins" with arguments "install_server . -p ' chucknorris-1.2.3 , googleanalytics-1.2.3 ' -c account_2 -e giblets"
40
40
  Then file "cookbooks/main/recipes/default.rb" is created
41
41
  And file "cookbooks/jenkins_master/recipes/default.rb" is created
42
- And file "cookbooks/jenkins_master/attributes/default.rb" contains ":plugins => %w[git github rake ruby greenballs envfile chucknorris googleanalytics]"
42
+ And file "cookbooks/jenkins_master/attributes/default.rb" contains ":plugins => %w[git-1.1.6 github-0.4 rake-1.7.6 ruby-1.2 greenballs-1.10 envfile-1.1 chucknorris-1.2.3 googleanalytics-1.2.3]"
43
43
 
44
44
  Scenario: Display example explicit calls if multiple accounts/options
45
45
  When I run local executable "ey-jenkins" with arguments "install_server . -e giblets"
@@ -7,3 +7,15 @@ Given /^I want to fake out the boot sequence of Jenkins$/ do
7
7
  ])
8
8
  end
9
9
 
10
+ Given /^I have public key "([^"]*)" on host "([^"]*)"$/ do |public_key_value, host|
11
+ mock_target = File.expand_path("../../../tmp/scp_mock", __FILE__)
12
+ File.open(mock_target, "w") { |file| file << public_key_value }
13
+ end
14
+
15
+ Given /^I set "([^"]*)" as the default Jenkins server$/ do |host|
16
+ require "jenkins"
17
+ require "jenkins/config"
18
+ Jenkins::Api.setup_base_url(:host => host, :port => 80)
19
+ Jenkins::Api.send(:cache_base_uri)
20
+ end
21
+
@@ -2,6 +2,8 @@ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../lib'))
2
2
  require 'bundler/setup'
3
3
  require 'engineyard-jenkins'
4
4
 
5
+ path = ENV['PATH']
6
+
5
7
  Before do
6
8
  @tmp_root = File.dirname(__FILE__) + "/../../tmp"
7
9
  @active_project_folder = @tmp_root
@@ -11,4 +13,6 @@ Before do
11
13
  FileUtils.rm_rf @tmp_root
12
14
  FileUtils.mkdir_p @home_path
13
15
  ENV['HOME'] = @home_path
16
+ fixture_bin_path = File.expand_path('../../../fixtures/bin', __FILE__)
17
+ ENV['PATH'] = fixture_bin_path + ":" + path
14
18
  end
@@ -0,0 +1,4 @@
1
+ # Stubbed bin scripts
2
+
3
+ If a bin/executable script is used by the CLI, a fake version is provided here during the test suites, as necessary.
4
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+
5
+ mock_target = File.expand_path("../../../tmp/scp_mock", __FILE__)
6
+ FileUtils.cp_r(mock_target, ARGV[-1])
@@ -42,7 +42,9 @@ module Engineyard
42
42
  # Currently the engineyard gem has badly formed URLs in its same data
43
43
  # This method cleans app_master_hostname.compute-1.amazonaws.com -> app-master-hostname.compute-1.amazonaws.com
44
44
  def clean_host_name(environment)
45
- environment.instances.first.public_hostname.gsub!(/_/,'-') if environment.instances.first
45
+ if environment.instances.first && environment.instances.first.public_hostname
46
+ environment.instances.first.public_hostname.gsub!(/_/,'-')
47
+ end
46
48
  end
47
49
  end
48
50
  end
@@ -7,9 +7,23 @@ module Engineyard
7
7
  class CLI < Thor
8
8
 
9
9
  desc "install PROJECT_PATH", "Install Jenkins node/slave recipes into your project."
10
+ method_option :host, :aliases => ['-h'], :desc => "Override Jenkins CI server host"
11
+ method_option :port, :aliases => ['-p'], :desc => "Override Jenkins CI server port"
10
12
  def install(project_path)
11
- require 'engineyard-jenkins/cli/install_generator'
12
- Engineyard::Jenkins::InstallGenerator.start(ARGV.unshift(project_path))
13
+ host, port = host_port(options)
14
+ unless host && port
15
+ say "USAGE: ey-jenkins install . --host HOST --port PORT", :red
16
+ say ""
17
+ say "HOST:PORT default to current jenkins CLI host (set by 'jenkins list --host HOST')"
18
+ else
19
+ tmp_file = File.join(Dir.tmpdir, "server_pub_key")
20
+ user = "deploy"
21
+ `scp #{user}@#{host}:~/.ssh/id_rsa.pub #{tmp_file}` # stubbed in fixtures/bin/scp
22
+ public_key = File.read(tmp_file)
23
+
24
+ require 'engineyard-jenkins/cli/install_generator'
25
+ Engineyard::Jenkins::InstallGenerator.start(ARGV.unshift(project_path, host, port, public_key))
26
+ end
13
27
  end
14
28
 
15
29
  desc "install_server [PROJECT_PATH]", "Install Jenkins CI into an AppCloud environment."
@@ -45,7 +59,7 @@ module Engineyard
45
59
  require 'engineyard/cli/recipes'
46
60
  environment.upload_recipes
47
61
 
48
- if status == "running"
62
+ if status == "running" || status == "error"
49
63
  say "Environment is rebuilding..."
50
64
  environment.run_custom_recipes
51
65
  watch_page_while public_hostname, 80, "/" do |req|
@@ -96,6 +110,20 @@ module Engineyard
96
110
  exit
97
111
  end
98
112
 
113
+ # Returns the [host, port] for the target Jenkins CI server
114
+ def host_port(options)
115
+ require "jenkins"
116
+ require "jenkins/config"
117
+ if base_uri = ::Jenkins::Config.config['base_uri']
118
+ uri = URI.parse(::Jenkins::Config.config['base_uri'])
119
+ host = uri.host
120
+ port = uri.port
121
+ end
122
+ host = options["host"] if options["host"]
123
+ port = options["port"] || port || '80'
124
+ [host, port]
125
+ end
126
+
99
127
  def no_environments_discovered
100
128
  say "No environments with name jenkins, jenkins_server, jenkins_production, jenkins_server_production.", :red
101
129
  say "Either:"
@@ -6,6 +6,9 @@ module Engineyard
6
6
  include Thor::Actions
7
7
 
8
8
  argument :project_path
9
+ argument :host
10
+ argument :port
11
+ argument :public_key
9
12
 
10
13
  def self.source_root
11
14
  File.join(File.dirname(__FILE__), "install_generator", "templates")
@@ -5,13 +5,12 @@
5
5
 
6
6
  jenkins_slave({
7
7
  :master => {
8
- :host => "ec2-174-129-24-134.compute-1.amazonaws.com",
9
- :port => 80,
10
- :public_key => "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6AWDDDJcsIrY0KA99KPg+UmSjxjPz7+Eu9mO5GaSNn0vvVdsgrgjkh+35AS9k8Gn/DPaQJoNih+DpY5ZHsuY1zlvnvvk+hsCUHOATngARNs6yQMf2IrQqf38SlBPJ/xjt4oopLyqZuZ59xbFMFa0Yr/B7cCpxNpeIMCbwmc8YOtztOG1ZazlxB6eMTwp1V25TxFPh3PqUz9s37NmBEhkRiEyiJzlDSrKwz2y+77VWztQByM30lYAEXc5GwJD1LTaQwlv/thjhwveAzKLIpxzC5TbUjii7L+4iJF/JrjtXAEYmkegXj6lGBpRIdwXTYWMm3jG6gG+MV2nfWmocDzg3Q==",
8
+ :host => <%= host.inspect %>,
9
+ :port => <%= port %>,
10
+ :public_key => <%= public_key.strip.inspect %>,
11
11
  :master_key_location => "/home/deploy/.ssh/id_rsa"
12
12
  },
13
13
  :gem => {
14
- :install => "jenkins --pre",
15
- :version => "jenkins-0.3.0.beta.16"
14
+ :install => "jenkins"
16
15
  }
17
16
  })
@@ -14,7 +14,7 @@ if ['solo','app_master'].include?(node[:instance_role]) && env_name =~ /(ci|jenk
14
14
 
15
15
  execute "install_jenkins_in_resin" do
16
16
  command "/usr/local/ey_resin/ruby/bin/gem install #{node[:jenkins_slave][:gem][:install]}"
17
- not_if { FileTest.directory?("/usr/local/ey_resin/ruby/gems/1.8/gems/#{node[:jenkins_slave][:gem][:version]}") }
17
+ # not_if { FileTest.directory?("/usr/local/ey_resin/ruby/gems/1.8/gems/#{node[:jenkins_slave][:gem][:version]}") }
18
18
  end
19
19
 
20
20
  ruby_block "authorize_jenkins_master_key" do
@@ -49,7 +49,7 @@ if ['solo','app_master'].include?(node[:instance_role]) && env_name =~ /(ci|jenk
49
49
  :slave_host => node[:engineyard][:environment][:instances].first[:public_hostname],
50
50
  :slave_user => username,
51
51
  :executors => [node[:applications].size, 1].max,
52
- :label => node[:applications].keys.join(" ")
52
+ :labels => node[:applications].keys.join(" ")
53
53
  )
54
54
  end
55
55
  action :create
@@ -73,7 +73,8 @@ if ['solo','app_master'].include?(node[:instance_role]) && env_name =~ /(ci|jenk
73
73
  c.envfile = "/data/#{app_name}/shared/config/git-env"
74
74
  c.steps = [
75
75
  [:build_shell_step, "bundle install"],
76
- [:build_ruby_step, <<-RUBY.gsub(/^ /, '')],
76
+ [:build_ruby_step, <<-RUBY.gsub(/^ /, '')],
77
+ require "fileutils"
77
78
  appcloud_database = "/data/#{app_name}/shared/config/database.yml"
78
79
  FileUtils.cp appcloud_database, "config/database.yml"
79
80
  RUBY
@@ -16,7 +16,7 @@ module Engineyard
16
16
  end
17
17
 
18
18
  def attributes
19
- @plugins = %w[git github rake ruby greenballs envfile] + (options[:plugins] || '').strip.split(/\s*,\s*/)
19
+ @plugins = %w[git-1.1.6 github-0.4 rake-1.7.6 ruby-1.2 greenballs-1.10 envfile-1.1] + (options[:plugins] || '').strip.split(/\s*,\s*/)
20
20
  template "attributes.rb.tt", "cookbooks/jenkins_master/attributes/default.rb"
21
21
  end
22
22
 
@@ -40,7 +40,7 @@ if ['solo'].include?(node[:instance_role])
40
40
  end
41
41
 
42
42
  remote_file "#{jenkins_home}/jenkins.war" do
43
- source "http://jenkins-ci.org/latest/jenkins.war"
43
+ source "http://mirrors.jenkins-ci.org/war/latest/jenkins.war"
44
44
  owner jenkins_user
45
45
  group jenkins_user
46
46
  not_if { FileTest.exists?("#{jenkins_home}/jenkins.war") }
@@ -59,14 +59,16 @@ if ['solo'].include?(node[:instance_role])
59
59
  )
60
60
  end
61
61
 
62
- plugins.each do |plugin|
63
- remote_file "#{jenkins_home}/plugins/#{plugin}.hpi" do
64
- source "http://jenkins-ci.org/latest/#{plugin}.hpi"
65
- owner jenkins_user
66
- group jenkins_user
67
- not_if { FileTest.exists?("#{jenkins_home}/plugins/#{plugin}.hpi") }
62
+ plugins.each do |plugin_version| # 'git-1.2.3'
63
+ plugin, version = plugin_version.split(/-/)
64
+ if version
65
+ remote_file "#{jenkins_home}/plugins/#{plugin}.hpi" do
66
+ source "http://mirrors.jenkins-ci.org/plugins/#{plugin}/#{version}/#{plugin}.hpi"
67
+ owner jenkins_user
68
+ group jenkins_user
69
+ not_if { FileTest.exists?("#{jenkins_home}/plugins/#{plugin}.hpi") }
70
+ end
68
71
  end
69
-
70
72
  end
71
73
 
72
74
  template "/data/nginx/servers/jenkins_reverse_proxy.conf" do
@@ -1,5 +1,5 @@
1
1
  module Engineyard
2
2
  module Jenkins
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: engineyard-jenkins
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dr Nic Williams
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-12 00:00:00 -07:00
13
+ date: 2011-04-13 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.6.2
45
+ version: 0.6.4
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: *id003
@@ -173,6 +173,8 @@ files:
173
173
  - features/support/engineyard.rb
174
174
  - features/support/env.rb
175
175
  - features/support/matchers.rb
176
+ - fixtures/bin/README.md
177
+ - fixtures/bin/scp
176
178
  - fixtures/cookbooks/main/recipes/default.rb
177
179
  - fixtures/cookbooks/redis/recipes/default.rb
178
180
  - fixtures/jenkins_boot_sequence/jenkins_booting.html
@@ -219,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
221
  requirements:
220
222
  - - ">="
221
223
  - !ruby/object:Gem::Version
222
- hash: -2707218013729594709
224
+ hash: -394096763024262056
223
225
  segments:
224
226
  - 0
225
227
  version: "0"
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  requirements:
229
231
  - - ">="
230
232
  - !ruby/object:Gem::Version
231
- hash: -2707218013729594709
233
+ hash: -394096763024262056
232
234
  segments:
233
235
  - 0
234
236
  version: "0"