lobot 0.9.7 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.rvmrc +1 -1
- data/Gemfile +1 -4
- data/LICENSE.txt +1 -1
- data/README.md +45 -21
- data/Rakefile +11 -0
- data/docs/ci_yml.md +4 -9
- data/features/ci.feature +9 -8
- data/features/config/secrets.yml.example +4 -6
- data/features/step_definitions/ci_steps.rb +42 -31
- data/features/support/env.rb +10 -1
- data/lib/generators/lobot/config_generator.rb +161 -0
- data/lib/generators/lobot/install_generator.rb +14 -5
- data/lib/generators/lobot/templates/Capfile +2 -2
- data/lib/generators/lobot/templates/bootstrap_server.sh +6 -5
- data/lib/generators/lobot/templates/capistrano-ci.rb +11 -5
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/nginx.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/libraries/ci_config.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/default.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/git_config.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/id_rsa.rb +2 -2
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/jenkins.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/recipes/xvfb.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/templates/default/jenkins-job-config.xml.erb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/files/default/cacert.pem +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/libraries/marker.rb +10 -10
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/ca_cert.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/daemontools.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/libxml_prereqs.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/mysql_5_1.rb +6 -6
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/mysql_5_5.rb +4 -4
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/node_js.rb +3 -3
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/postgres.rb +6 -6
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/sqlite.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/recipes/swap.rb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-conf.erb +5 -5
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-htaccess.erb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/nginx-run-script.erb +1 -1
- data/lib/generators/lobot/templates/chef/cookbooks/pivotal_server/templates/default/postgres-run-script.erb +1 -1
- data/lib/generators/lobot/templates/ci.yml +6 -8
- data/lib/generators/lobot/templates/ci_build.sh +4 -1
- data/lib/generators/lobot/templates/deploy-ci.rb +4 -2
- data/lib/generators/lobot/templates/dot-gitignore +1 -0
- data/lib/generators/lobot/templates/soloistrc +1 -1
- data/lib/lobot.rb +1 -1
- data/lib/lobot/railtie.rb +1 -1
- data/lib/lobot/tasks/ci.rake +50 -17
- data/lib/lobot/version.rb +1 -1
- data/lobot.gemspec +11 -4
- data/spec/install_spec.rb +21 -12
- data/spec/spec_helper.rb +1 -1
- metadata +207 -104
data/.rspec
ADDED
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use ruby-1.
|
1
|
+
rvm --create use ruby-1.9.3-p125@lobot
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -12,14 +12,14 @@ Lando Calrissian relies on Lobot to keep Cloud City afloat, and now you can rely
|
|
12
12
|
* capistrano tasks for bootstrapping and deploying to an EC2 instance
|
13
13
|
* chef recipes for configuring a Centos server to run Jenkins and build Rails projects.
|
14
14
|
|
15
|
-
all you'll need to do is:
|
15
|
+
all you'll need to do is run the following commands:
|
16
16
|
|
17
17
|
rails g lobot:install
|
18
|
-
|
18
|
+
rails g lobot:config
|
19
19
|
rake ci:server_start
|
20
20
|
cap ci bootstrap
|
21
21
|
cap ci chef
|
22
|
-
|
22
|
+
|
23
23
|
Read on for an explanation of what each one of these steps does.
|
24
24
|
|
25
25
|
## Install
|
@@ -34,52 +34,72 @@ Lobot is a Rails 3 generator. Rails 2 can be made to work, but you will need to
|
|
34
34
|
rails g lobot:install
|
35
35
|
|
36
36
|
## Setup
|
37
|
+
You can use a generator to interactively generate the config/ci.yml that includes some reasonable defaults and explanations
|
38
|
+
|
39
|
+
rails g lobot:config
|
37
40
|
|
38
|
-
|
41
|
+
Alternatively, manually edit config/ci.yml
|
39
42
|
|
40
|
-
---
|
43
|
+
---
|
41
44
|
app_name: # a short name for your application
|
42
45
|
app_user: # the user created to run your CI process
|
43
46
|
git_location: # The location of your remote git repository which Jenkins will poll and pull from on changes.
|
44
|
-
basic_auth:
|
47
|
+
basic_auth:
|
45
48
|
- username: # The username you will use to access the Jenkins web interface
|
46
49
|
password: # The password you will use to access the Jenkins web interface
|
47
|
-
credentials:
|
50
|
+
credentials:
|
48
51
|
aws_access_key_id: # The Access Key for your Amazon AWS account
|
49
52
|
aws_secret_access_key: The Secret Access Key for your Amazon AWS account
|
50
53
|
provider: AWS # leave this one alone
|
51
|
-
server:
|
54
|
+
server:
|
52
55
|
name: run 'rake ci:server_start to populate'
|
53
56
|
instance_id: run 'rake ci:server_start to populate'
|
54
57
|
build_command: ./script/ci_build.sh
|
55
|
-
ec2_server_access:
|
58
|
+
ec2_server_access:
|
56
59
|
key_pair_name: myapp_ci
|
57
60
|
id_rsa_path: ~/.ssh/id_rsa
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
github_private_ssh_key_path: ~/.ssh/id_rsa
|
62
|
+
|
63
|
+
For security, the lobot:install task added config/ci.yml to the .gitignore file since it includes sensitive AWS credentials and your CI users password.
|
64
|
+
Keep in mind that the default build script ci_build.sh uses the headless gem and jasmine. You'll want to add those to your Gemfile or change your build command.
|
65
|
+
|
66
|
+
At this point you will need to create a commit of the files generated or modified and push those changes to your remote git repository so jenkins can execute your build command.
|
64
67
|
|
65
68
|
## Modify the soloistrc if necessary
|
66
69
|
|
67
70
|
Switch postgres to mysql, or add your own recipes for your own dependencies.
|
68
71
|
|
69
|
-
##
|
72
|
+
## Starting your lobot instance
|
70
73
|
|
71
|
-
Launch an instance, allocate and associates an elastic IP and updates ci.yml:
|
74
|
+
1. Launch an instance, allocate and associates an elastic IP and updates ci.yml:
|
72
75
|
|
73
76
|
rake ci:server_start
|
74
77
|
|
75
|
-
Bootstrap the instance using the boostrap_server.sh script generated by Lobot. The script instals ruby prerequisites, creates the app_user account, and installs RVM for that user:
|
78
|
+
2. Bootstrap the instance using the boostrap_server.sh script generated by Lobot. The script instals ruby prerequisites, creates the app_user account, and installs RVM for that user:
|
76
79
|
|
77
80
|
cap ci bootstrap
|
78
|
-
|
79
|
-
Upload the contents of your chef/cookbooks/ directory, upload the soloistrc, and run chef:
|
81
|
+
|
82
|
+
3. Upload the contents of your chef/cookbooks/ directory, upload the soloistrc, and run chef:
|
80
83
|
|
81
84
|
cap ci chef
|
82
85
|
|
86
|
+
Your lobot instance should now be up and running. You will be able to access your CI server at: http://<your instance address>/ with the username and password you chose during configuration.
|
87
|
+
For more information about Jenkins CI, see http://jenkins-ci.org/
|
88
|
+
|
89
|
+
## Troubleshooting
|
90
|
+
|
91
|
+
Shell access for your instance
|
92
|
+
|
93
|
+
rake ci:ssh
|
94
|
+
|
95
|
+
Terminating your instance and deallocating the elastic IP
|
96
|
+
|
97
|
+
rake ci:terminate
|
98
|
+
|
99
|
+
Suspending your instance
|
100
|
+
|
101
|
+
rake ci:stop
|
102
|
+
|
83
103
|
## Add your new CI instance to [cimonitor](http://github.com/pivotal/cimonitor) and CCMenu
|
84
104
|
|
85
105
|
Lobot can generate the config for you, just run:
|
@@ -92,10 +112,14 @@ Lobot can generate the config for you, just run:
|
|
92
112
|
* capistrano
|
93
113
|
* capistrano-ext
|
94
114
|
* rvm (the gem - it configures capistrano to use RVM on the server)
|
115
|
+
* nokogiri
|
95
116
|
|
96
117
|
# Tests
|
97
118
|
|
98
|
-
Lobot is tested using rspec, generator_spec and cucumber. Cucumber provides a full integration test which can generate a rails application, push it to github, start a server and bring up CI for the generated project.
|
119
|
+
Lobot is tested using rspec, generator_spec and cucumber. Cucumber provides a full integration test which can generate a rails application, push it to github, start a server and bring up CI for the generated project.
|
120
|
+
You'll need a git repository (which should not have any code you care about) and an AWS account to run the whole test suite. It costs about $0.50 and takes about half an hour.
|
121
|
+
It will attempt to terminate the server however you should verify this so you do not get charged additional money.
|
122
|
+
Use the secrets.yml.example to create a secrets.yml file with your account information.
|
99
123
|
|
100
124
|
# Contributing
|
101
125
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,13 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'cucumber/rake/task'
|
1
3
|
require 'bundler'
|
2
4
|
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
task :default => [:spec, :features]
|
7
|
+
|
8
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
desc "Run all features in the features directory"
|
12
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
13
|
+
end
|
data/docs/ci_yml.md
CHANGED
@@ -15,7 +15,7 @@ The basic auth field is an array of hashes containing the usernames and password
|
|
15
15
|
# credentials:
|
16
16
|
Currently Lobot only supports managing EC2 servers. To start a new instance, the rake task needs to be able to connect to ec2 and ask it to launch a server.
|
17
17
|
## aws_access_key_id:
|
18
|
-
The Access Key for your Amazon AWS account. You can obtain it by visiting
|
18
|
+
The Access Key for your Amazon AWS account. You can obtain it by visiting
|
19
19
|
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
|
20
20
|
## aws_secret_access_key: The Secret Access Key for your Amazon AWS account
|
21
21
|
This will be available at the same URL.
|
@@ -32,16 +32,11 @@ The instance_id is also saved, in order to facilitate stopping and starting inst
|
|
32
32
|
# build_command: ./script/ci_build.sh
|
33
33
|
The build command is the shell script that Jenkins will execute to run your build. While you could put this script is the Jenkins configuration, it's clearer to have it in a script directly checked into your project.
|
34
34
|
|
35
|
-
# ec2_server_access:
|
35
|
+
# ec2_server_access:
|
36
36
|
key_pair_name: myapp_ci
|
37
37
|
id_rsa_path: ~/.ssh/id_rsa
|
38
38
|
|
39
39
|
The EC2 server access section is perhaps the most confusing field in the ci.yml file. This section tells Lobot what ssh keys to use to access the servers it spins up. When you run rake ci:sever_start, Lobot first looks in your ec2 account to see if they key pair name you specified exists - if it doesn't, it uploads the specified #{id_rsa_path}.pub to amazon, and names it #{key_pair_name}. It then launches the server, telling EC2 to use the key pair specified.
|
40
40
|
|
41
|
-
#
|
42
|
-
|
43
|
-
-----BEGIN RSA PRIVATE KEY-----
|
44
|
-
SSH KEY WITH ACCESS TO GITHUB GOES HERE
|
45
|
-
-----END RSA PRIVATE KEY-----
|
46
|
-
|
47
|
-
This is the rsa key that jenkins will use when connecting to github. Note that it is indented as it's a multiline markdown string.
|
41
|
+
# github_private_ssh_key_path: ~/.ssh/id_github_current
|
42
|
+
This is the path to the ssh private key that jenkins will use when connecting to github.
|
data/features/ci.feature
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
Feature: CI
|
1
|
+
Feature: CI
|
2
2
|
|
3
3
|
Background:
|
4
4
|
Given the temp directory is clean
|
5
|
-
|
6
|
-
|
5
|
+
And I am in the temp directory
|
6
|
+
|
7
7
|
Scenario: Installing Lobot on a rails3 project
|
8
|
-
When I create a new Rails project
|
8
|
+
When I create a new Rails project
|
9
9
|
And I vendor Lobot
|
10
10
|
And I put Lobot in the Gemfile
|
11
11
|
And I run bundle install
|
12
12
|
And I run the Lobot generator
|
13
13
|
Then rake reports ci tasks as being available
|
14
|
-
|
14
|
+
|
15
|
+
@aws
|
15
16
|
Scenario: Install CI on Amazon AWS using new Rails template
|
16
|
-
When I create a new Rails project
|
17
|
+
When I create a new Rails project
|
17
18
|
And I vendor Lobot
|
18
19
|
And I put Lobot in the Gemfile
|
19
20
|
And I add a gem with an https://github.com source
|
20
21
|
And I run bundle install
|
21
22
|
And I run the Lobot generator
|
22
23
|
And I enter my info into the ci.yml file
|
23
|
-
And I
|
24
|
+
And I make changes to be committed
|
24
25
|
And I push to git
|
25
|
-
And I
|
26
|
+
And I start the server
|
26
27
|
And I bootstrap
|
27
28
|
And I deploy
|
28
29
|
Then CI is green
|
@@ -1,19 +1,16 @@
|
|
1
|
-
|
2
|
-
def system!(str)
|
3
|
-
raise "Command Failed: #{str}" unless system(str)
|
4
|
-
end
|
5
|
-
|
6
1
|
Given /^the temp directory is clean$/ do
|
7
2
|
system!("rm -rf /tmp/lobot-test")
|
8
3
|
system!("mkdir -p /tmp/lobot-test")
|
9
4
|
end
|
10
5
|
|
11
6
|
Given /^I am in the temp directory$/ do
|
12
|
-
Dir.chdir(
|
7
|
+
Dir.chdir(LOBOT_TEMP_DIRECTORY)
|
13
8
|
end
|
14
9
|
|
15
|
-
When /^I create a new Rails project
|
16
|
-
system!("
|
10
|
+
When /^I create a new Rails project$/ do
|
11
|
+
system!("rvm ruby-1.9.3-p125 do rvm gemset create testapp")
|
12
|
+
system!("rails new testapp")
|
13
|
+
system!("cd testapp && echo 'rvm use ruby-1.9.3-p125@testapp' > .rvmrc")
|
17
14
|
end
|
18
15
|
|
19
16
|
When /^I vendor Lobot$/ do
|
@@ -30,6 +27,7 @@ end
|
|
30
27
|
|
31
28
|
When /^I add a gem with an https:\/\/github.com source$/ do
|
32
29
|
system!(%{echo "gem 'greyhawkweather', :git => 'https://github.com/verdammelt/Greyhawk-Weather.git'" >> testapp/Gemfile})
|
30
|
+
system!("cd testapp && bundle install")
|
33
31
|
end
|
34
32
|
|
35
33
|
When /^I run bundle install$/ do
|
@@ -45,48 +43,61 @@ When /^I run the Lobot generator$/ do
|
|
45
43
|
end
|
46
44
|
|
47
45
|
When /^I enter my info into the ci\.yml file$/ do
|
48
|
-
|
49
|
-
|
46
|
+
hostname = `hostname`.strip
|
47
|
+
secrets_file = File.expand_path('../config/secrets.yml', File.dirname(__FILE__))
|
48
|
+
raise "Missing #{secrets_file}, needed for AWS test." unless File.exist?(secrets_file)
|
49
|
+
secrets = YAML.load_file(secrets_file)
|
50
|
+
raise "Missing AWS secret access key" unless secrets["aws_secret_access_key"].to_s != ""
|
51
|
+
raise "Missing AWS access key id" unless secrets["aws_access_key_id"].to_s != ""
|
52
|
+
raise "Missing github private key path" unless secrets["github_private_ssh_key_path"].to_s != ""
|
53
|
+
|
54
|
+
raise "Missing private SSH key for AWS!" unless File.exist?(File.expand_path("~/.ssh/id_github_current"))
|
50
55
|
ci_conf_location = 'testapp/config/ci.yml'
|
51
56
|
ci_yml = YAML.load_file(ci_conf_location)
|
52
57
|
ci_yml.merge!(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
'app_name' => 'testapp',
|
59
|
+
'app_user' => 'testapp-user',
|
60
|
+
'git_location' => 'git@github.com:pivotalprivate/ci-smoke.git',
|
61
|
+
'basic_auth' => [{ 'username' => 'testapp', 'password' => 'testpass' }],
|
62
|
+
'credentials' => { 'aws_access_key_id' => secrets['aws_access_key_id'], 'aws_secret_access_key' => secrets['aws_secret_access_key'], 'provider' => 'AWS' },
|
63
|
+
'ec2_server_access' => {'key_pair_name' => "lobot_cucumber_key_pair_#{hostname}", 'id_rsa_path' => '~/.ssh/id_github_current'},
|
64
|
+
'github_private_ssh_key_path' => secrets["github_private_ssh_key_path"]
|
60
65
|
)
|
61
|
-
# ci_yml['server']['name] = '' # This can be used to merge in a server which is already running if you want to skip the setup steps while iterating on a test
|
66
|
+
# ci_yml['server']['name'] = '' # This can be used to merge in a server which is already running if you want to skip the setup steps while iterating on a test
|
62
67
|
File.open(ci_conf_location, "w") do |f|
|
63
|
-
|
68
|
+
f << ci_yml.to_yaml
|
69
|
+
f << File.read(secrets_file)
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
|
-
When /^I
|
68
|
-
system! "cd testapp && echo 'rvm use ruby-1.8.7-p299@lobot' > .rvmrc"
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
When /^I push to git$/ do
|
73
|
+
When /^I make changes to be committed$/ do
|
73
74
|
lobot_dir = File.expand_path('../../', File.dirname(__FILE__))
|
74
75
|
system! "rm testapp/vendor/cache/*"
|
75
76
|
system! "cp #{lobot_dir}/pkg/lobot-#{Lobot::VERSION}.gem testapp/vendor/cache/"
|
76
77
|
system! "echo 'config/ci.yml' >> testapp/.gitignore"
|
78
|
+
["headless", "rspec-rails", "jasmine"].each do |gem|
|
79
|
+
system!(%{echo "gem '#{gem}'" >> testapp/Gemfile})
|
80
|
+
end
|
81
|
+
system!("cd testapp && bundle install")
|
82
|
+
system!("cd testapp && bundle exec jasmine init .")
|
83
|
+
end
|
84
|
+
|
85
|
+
When /^I push to git$/ do
|
86
|
+
system! "cd testapp && git init"
|
77
87
|
system! "cd testapp && git add ."
|
78
88
|
system! "cd testapp && git commit -m'initial commit'"
|
79
|
-
system "cd testapp && git remote rm origin"
|
89
|
+
system "cd testapp && git remote rm origin" # Ignore failures
|
80
90
|
system! "cd testapp && git remote add origin git@github.com:pivotalprivate/ci-smoke.git"
|
81
91
|
system! "cd testapp && git push --force -u origin master"
|
82
92
|
end
|
83
93
|
|
84
|
-
When /^I
|
85
|
-
system! "cd testapp && rake ci:server_start"
|
94
|
+
When /^I start the server$/ do
|
95
|
+
system! "cd testapp && bundle exec rake ci:server_start"
|
86
96
|
end
|
87
97
|
|
88
98
|
When /^I bootstrap$/ do
|
89
|
-
system!
|
99
|
+
system!("cd testapp && bundle install")
|
100
|
+
system! "cd testapp && bundle exec cap ci bootstrap"
|
90
101
|
end
|
91
102
|
|
92
103
|
When /^I deploy$/ do
|
@@ -95,12 +106,12 @@ end
|
|
95
106
|
|
96
107
|
Then /^CI is green$/ do
|
97
108
|
Timeout::timeout(300) do
|
98
|
-
until system("cd testapp && rake ci:status")
|
109
|
+
until system("cd testapp && bundle exec rake ci:status")
|
99
110
|
sleep 5
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
104
115
|
Then /^rake reports ci tasks as being available$/ do
|
105
|
-
`cd testapp && rake -T`.should include("ci:start")
|
116
|
+
`cd testapp && bundle exec rake -T`.should include("ci:start")
|
106
117
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require File.expand_path('../../lib/lobot', File.dirname(__FILE__))
|
3
|
+
LOBOT_TEMP_DIRECTORY = "/tmp/lobot-test"
|
2
4
|
|
3
|
-
|
5
|
+
def system!(str)
|
6
|
+
system(str)
|
7
|
+
raise "Command Failed: #{str} with exit code #{$?.exitstatus}" unless $?.success?
|
8
|
+
end
|
9
|
+
|
10
|
+
After '@aws' do
|
11
|
+
system "cd #{LOBOT_TEMP_DIRECTORY}/testapp && rake ci:terminate" unless ENV["KEEP_INSTANCE"]
|
12
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module Lobot
|
2
|
+
class ConfigGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
4
|
+
|
5
|
+
def generate_ci_config
|
6
|
+
default_git_location = nil
|
7
|
+
if File.exist?(Rails.root.join(".git/config"))
|
8
|
+
default_git_location = `cat .git/config | grep url`.strip.split.last
|
9
|
+
else
|
10
|
+
puts "nope"
|
11
|
+
end
|
12
|
+
default_app_name = File.basename(Rails.root)
|
13
|
+
config = {
|
14
|
+
'app_name' => default_app_name,
|
15
|
+
'app_user' => ENV['USER'],
|
16
|
+
'git_location' => default_git_location,
|
17
|
+
'basic_auth' => [
|
18
|
+
{
|
19
|
+
'username' => "#{default_app_name}_ci"
|
20
|
+
}
|
21
|
+
],
|
22
|
+
'credentials' => {
|
23
|
+
'provider' => "AWS"
|
24
|
+
},
|
25
|
+
'server' => {
|
26
|
+
'flavor_id' => "m1.large",
|
27
|
+
'security_group' => "ci_servers",
|
28
|
+
'ssh_port' => "22"
|
29
|
+
},
|
30
|
+
'build_command' => "./script/ci_build.sh",
|
31
|
+
'ec2_server_access' => {
|
32
|
+
"key_pair_name" => "#{default_app_name}_ci",
|
33
|
+
"id_rsa_path" => File.expand_path("~/.ssh/id_rsa")
|
34
|
+
},
|
35
|
+
"github_private_ssh_key_path" => File.expand_path("~/.ssh/id_rsa")
|
36
|
+
}
|
37
|
+
|
38
|
+
say "* The name of your application as it will appear in CI"
|
39
|
+
app_name = ask "Application Name [#{config['app_name']}]: "
|
40
|
+
config['app_name'] = app_name if app_name != ""
|
41
|
+
|
42
|
+
say "* The user created to run your CI process"
|
43
|
+
app_user = ask "Application User [#{config['app_user']}]: "
|
44
|
+
config['app_user'] = app_user if app_user != ""
|
45
|
+
|
46
|
+
say "* The location of your remote git repository which CI will poll and pull from on changes"
|
47
|
+
git_location = ask "Git Repository Location [#{config['git_location']}]: "
|
48
|
+
config['git_location'] = git_location if git_location != ""
|
49
|
+
|
50
|
+
say "* The username you will use to access the CI web interface"
|
51
|
+
ci_username = ask "CI Username [#{config['basic_auth'][0]['username']}]: "
|
52
|
+
config['basic_auth'][0]['username'] = ci_username if ci_username != ""
|
53
|
+
|
54
|
+
say "* The password you will use to access the Jenkins web interface"
|
55
|
+
while true do
|
56
|
+
ci_password = ask "Choose a CI password: "
|
57
|
+
config['basic_auth'][0]['password'] = ci_password
|
58
|
+
if ci_password == ""
|
59
|
+
say "Password cannot be blank"
|
60
|
+
else
|
61
|
+
break
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
say <<-EOS
|
66
|
+
* See https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
|
67
|
+
* for access key id and secret access key
|
68
|
+
EOS
|
69
|
+
|
70
|
+
while true do
|
71
|
+
aws_access_key_id = ask "AWS Access Key ID: "
|
72
|
+
config['credentials']['aws_access_key_id'] = aws_access_key_id
|
73
|
+
if aws_access_key_id == ""
|
74
|
+
say "AWS Access Key ID cannot be blank"
|
75
|
+
else
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
while true do
|
81
|
+
aws_secret_access_key = ask "AWS Secret Access Key: "
|
82
|
+
config['credentials']['aws_secret_access_key'] = aws_secret_access_key
|
83
|
+
if aws_secret_access_key == ""
|
84
|
+
say "AWS Secret Access Key cannot be blank"
|
85
|
+
else
|
86
|
+
break
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
say <<-EOS
|
91
|
+
* See http://aws.amazon.com/ec2/instance-types/ API name values (e.g. m1.large)
|
92
|
+
EOS
|
93
|
+
flavor_id = ask "Choose an EC2 instance type [#{config['server']['flavor_id']}]: "
|
94
|
+
config['server']['flavor_id'] = flavor_id if flavor_id != ""
|
95
|
+
|
96
|
+
security_group = ask "AWS EC2 Security Group Name [#{config['server']['security_group']}]: "
|
97
|
+
config['server']['security_group'] = security_group if security_group != ""
|
98
|
+
|
99
|
+
ssh_port = ask "Server SSH Port [#{config['server']['ssh_port']}]: "
|
100
|
+
config['server']['ssh_port'] = ssh_port if ssh_port != ""
|
101
|
+
|
102
|
+
build_command = ask "Build Command: [#{config['build_command']}]: "
|
103
|
+
config['build_command'] = build_command if build_command != ""
|
104
|
+
|
105
|
+
say <<-EOS
|
106
|
+
* This should refer to an SSH key pair that you have already generated. You may wish to generate a new key
|
107
|
+
* separate from what you may already be using for github or other systems.
|
108
|
+
* For a tutorial on this see: http://open.bsdcow.org/histerical/tutorials/ssh_pubkey_auth#1.2
|
109
|
+
EOS
|
110
|
+
while true do
|
111
|
+
id_rsa_path = ask "Path to SSH Private Key for EC2 Access [#{config['ec2_server_access']['id_rsa_path']}]: "
|
112
|
+
config['ec2_server_access']['id_rsa_path'] = id_rsa_path if id_rsa_path != ""
|
113
|
+
if config['ec2_server_access']['id_rsa_path'] != File.expand_path(config['ec2_server_access']['id_rsa_path'])
|
114
|
+
config['ec2_server_access']['id_rsa_path'] = File.expand_path(File.join(ENV['HOME'], '.ssh', config['ec2_server_access']['id_rsa_path']))
|
115
|
+
end
|
116
|
+
if File.exist?(config['ec2_server_access']['id_rsa_path']) && File.exist?("#{config['ec2_server_access']['id_rsa_path']}.pub")
|
117
|
+
break
|
118
|
+
else
|
119
|
+
say "Unable to find both #{config['ec2_server_access']['id_rsa_path']} and #{config['ec2_server_access']['id_rsa_path']}.pub"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
say <<-EOS
|
124
|
+
* This is an arbitrary label corresponding to the SSH credentials that you just selected
|
125
|
+
* You may name this anything you like. For example: your project name, hostname or name of the SSH key you just chose
|
126
|
+
EOS
|
127
|
+
key_pair_name = ask "AWS EC2 Key Pair Name [#{config['ec2_server_access']['key_pair_name']}]: "
|
128
|
+
config['ec2_server_access']['key_pair_name'] = key_pair_name if key_pair_name != ""
|
129
|
+
|
130
|
+
say <<-EOS
|
131
|
+
* This needs to refer to an SSH Private Key that has been associated an account that has access to the git
|
132
|
+
* repository you entered above. On github this will be listed here: https://github.com/settings/ssh
|
133
|
+
EOS
|
134
|
+
while true do
|
135
|
+
github_private_ssh_key_path = ask "Path to SSH Private Key for Github [#{config['github_private_ssh_key_path']}]: "
|
136
|
+
config['github_private_ssh_key_path'] = github_private_ssh_key_path if github_private_ssh_key_path != ""
|
137
|
+
if config['github_private_ssh_key_path'] != File.expand_path(config['github_private_ssh_key_path'])
|
138
|
+
config['github_private_ssh_key_path'] = File.expand_path(File.join(ENV['HOME'], '.ssh', config['github_private_ssh_key_path']))
|
139
|
+
end
|
140
|
+
if File.exist?(config['github_private_ssh_key_path'])
|
141
|
+
break
|
142
|
+
else
|
143
|
+
say "Unable to find #{config['github_private_ssh_key_path']}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
config_ci = YAML.load_file(Rails.root.join("config/ci.yml")) rescue {}
|
150
|
+
config_ci.merge!(config)
|
151
|
+
|
152
|
+
File.open(Rails.root.join("config/ci.yml"), "w") do |f|
|
153
|
+
f << config_ci.to_yaml
|
154
|
+
end
|
155
|
+
|
156
|
+
say "\n\nconfig/ci.yml configured. To launch your instance run rake ci:server_start."
|
157
|
+
say "Be sure to push uncommitted changes made by the lobot:install process first."
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|