lobot 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +7 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +78 -0
  6. data/Rakefile +2 -0
  7. data/features/ci.feature +18 -0
  8. data/features/config/secrets.yml.example +6 -0
  9. data/features/step_definitions/ci_steps.rb +98 -0
  10. data/features/support/env.rb +3 -0
  11. data/lib/generators/lobot/USAGE +8 -0
  12. data/lib/generators/lobot/install_generator.rb +24 -0
  13. data/lib/generators/lobot/templates/Capfile +6 -0
  14. data/lib/generators/lobot/templates/bootstrap_server.sh +57 -0
  15. data/lib/generators/lobot/templates/capistrano-ci.rb +68 -0
  16. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/nginx.rb +2 -0
  17. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/libraries/ci_config.rb +2 -0
  18. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/default.rb +7 -0
  19. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/git_config.rb +11 -0
  20. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/id_rsa.rb +14 -0
  21. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/jenkins.rb +45 -0
  22. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/xvfb.rb +24 -0
  23. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/templates/default/jenkins-job-config.xml.erb +62 -0
  24. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/libraries/marker.rb +42 -0
  25. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/daemontools.rb +15 -0
  26. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/imagemagick.rb +37 -0
  27. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/libxml_prereqs.rb +14 -0
  28. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/mysql_5_1.rb +90 -0
  29. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/mysql_5_5.rb +86 -0
  30. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/nginx.rb +65 -0
  31. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/postgres.rb +80 -0
  32. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/sqlite.rb +20 -0
  33. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/swap.rb +17 -0
  34. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-conf.erb +42 -0
  35. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-htaccess.erb +3 -0
  36. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-mime-types.erb +75 -0
  37. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-run-script.erb +2 -0
  38. data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/postgres-run-script.erb +2 -0
  39. data/lib/generators/lobot/templates/ci.rake +111 -0
  40. data/lib/generators/lobot/templates/ci.yml +24 -0
  41. data/lib/generators/lobot/templates/deploy-ci.rb +5 -0
  42. data/lib/generators/lobot/templates/soloistrc +11 -0
  43. data/lib/lobot.rb +8 -0
  44. data/lib/lobot/version.rb +3 -0
  45. data/lobot.gemspec +27 -0
  46. data/spec/install_spec.rb +68 -0
  47. data/spec/spec_helper.rb +11 -0
  48. metadata +161 -0
