5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/generators/lobot/config_generator.rb', line 5
def generate_ci_config
default_git_location = nil
if File.exist?(Rails.root.join(".git/config"))
default_git_location = `cat .git/config | grep url`.strip.split.last
else
puts "nope"
end
default_app_name = File.basename(Rails.root)
config = {
'app_name' => default_app_name,
'app_user' => "ci",
'git_location' => default_git_location,
'basic_auth' => [
{
'username' => "ci"
}
],
'credentials' => {
'provider' => "AWS"
},
'server' => {
'name' => nil,
'instance_id' => nil,
'flavor_id' => "m1.large",
'security_group' => "ci_servers",
'ssh_port' => "22"
},
'build_command' => "./script/ci_build.sh",
'ec2_server_access' => {
"key_pair_name" => "#{default_app_name}_ci",
"id_rsa_path" => File.expand_path("~/.ssh/id_rsa")
},
"github_private_ssh_key_path" => File.expand_path("~/.ssh/id_rsa")
}
say "* The name of your application as it will appear in CI", :green
app_name = ask("Application Name [#{config['app_name']}]:", :bold)
config['app_name'] = app_name if app_name != ""
say "* The location of your remote git repository which CI will poll and pull from on changes", :green
git_location = ask("Git Repository Location [#{config['git_location']}]:", :bold)
config['git_location'] = git_location if git_location != ""
say "* The username you will use to access the CI web interface", :green
ci_username = ask("CI Username [#{config['basic_auth'][0]['username']}]:", :bold)
config['basic_auth'][0]['username'] = ci_username if ci_username != ""
say "* The password you will use to access the CI web interface", :green
while true do
ci_password = ask("Choose a CI password:", :bold)
config['basic_auth'][0]['password'] = ci_password
if ci_password == ""
say "Password cannot be blank", :red
else
break
end
end
say (<<-EOS).chop, :green
* See https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
* for access key id and secret access key
EOS
while true do
aws_access_key_id = ask("AWS Access Key ID:", :bold)
config['credentials']['aws_access_key_id'] = aws_access_key_id
if aws_access_key_id == ""
say "AWS Access Key ID cannot be blank", :red
else
break
end
end
while true do
aws_secret_access_key = ask("AWS Secret Access Key:", :bold)
config['credentials']['aws_secret_access_key'] = aws_secret_access_key
if aws_secret_access_key == ""
say "AWS Secret Access Key cannot be blank", :red
else
break
end
end
build_command = ask("Build Command: [#{config['build_command']}]:", :bold)
config['build_command'] = build_command if build_command != ""
say (<<-EOS).chop, :green
* This should refer to an SSH key pair that you have already generated. You may wish to generate a new key
* separate from what you may already be using for github or other systems.
* For a tutorial on this see: http://open.bsdcow.org/histerical/tutorials/ssh_pubkey_auth#1.2
EOS
while true do
id_rsa_path = ask("SSH Private Key for EC2 Access [#{config['ec2_server_access']['id_rsa_path'].split('/').last}]:", :bold)
config['ec2_server_access']['id_rsa_path'] = id_rsa_path if id_rsa_path != ""
if config['ec2_server_access']['id_rsa_path'] != File.expand_path(config['ec2_server_access']['id_rsa_path'])
config['ec2_server_access']['id_rsa_path'] = File.expand_path(File.join(ENV['HOME'], '.ssh', config['ec2_server_access']['id_rsa_path']))
end
if File.exist?(config['ec2_server_access']['id_rsa_path']) && File.exist?("#{config['ec2_server_access']['id_rsa_path']}.pub")
break
else
say "Unable to find both #{config['ec2_server_access']['id_rsa_path']} and #{config['ec2_server_access']['id_rsa_path']}.pub", :red
end
end
say (<<-EOS).chop, :green
* This needs to refer to an SSH Private Key that has been associated an account that has access to the git
* repository you entered above. On github this will be listed here: https://github.com/settings/ssh
EOS
while true do
github_private_ssh_key_path = ask("SSH Private Key for Github [#{config['github_private_ssh_key_path'].split('/').last}]:", :bold)
config['github_private_ssh_key_path'] = github_private_ssh_key_path if github_private_ssh_key_path != ""
if config['github_private_ssh_key_path'] != File.expand_path(config['github_private_ssh_key_path'])
config['github_private_ssh_key_path'] = File.expand_path(File.join(ENV['HOME'], '.ssh', config['github_private_ssh_key_path']))
end
if File.exist?(config['github_private_ssh_key_path'])
break
else
say "Unable to find #{config['github_private_ssh_key_path']}", :red
end
end
config_ci = YAML.load_file(Rails.root.join("config/ci.yml")) rescue {}
config_ci.merge!(config)
File.open(Rails.root.join("config/ci.yml"), "w") do |f|
f << config_ci.to_yaml
end
say "\n\nconfig/ci.yml configured:\n#{File.read(Rails.root.join('config/ci.yml'))}\n"
say "You can edit this file to change any additional defaults."
say "Before continuing, be sure to push uncommitted changes to your git repository.", :green
say "For next steps, see the lobot README.md"
end
|