@@ -0,0 +1,11 @@
1
+ username = ENV['SUDO_USER'].strip
2
+
3
+ execute "set git email" do
4
+ command "git config --global user.email 'jenkins-ci@example.com'"
5
+ user username
6
+ end
7
+
8
+ execute "set git user" do
9
+ command "git config --global user.name 'Jenkins CI Server'"
10
+ user username
11
+ end
@@ -0,0 +1,14 @@
1
+ username = ENV['SUDO_USER'].strip
2
+
3
+ file "/home/#{username}/.ssh/id_rsa" do
4
+ content CI_CONFIG['id_rsa_for_github_access']
5
+ mode 0600
6
+ only_if { CI_CONFIG['id_rsa_for_github_access'] }
7
+ owner username
8
+ end
9
+
10
+ execute "add github to known hosts if necessary" do
11
+ github_string = 'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
12
+ command "echo '#{github_string}' >> /home/#{username}/.ssh/known_hosts"
13
+ not_if "grep '#{github_string}' /home/#{username}/.ssh/known_hosts"
14
+ end
@@ -0,0 +1,45 @@
1
+ include_recipe "pivotal_server::daemontools"
2
+ include_recipe "pivotal_ci::xvfb"
3
+ include_recipe "pivotal_ci::git_config"
4
+
5
+ username = ENV['SUDO_USER'].strip
6
+ user_home = ENV['HOME']
7
+
8
+ install_dir = "/usr/local/jenkins"
9
+ bin_location = "#{install_dir}/jenkins.war"
10
+
11
+ execute "download jenkins" do
12
+ command "mkdir -p #{install_dir} && curl -Lsf http://mirrors.jenkins-ci.org/war/latest/jenkins.war -o #{bin_location}"
13
+ not_if { File.exists?(bin_location) }
14
+ end
15
+
16
+ execute "download git plugin" do
17
+ command "mkdir -p /home/#{username}/.jenkins/plugins && curl -Lsf http://mirrors.jenkins-ci.org/plugins/git/latest/git.hpi -o /home/#{username}/.jenkins/plugins/git.hpi"
18
+ not_if { File.exists?("/home/#{username}/.jenkins/plugins/git.hpi") }
19
+ user username
20
+ end
21
+
22
+ execute "make projec#t dir" do
23
+ command "mkdir -p /home/#{username}/.jenkins/jobs/#{ENV['APP_NAME']}"
24
+ user username
25
+ end
26
+
27
+ template "/home/#{username}/.jenkins/jobs/#{ENV['APP_NAME']}/config.xml" do
28
+ source "jenkins-job-config.xml.erb"
29
+ owner username
30
+ end
31
+
32
+ service_name = "jenkins"
33
+
34
+ execute "create daemontools directory" do
35
+ command "mkdir -p /service/#{service_name}"
36
+ end
37
+
38
+ execute "create run script2" do # srsly! the not_if from mysql was being applied because they had the same name. I kid you not.
39
+ command "echo -e '#!/bin/sh\nexport PATH=/usr/local/mysql/bin/:$PATH\nexport HOME=/home/#{username}\nexec /command/setuidgid #{username} /usr/bin/java -jar #{bin_location}' > /service/#{service_name}/run"
40
+ # not_if "ls /service/#{service_name}/run"
41
+ end
42
+
43
+ execute "make run script executable" do
44
+ command "chmod 755 /service/#{service_name}/run"
45
+ end
@@ -0,0 +1,24 @@
1
+ # include_recipe "pivotal_server::daemontools"
2
+
3
+ # service_name = "xvfb"
4
+
5
+ execute "install xvfb" do
6
+ command "yum -y install xorg-x11-server-Xvfb"
7
+ end
8
+
9
+ execute "install firefox" do
10
+ command "yum -y install firefox"
11
+ end
12
+
13
+ # execute "make daemontools dir" do
14
+ # command "mkdir -p /service/#{service_name}"
15
+ # end
16
+ #
17
+ # execute "create run script3" do # srsly! the not_if from mysql was being applied because they had the same name. I kid you not.
18
+ # command "echo -e '#!/bin/sh\nexec Xvfb :99 -ac -screen 0 1024x768x16' > /service/#{service_name}/run"
19
+ # # not_if "ls /service/#{service_name}/run"
20
+ # end
21
+ #
22
+ # execute "make run script executable" do
23
+ # command "chmod 755 /service/#{service_name}/run"
24
+ # end
@@ -0,0 +1,62 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <project>
3
+ <actions/>
4
+ <description></description>
5
+ <keepDependencies>false</keepDependencies>
6
+ <properties/>
7
+ <scm class="hudson.plugins.git.GitSCM">
8
+ <configVersion>1</configVersion>
9
+ <remoteRepositories>
10
+ <org.spearce.jgit.transport.RemoteConfig>
11
+ <string>origin</string>
12
+ <int>5</int>
13
+ <string>fetch</string>
14
+ <string>+refs/heads/*:refs/remotes/origin/*</string>
15
+ <string>receivepack</string>
16
+ <string>git-upload-pack</string>
17
+ <string>uploadpack</string>
18
+ <string>git-upload-pack</string>
19
+ <string>url</string>
20
+ <string><%= CI_CONFIG['git_location'] %></string>
21
+ <string>tagopt</string>
22
+ <string></string>
23
+ </org.spearce.jgit.transport.RemoteConfig>
24
+ </remoteRepositories>
25
+ <branches>
26
+ <hudson.plugins.git.BranchSpec>
27
+ <name>master</name>
28
+ </hudson.plugins.git.BranchSpec>
29
+ </branches>
30
+ <mergeOptions/>
31
+ <recursiveSubmodules>false</recursiveSubmodules>
32
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
33
+ <authorOrCommitter>false</authorOrCommitter>
34
+ <clean>false</clean>
35
+ <wipeOutWorkspace>false</wipeOutWorkspace>
36
+ <pruneBranches>false</pruneBranches>
37
+ <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
38
+ <gitTool>Default</gitTool>
39
+ <submoduleCfg class="list"/>
40
+ <relativeTargetDir></relativeTargetDir>
41
+ <excludedRegions></excludedRegions>
42
+ <excludedUsers></excludedUsers>
43
+ <skipTag>false</skipTag>
44
+ </scm>
45
+ <canRoam>true</canRoam>
46
+ <disabled>false</disabled>
47
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
48
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
49
+ <triggers class="vector">
50
+ <hudson.triggers.SCMTrigger>
51
+ <spec>* * * * *</spec>
52
+ </hudson.triggers.SCMTrigger>
53
+ </triggers>
54
+ <concurrentBuild>false</concurrentBuild>
55
+ <builders>
56
+ <hudson.tasks.Shell>
57
+ <command><%= CI_CONFIG['build_command'] %></command>
58
+ </hudson.tasks.Shell>
59
+ </builders>
60
+ <publishers/>
61
+ <buildWrappers/>
62
+ </project>
@@ -0,0 +1,42 @@
1
+ class Chef::Recipe
2
+
3
+ MARKER_DIR = "#{ENV['HOME']}/.install_markers"
4
+
5
+ #Regarding marker files:
6
+ #
7
+ #The idea here is you have a simple "signal" on disk that tells you when you've
8
+ #successfully run something, and you don't want to run it again if you don't have to.
9
+ #
10
+ #Also, the decision to rerun a unit of work becomes explicit - and owned by you.
11
+ #(it's not based on trusting a target program to respond in some way).
12
+ #You don't have to learn and keep up this "re-run" logic per unit of work / program
13
+ #
14
+ #Also, simply ls'ing the marker dir gives you interesting information all in once place -
15
+ #i.e. what markers are there and what are their timestamps?
16
+ #
17
+ #And reinstalls are easy - just rm the relevant marker file.
18
+
19
+ def run_unless_marker_file_exists(marker_file_name)
20
+
21
+ directory MARKER_DIR do
22
+ # owner WS_USER
23
+ recursive true
24
+ end
25
+
26
+ marker_path = File.join(MARKER_DIR, marker_file_name)
27
+ if File.exists?(marker_path)
28
+ log "skipping #{marker_file_name}: marker file found (#{marker_path}), detail: #{`ls -la #{marker_path}`.strip}"
29
+ else
30
+
31
+ log "no marker file found for #{marker_file_name} in #{MARKER_DIR}, running"
32
+
33
+ yield
34
+
35
+ execute "touching marker file #{marker_path} after successful run" do
36
+ # user WS_USER
37
+ command "touch #{marker_path}"
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ ruby_block "install daemontools" do
2
+ block do
3
+ directory = "/package/admin"
4
+ repo = "git://github.com/MikeSofaer/daemontools.git"
5
+ dir_name = "daemontools-0.76"
6
+ FileUtils.mkdir_p directory
7
+ system("cd #{directory} && git clone #{repo} #{dir_name}")
8
+ system("cd #{File.join(directory, dir_name)} && ./package/install")
9
+ end
10
+ not_if "ls /command/svscanboot"
11
+ end
12
+
13
+ execute "make sure daemontools is installed" do
14
+ command "ls /command/svscanboot"
15
+ end
@@ -0,0 +1,37 @@
1
+
2
+
3
+ src_dir = "/usr/local/src/imagemagick"
4
+
5
+ directory src_dir
6
+
7
+ run_unless_marker_file_exists("imagemagick_6_6_5") do
8
+ execute "install imagemagic prerequisites" do
9
+ command "yum -y install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel"
10
+ end
11
+
12
+ execute "download imagemagick" do
13
+ # using an older version because the URL for the current version dies when a new version comes out.
14
+ # http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
15
+ command "curl -Lsf ftp://ftp.imagemagick.org/pub/ImageMagick/legacy/ImageMagick-6.6.5-10.tar.gz | tar xvz -C#{src_dir} --strip 1"
16
+ end
17
+
18
+ execute "configure imagemagick" do
19
+ command "./configure --prefix=/usr/local --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes"
20
+ cwd src_dir
21
+ end
22
+
23
+ execute "make clean" do
24
+ command "make clean"
25
+ cwd src_dir
26
+ end
27
+
28
+ execute "make imagemagic" do
29
+ command "make"
30
+ cwd src_dir
31
+ end
32
+
33
+ execute "make install" do
34
+ command "make install"
35
+ cwd src_dir
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ {
2
+ "libxml2" => "2.6.26-2.1.2.8.el5_5.1",
3
+ "libxml2-devel" => "2.6.26-2.1.2.8.el5_5.1",
4
+ "libxslt" => "1.1.17-2.el5_2.2",
5
+ "libxslt-devel" => "1.1.17-2.el5_2.2",
6
+ }.each do |package_name, version_string|
7
+ ['x86_64'].each do |arch_string|
8
+ yum_package package_name do
9
+ action :install
10
+ version version_string
11
+ # arch arch_string
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ include_recipe "pivotal_server::daemontools"
2
+
3
+ src_dir = "/usr/local/src/mysql"
4
+ install_dir = "/usr/local/mysql"
5
+ mysql_root_password = "password"
6
+ mysql_user_name = "app_user"
7
+ mysql_user_password = "password"
8
+
9
+ {
10
+ "bison" => "2.3-2.1",
11
+ "ncurses-devel" => "5.5-24.20060715"
12
+ }.each do |package_name, version_string|
13
+ package package_name do
14
+ action :install
15
+ version version_string
16
+ end
17
+ end
18
+
19
+ user "mysql"
20
+
21
+ run_unless_marker_file_exists("mysql_5_1") do
22
+ execute "download mysql src" do
23
+ command "mkdir -p #{src_dir} && curl -Lsf http://mysql.he.net/Downloads/MySQL-5.1/mysql-5.1.57.tar.gz | tar xvz -C#{src_dir} --strip 1"
24
+ end
25
+
26
+ execute "configure" do
27
+ command "./configure --prefix=/usr/local/mysql"
28
+ cwd src_dir
29
+ end
30
+
31
+ execute "make" do
32
+ command "make"
33
+ cwd src_dir
34
+ end
35
+
36
+ execute "make install" do
37
+ command "make install"
38
+ cwd src_dir
39
+ end
40
+
41
+ execute "mysql owns #{install_dir}" do
42
+ command "chown -R mysql #{install_dir}"
43
+ end
44
+
45
+ execute "install db" do
46
+ command "#{install_dir}/bin/mysql_install_db --user=mysql"
47
+ cwd install_dir
48
+ end
49
+ end
50
+
51
+ execute "create daemontools directory" do
52
+ command "mkdir -p /service/mysql"
53
+ end
54
+
55
+ execute "create run script" do
56
+ command "echo -e '#!/bin/sh\nexec /command/setuidgid mysql /usr/local/mysql/libexec/mysqld' > /service/mysql/run"
57
+ not_if "ls /service/mysql/run"
58
+ end
59
+
60
+ execute "make run script executable" do
61
+ command "chmod 755 /service/mysql/run"
62
+ end
63
+
64
+ ruby_block "wait for mysql to come up" do
65
+ block do
66
+ Timeout::timeout(60) do
67
+ until system("ls /tmp/mysql.sock")
68
+ sleep 1
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ execute "set the root mysql password" do
75
+ command "#{install_dir}/bin/mysqladmin -uroot password #{mysql_root_password}"
76
+ not_if "#{install_dir}/bin/mysql -uroot -p#{mysql_root_password} -e 'show databases'"
77
+ end
78
+
79
+ execute "create app_user user" do
80
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"CREATE USER '#{mysql_user_name}'@'localhost'\""
81
+ not_if "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SELECT * FROM user where User='#{mysql_user_name}' and Host = 'localhost'\" | grep -q #{mysql_user_name}"
82
+ end
83
+
84
+ execute "set password for app_user" do
85
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SET PASSWORD FOR '#{mysql_user_name}'@'localhost' = PASSWORD('#{mysql_user_password}')\""
86
+ end
87
+
88
+ execute "grant user all rights (this maybe isn't a great idea)" do
89
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"GRANT ALL on *.* to '#{mysql_user_name}'@'localhost'\""
90
+ end
@@ -0,0 +1,86 @@
1
+ include_recipe "pivotal_server::daemontools"
2
+
3
+ src_dir = "/usr/local/src/mysql"
4
+ install_dir = "/usr/local/mysql"
5
+ mysql_root_password = "password"
6
+ mysql_user_name = "app_user"
7
+ mysql_user_password = "password"
8
+
9
+ {
10
+ "cmake" => "2.6.4-5.el5.2",
11
+ "bison" => "2.3-2.1",
12
+ "ncurses-devel" => "5.5-24.20060715"
13
+ }.each do |package_name, version_string|
14
+ package package_name do
15
+ action :install
16
+ version version_string
17
+ end
18
+ end
19
+
20
+ user "mysql"
21
+
22
+ run_unless_marker_file_exists("mysql_5_5_11") do
23
+ execute "download mysql src" do
24
+ command "mkdir -p #{src_dir} && curl -Lsf http://mysql.he.net/Downloads/MySQL-5.5/mysql-5.5.14.tar.gz | tar xvz -C#{src_dir} --strip 1"
25
+ end
26
+
27
+ execute "cmake" do
28
+ command "cmake ."
29
+ cwd src_dir
30
+ end
31
+
32
+ execute "make" do
33
+ command "make install"
34
+ cwd src_dir
35
+ end
36
+
37
+ execute "mysql owns #{install_dir}/data" do
38
+ command "chown -R mysql #{install_dir}/data"
39
+ end
40
+
41
+ execute "install db" do
42
+ command "#{install_dir}/scripts/mysql_install_db --user=mysql"
43
+ cwd install_dir
44
+ end
45
+ end
46
+
47
+ execute "create daemontools directory" do
48
+ command "mkdir -p /service/mysql"
49
+ end
50
+
51
+ execute "create run script" do
52
+ command "echo -e '#!/bin/sh\nexec /command/setuidgid mysql /usr/local/mysql/bin/mysqld' > /service/mysql/run"
53
+ not_if "ls /service/mysql/run"
54
+ end
55
+
56
+ execute "make run script executable" do
57
+ command "chmod 755 /service/mysql/run"
58
+ end
59
+
60
+ ruby_block "wait for mysql to come up" do
61
+ block do
62
+ Timeout::timeout(60) do
63
+ until system("ls /tmp/mysql.sock")
64
+ sleep 1
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ execute "set the root mysql password" do
71
+ command "#{install_dir}/bin/mysqladmin -uroot password #{mysql_root_password}"
72
+ not_if "#{install_dir}/bin/mysql -uroot -p#{mysql_root_password} -e 'show databases'"
73
+ end
74
+
75
+ execute "create app_user user" do
76
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"CREATE USER '#{mysql_user_name}'@'localhost'\""
77
+ not_if "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SELECT * FROM user where User='#{mysql_user_name}' and Host = 'localhost'\" | grep -q #{mysql_user_name}"
78
+ end
79
+
80
+ execute "set password for app_user" do
81
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SET PASSWORD FOR '#{mysql_user_name}'@'localhost' = PASSWORD('#{mysql_user_password}')\""
82
+ end
83
+
84
+ execute "grant user all rights (this maybe isn't a great idea)" do
85
+ command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"GRANT ALL on *.* to '#{mysql_user_name}'@'localhost'\""
86
+ end