railshoster 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.textile +8 -1
- data/Gemfile.lock +94 -0
- data/bin/railshoster +4 -3
- data/lib/railshoster/command.rb +6 -0
- data/lib/railshoster/init_capistrano_helpers.rb +27 -0
- data/lib/railshoster/init_command.rb +64 -122
- data/lib/railshoster/init_database_helpers.rb +53 -0
- data/lib/railshoster/init_gem_helpers.rb +45 -0
- data/lib/railshoster/init_ssh_helpers.rb +53 -0
- data/lib/railshoster/init_validation_helpers.rb +49 -0
- data/lib/railshoster/version.rb +1 -1
- data/spec/.DS_Store +0 -0
- data/spec/fakefs/bundler/mysql/Gemfile.lock +94 -0
- data/spec/fakefs/bundler/mysql2/Gemfile.lock +94 -0
- data/spec/fakefs/bundler/pg/Gemfile.lock +94 -0
- data/spec/fakefs/database_yml/database.mysql.yml +13 -0
- data/spec/{fake_dot_ssh → fakefs/fake_dot_ssh}/1_valid_key/bullshit.pub +0 -0
- data/spec/{fake_dot_ssh → fakefs/fake_dot_ssh}/1_valid_key/id_rsa.pub +0 -0
- data/spec/{fake_dot_ssh → fakefs/fake_dot_ssh}/2_valid_keys/github_rsa.pub +0 -0
- data/spec/{fake_dot_ssh → fakefs/fake_dot_ssh}/2_valid_keys/id_dsa.pub +0 -0
- data/spec/lib/railshoster/command_spec.rb +10 -0
- data/spec/lib/railshoster/init_command_spec.rb +6 -8
- data/spec/lib/railshoster/init_database_helpers_spec.rb +33 -0
- data/spec/lib/railshoster/init_gem_helpers_spec.rb +55 -0
- data/spec/lib/railshoster/utilities_spec.rb +3 -3
- data/templates/h/deploy.rb.erb +2 -11
- metadata +32 -13
data/CHANGELOG.textile
CHANGED
@@ -57,4 +57,11 @@ h3. 0.5.0
|
|
57
57
|
|
58
58
|
h3. 0.5.1
|
59
59
|
|
60
|
-
* Bugfix in deploy.rb.
|
60
|
+
* Bugfix in deploy.rb.
|
61
|
+
|
62
|
+
h3. 0.6.0
|
63
|
+
|
64
|
+
* Splited up init_command into several helper modules to keep the InitCommand classes' main workflow clear and obvious.
|
65
|
+
* Analysis of Gemfile.lock to determine your database adapter to modify database.yml.
|
66
|
+
* Refactored product specific settings.
|
67
|
+
* Moved from deploy.rb.yml into init_comand. added database.yml update via sftp
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
acts_as_commentable (3.0.1)
|
32
|
+
arel (2.0.10)
|
33
|
+
authlogic (3.0.3)
|
34
|
+
activerecord (>= 3.0.7)
|
35
|
+
activerecord (>= 3.0.7)
|
36
|
+
builder (2.1.2)
|
37
|
+
cocaine (0.2.0)
|
38
|
+
erubis (2.6.6)
|
39
|
+
abstract (>= 1.0.0)
|
40
|
+
haml (3.1.3)
|
41
|
+
i18n (0.5.0)
|
42
|
+
mail (2.2.19)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.17.2)
|
48
|
+
mysql2 (0.2.7)
|
49
|
+
paperclip (2.3.16)
|
50
|
+
activerecord (>= 2.3.0)
|
51
|
+
activesupport (>= 2.3.2)
|
52
|
+
cocaine (>= 0.0.2)
|
53
|
+
mime-types
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.2.4)
|
56
|
+
rack-mount (0.6.14)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (0.5.7)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.0.7)
|
61
|
+
actionmailer (= 3.0.7)
|
62
|
+
actionpack (= 3.0.7)
|
63
|
+
activerecord (= 3.0.7)
|
64
|
+
activeresource (= 3.0.7)
|
65
|
+
activesupport (= 3.0.7)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.0.7)
|
68
|
+
railties (3.0.7)
|
69
|
+
actionpack (= 3.0.7)
|
70
|
+
activesupport (= 3.0.7)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
thor (~> 0.14.4)
|
73
|
+
rake (0.8.7)
|
74
|
+
sass (3.1.10)
|
75
|
+
thor (0.14.6)
|
76
|
+
treetop (1.4.10)
|
77
|
+
polyglot
|
78
|
+
polyglot (>= 0.3.1)
|
79
|
+
tzinfo (0.3.31)
|
80
|
+
will_paginate (3.0.2)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
acts_as_commentable (>= 3.0.1)
|
87
|
+
authlogic (~> 3.0.3)
|
88
|
+
haml (>= 3.1.1)
|
89
|
+
mysql2 (= 0.2.7)
|
90
|
+
paperclip (~> 2.3.6)
|
91
|
+
rails (= 3.0.7)
|
92
|
+
rake (= 0.8.7)
|
93
|
+
sass (>= 3.1.1)
|
94
|
+
will_paginate (>= 3.0.pre2)
|
data/bin/railshoster
CHANGED
@@ -35,12 +35,13 @@ command [:init] do |c|
|
|
35
35
|
ask_for_project_dir(cwd) if args.empty?
|
36
36
|
project_git_dir_name = args[0] || cwd
|
37
37
|
|
38
|
-
|
38
|
+
|
39
|
+
|
39
40
|
|
40
41
|
if options[:a] then
|
41
|
-
|
42
|
+
Railshoster::InitCommand.run_by_application_token(project_git_dir_name, options[:a])
|
42
43
|
elsif options[:j] then
|
43
|
-
|
44
|
+
Railshoster::InitCommand.new(project_git_dir_name, options[:j]).start
|
44
45
|
else
|
45
46
|
raise "Illegal State."
|
46
47
|
end
|
data/lib/railshoster/command.rb
CHANGED
@@ -15,6 +15,12 @@ module Railshoster
|
|
15
15
|
|
16
16
|
protected
|
17
17
|
|
18
|
+
def get_git_remote_url_from_git_config
|
19
|
+
|
20
|
+
#TODO Error management: what if there is not remote url (local repo)?
|
21
|
+
@git.config['remote.origin.url']
|
22
|
+
end
|
23
|
+
|
18
24
|
def capfile_exists?
|
19
25
|
File.exists?(capfile_path)
|
20
26
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Railshoster
|
2
|
+
module InitCapistranoHelpers
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def create_deployrb(app_hash)
|
7
|
+
deployrb_str = ""
|
8
|
+
deployrb_str = Railshoster::Capistrano::Config.render_deploy_rb_to_s(app_hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_deploy_rb(deployrb_str)
|
12
|
+
deployrb_basepath = File.join(@project_dir, "config")
|
13
|
+
FileUtils.mkdir_p(deployrb_basepath)
|
14
|
+
|
15
|
+
deployrb_path = File.join(deployrb_basepath, "deploy.rb")
|
16
|
+
Railshoster::Utilities.backup_file(deployrb_path) if File.exists?(deployrb_path)
|
17
|
+
|
18
|
+
File.open(deployrb_path, "w+") { |f| f << deployrb_str }
|
19
|
+
end
|
20
|
+
|
21
|
+
def capify_project
|
22
|
+
puts "\n\tWarning: You are initializing a project with an existing Capfile.\n" if capfile_exists?
|
23
|
+
successful = system("capify #{@project_dir}")
|
24
|
+
raise CapifyProjectFailedError.new("Couldn't capify project at #{@project_dir}") unless successful
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,21 +2,51 @@ require 'base64'
|
|
2
2
|
require 'json'
|
3
3
|
require 'git'
|
4
4
|
require 'fileutils'
|
5
|
-
require '
|
6
|
-
require 'sane'
|
5
|
+
require 'bundler'
|
7
6
|
|
8
7
|
require File.expand_path(File.join(File.dirname(__FILE__), '/capistrano/config'))
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/init_ssh_helpers'))
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/init_capistrano_helpers'))
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/init_validation_helpers'))
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/init_gem_helpers'))
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/init_database_helpers'))
|
9
13
|
|
10
14
|
module Railshoster
|
11
15
|
|
12
16
|
# This action class helps to setup a new rails applicaton
|
17
|
+
#
|
18
|
+
# == Design Contraints
|
19
|
+
# * The workflow of this class should be easy to read. Hence helper methods are sourced out to helper modules.
|
20
|
+
# * All modifications of the @app_hash must be done within this file not in a helper module. This helps to easily grasp the app_hash structure with all changed made to it.
|
13
21
|
class InitCommand < Command
|
14
22
|
|
15
|
-
|
23
|
+
include Railshoster::InitSshHelpers
|
24
|
+
include Railshoster::InitCapistranoHelpers
|
25
|
+
include Railshoster::InitGemHelpers
|
26
|
+
include Railshoster::InitValidationHelpers
|
27
|
+
include Railshoster::InitDatabaseHelpers
|
28
|
+
|
29
|
+
def initialize(project_dir, application_hash_as_json_string)
|
30
|
+
super(project_dir)
|
31
|
+
@application_hash_as_json_string = application_hash_as_json_string
|
32
|
+
end
|
33
|
+
|
34
|
+
#### Instance Methods
|
35
|
+
def start
|
36
|
+
check_system_requirements
|
37
|
+
check_project_requirements
|
38
|
+
@app_hash = parse_application_json_hash(@application_hash_as_json_string)
|
39
|
+
expand_app_hash_product_specifically
|
40
|
+
process_application_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
#### Static
|
44
|
+
|
45
|
+
def self.run_by_application_token(project_dir, application_token)
|
16
46
|
decoded_token = decode_token(application_token)
|
17
47
|
|
18
48
|
begin
|
19
|
-
|
49
|
+
new(project_dir, decoded_token).start
|
20
50
|
rescue BadApplicationJSONHashError => e
|
21
51
|
msg = "Please verify your application_token. It did not decode to a valid application hash.\n" +
|
22
52
|
"This is how your application token looked like:\n\n#{application_token.inspect}\n\n" +
|
@@ -26,118 +56,51 @@ module Railshoster
|
|
26
56
|
end
|
27
57
|
end
|
28
58
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
59
|
+
#### Protected Instance Methods
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def process_application_hash
|
64
|
+
expand_app_hash_product_specifically
|
65
|
+
# e.g. mysql2
|
66
|
+
@app_hash["db_gem"] = get_db_gem.name
|
67
|
+
|
34
68
|
# Extract GIT URL from project and add it to the app_hash
|
35
69
|
git_url = get_git_remote_url_from_git_config
|
36
|
-
app_hash["git"] = git_url
|
70
|
+
@app_hash["git"] = git_url
|
37
71
|
|
38
72
|
#TODO Add connection test -> If there's already access -> no need to do this
|
39
73
|
selected_key = Railshoster::Utilities.select_public_ssh_key
|
40
|
-
app_hash["public_ssh_key"] = Pathname.new(selected_key[:path]).basename.to_s.gsub(".pub", "")
|
74
|
+
@app_hash["public_ssh_key"] = Pathname.new(selected_key[:path]).basename.to_s.gsub(".pub", "")
|
41
75
|
|
42
|
-
create_remote_authorized_key_file_from_app_hash(app_hash, selected_key)
|
43
|
-
|
76
|
+
create_remote_authorized_key_file_from_app_hash(@app_hash, selected_key)
|
77
|
+
|
78
|
+
@app_hash["remote_db_yml"] = "#{@app_hash["deploy_to"]}/shared/config/database.yml"
|
79
|
+
update_database_yml_db_adapters_via_ssh
|
80
|
+
|
81
|
+
deployrb_str = create_deployrb(@app_hash)
|
44
82
|
write_deploy_rb(deployrb_str)
|
45
83
|
capify_project
|
46
84
|
success_message
|
47
85
|
end
|
48
86
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
check_gemfile
|
60
|
-
end
|
61
|
-
|
62
|
-
def check_gemfile
|
63
|
-
gem_file = File.join(@project_dir, "Gemfile")
|
64
|
-
unless File.exists?(gem_file) then
|
65
|
-
puts "\nWarning: Your project does not seem to have a Gemfile. Please ensure your are using bundler."
|
66
|
-
exit_now!("Initialization aborted. No Gemfile found.", -1)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def check_os
|
71
|
-
if OS.windows? then
|
72
|
-
puts "\nWarning: This software requires a Unix/Linux/BSD OS. Do you really want to proceed?"
|
73
|
-
decision = STDIN.gets.chomp
|
74
|
-
unless %w(y Y).include?(decision) then
|
75
|
-
exit_now!("Initialization aborted. Bad operating system.", -1)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def create_remote_authorized_key_file_from_app_hash(app_hash, key)
|
81
|
-
if app_hash["t"].eql?("h") then
|
82
|
-
|
83
|
-
# For a hosting package the password is the deploy user's password
|
84
|
-
create_remote_authorized_key_file(app_hash["h"], app_hash["u"], app_hash["p"], key)
|
85
|
-
elsif app_hash["t"].eql?("v") then
|
86
|
-
|
87
|
-
# For a vps the given password it the root user's password -> Register key for root user
|
88
|
-
create_remote_authorized_key_file(app_hash["h"], "root", app_hash["p"], key)
|
89
|
-
|
90
|
-
# Also register the public key to enable key access to the deploy user
|
91
|
-
# This means that the
|
92
|
-
create_remote_authorized_key_file(app_hash["h"], "root", app_hash["p"], key, "/home/#{app_hash['u']}/.ssh", app_hash['u'])
|
93
|
-
else
|
94
|
-
exit_now!("Initialization aborted. Invalid product type: #{app_hash['t']}.", -1)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Creates a remote authorized keys file for the given public key
|
99
|
-
#
|
100
|
-
# === Parameters
|
101
|
-
# +host+:: SSH host to connect to
|
102
|
-
# +password+:: SSH password
|
103
|
-
# +key+:: Public key hash. Have a look at +Railshoster::Utilities.select_public_ssh_key+ for more details about the key structure.
|
104
|
-
# +remote_dot_ssh_path+:: Remote path to the user's .ssh path. Usually this is relative to the ssh-users's home path. Use absolute path names to avoid that.
|
105
|
-
# +target_username+:: Optional. If this parameter is set .ssh directory and the authorized_keys file will be assegned to the user with the given username.
|
106
|
-
def create_remote_authorized_key_file(host, ssh_username, password, key, remote_dot_ssh_path = ".ssh", target_username = nil)
|
107
|
-
remote_authorized_keys_path = remote_dot_ssh_path + "/authorized_keys"
|
108
|
-
Net::SFTP.start(host, ssh_username, :password => password) do |sftp|
|
109
|
-
|
110
|
-
#TODO Smarter way to determine home directory
|
111
|
-
stats = sftp.stat!("/home/#{target_username}") if target_username
|
112
|
-
|
113
|
-
begin
|
114
|
-
sftp.mkdir!(remote_dot_ssh_path)
|
115
|
-
sftp.setstat(remote_dot_ssh_path, :uid => stats.uid, :gid => stats.gid) if target_username
|
116
|
-
rescue Net::SFTP::StatusException => e
|
117
|
-
# Most likely the .ssh folder already exists raise again if not.
|
118
|
-
raise e unless e.code == 4
|
119
|
-
end
|
120
|
-
sftp.upload!(key[:path].to_s, remote_authorized_keys_path)
|
121
|
-
sftp.setstat(remote_authorized_keys_path, :uid => stats.uid, :gid => stats.gid) if target_username
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def create_deployrb(app_hash)
|
126
|
-
deployrb_str = ""
|
127
|
-
|
128
|
-
# Choose the further process depending on the application type by applying a strategy pattern.
|
129
|
-
case app_hash["t"].to_sym
|
130
|
-
when :h, :v
|
131
|
-
# Shared Hosting Deployments
|
132
|
-
deployrb_str = Railshoster::Capistrano::Config.render_deploy_rb_to_s(app_hash)
|
87
|
+
# Add values ot app_hash specific to the given product type.
|
88
|
+
def expand_app_hash_product_specifically
|
89
|
+
case @app_hash["t"].to_sym
|
90
|
+
when :h
|
91
|
+
@app_hash["deploy_to"] = "/home/#{@app_hash['u']}/#{@app_hash['a']}"
|
92
|
+
@app_hash["app_url"] = "http://#{@app_hash['u']}-#{@app_hash['aid']}.#{@app_hash['h']}"
|
93
|
+
when :v
|
94
|
+
@app_hash["deploy_to"] = "/var/www/#{@app_hash['a']}"
|
95
|
+
@app_hash["app_url"] = "http://#{@app_hash['a']}.#{@app_hash['h']}"
|
133
96
|
else
|
134
97
|
raise UnsupportedApplicationTypeError.new
|
135
98
|
end
|
136
|
-
end
|
137
|
-
|
99
|
+
end
|
100
|
+
|
138
101
|
# Decodoes token to get the JSON hash back.
|
139
102
|
# gQkUSMakKRPhm0EIaer => {"key":"value"}
|
140
|
-
def decode_token(token)
|
103
|
+
def self.decode_token(token)
|
141
104
|
Base64.decode64(token)
|
142
105
|
end
|
143
106
|
|
@@ -148,30 +111,9 @@ module Railshoster
|
|
148
111
|
msg = "The application hash you have passed is malformed. It could not be parsed as regular JSON. It looked like this:\n\n #{app_hash_as_json_string.inspect}\n"
|
149
112
|
raise BadApplicationJSONHashError.new(msg + "\nHere is what the JSON parse said:\n\n" + e.message)
|
150
113
|
end
|
114
|
+
ruby_app_hash
|
151
115
|
end
|
152
|
-
|
153
|
-
def get_git_remote_url_from_git_config
|
154
116
|
|
155
|
-
#TODO Error management: what if there is not remote url (local repo)?
|
156
|
-
@git.config['remote.origin.url']
|
157
|
-
end
|
158
|
-
|
159
|
-
def write_deploy_rb(deployrb_str)
|
160
|
-
deployrb_basepath = File.join(@project_dir, "config")
|
161
|
-
FileUtils.mkdir_p(deployrb_basepath)
|
162
|
-
|
163
|
-
deployrb_path = File.join(deployrb_basepath, "deploy.rb")
|
164
|
-
Railshoster::Utilities.backup_file(deployrb_path) if File.exists?(deployrb_path)
|
165
|
-
|
166
|
-
File.open(deployrb_path, "w+") { |f| f << deployrb_str }
|
167
|
-
end
|
168
|
-
|
169
|
-
def capify_project
|
170
|
-
puts "\n\tWarning: You are initializing a project with an existing Capfile.\n" if capfile_exists?
|
171
|
-
successful = system("capify #{@project_dir}")
|
172
|
-
raise CapifyProjectFailedError.new("Couldn't capify project at #{@project_dir}") unless successful
|
173
|
-
end
|
174
|
-
|
175
117
|
def success_message
|
176
118
|
puts "Your application has been successfully initialized."
|
177
119
|
puts "\n\tYou can now use 'railshoster deploy' to deploy your app.\n\n"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Railshoster
|
5
|
+
module InitDatabaseHelpers
|
6
|
+
|
7
|
+
# Currently pointless but for Postgres this will look like this {"pg" => "postgresql"}
|
8
|
+
DB_GEM_TO_DB_ADAPTER = {"mysql" => "mysql", "mysql2" => "mysql2"}
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
# Receive and update a database.yml via SFTP.
|
13
|
+
def update_database_yml_db_adapters_via_ssh(host = @app_hash["h"], ssh_username = @app_hash["u"], path_to_dbyml = @app_hash["remote_db_yml"])
|
14
|
+
dbyml = ""
|
15
|
+
Net::SFTP.start(host, ssh_username) do |sftp|
|
16
|
+
sftp.file.open(path_to_dbyml) do |file|
|
17
|
+
dbyml = file.read
|
18
|
+
end
|
19
|
+
sftp.file.open(path_to_dbyml, "w+") do |file|
|
20
|
+
file.write(update_database_yml_db_adapters_in_yml(dbyml))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_path_to_dbyml
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# Takes a yml string, replaces the db adapters and produces yml again.
|
30
|
+
def update_database_yml_db_adapters_in_yml(dbyml_str)
|
31
|
+
dbyml = YAML.load(dbyml_str)
|
32
|
+
|
33
|
+
db_adapter = DB_GEM_TO_DB_ADAPTER[@app_hash["db_gem"].downcase]
|
34
|
+
|
35
|
+
%w(production development).each do |env|
|
36
|
+
dbyml[env]["adapter"] = db_adapter
|
37
|
+
end
|
38
|
+
|
39
|
+
YAML.dump(dbyml)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Receive a database.yml via SFTP.
|
43
|
+
def get_database_yml(host, ssh_username, path_to_dbyml)
|
44
|
+
dbyml = ""
|
45
|
+
Net::SFTP.start(host, ssh_username) do |sftp|
|
46
|
+
sftp.file.open(path_to_dbyml) do |file|
|
47
|
+
dbyml = file.read
|
48
|
+
end
|
49
|
+
end
|
50
|
+
dbyml
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Railshoster
|
2
|
+
|
3
|
+
# == Assumptions
|
4
|
+
# * +@project_dir+ is defined.
|
5
|
+
module InitGemHelpers
|
6
|
+
|
7
|
+
UNSUPPORTED_DATABASE_GEMS = %w(pq sqlite sqlite2 sqlite3)
|
8
|
+
SUPPORTED_DATABASE_GEMS = %w(mysql mysql2)
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def gemfilelock_filepath
|
13
|
+
File.join(@project_dir, "Gemfile.lock")
|
14
|
+
end
|
15
|
+
|
16
|
+
#TODO Find a better place for this method
|
17
|
+
def get_db_gem(path_to_gemfilelock = gemfilelock_filepath)
|
18
|
+
gemfilelock = File.open(path_to_gemfilelock).read
|
19
|
+
p = Bundler::LockfileParser.new(gemfilelock)
|
20
|
+
|
21
|
+
found_supported_db_gems = []
|
22
|
+
found_unsupported_db_gems = []
|
23
|
+
|
24
|
+
p.dependencies.each do |dependency|
|
25
|
+
found_supported_db_gems << dependency if SUPPORTED_DATABASE_GEMS.include?(dependency.name)
|
26
|
+
found_unsupported_db_gems << dependency if UNSUPPORTED_DATABASE_GEMS.include?(dependency.name)
|
27
|
+
end
|
28
|
+
|
29
|
+
unless found_unsupported_db_gems.empty? then
|
30
|
+
puts "Attention: You are using unsupported database gems. This might cause problems: #{found_unsupported_db_gems.inspect}"
|
31
|
+
end
|
32
|
+
|
33
|
+
if found_supported_db_gems.size == 1 then
|
34
|
+
puts "Everything is fine. You are using: #{found_supported_db_gems.first.name}"
|
35
|
+
|
36
|
+
elsif found_supported_db_gems.size > 1 then
|
37
|
+
puts "You are using more than one supported database gem. Hence I cannot uniquely identify the gem your app depends on. Please change your Gemfile and perform bundle update to update your Gemfile.lock file."
|
38
|
+
raise("Abortet. Ambigious database gem information.")
|
39
|
+
else
|
40
|
+
raise("Abortet. Haven't found a supported database gem. Please consider to use mysql2.")
|
41
|
+
end
|
42
|
+
found_supported_db_gems.first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
3
|
+
module Railshoster
|
4
|
+
module InitSshHelpers
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def create_remote_authorized_key_file_from_app_hash(app_hash, key)
|
9
|
+
if app_hash["t"].eql?("h") then
|
10
|
+
|
11
|
+
# For a hosting package the password is the deploy user's password
|
12
|
+
create_remote_authorized_key_file(app_hash["h"], app_hash["u"], app_hash["p"], key)
|
13
|
+
elsif app_hash["t"].eql?("v") then
|
14
|
+
|
15
|
+
# For a vps the given password it the root user's password -> Register key for root user
|
16
|
+
create_remote_authorized_key_file(app_hash["h"], "root", app_hash["p"], key)
|
17
|
+
|
18
|
+
# Also register the public key to enable key access to the deploy user
|
19
|
+
create_remote_authorized_key_file(app_hash["h"], "root", app_hash["p"], key, "/home/#{app_hash['u']}/.ssh", app_hash['u'])
|
20
|
+
else
|
21
|
+
raise("Initialization aborted. Invalid product type: #{app_hash['t']}.")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a remote authorized keys file for the given public key
|
26
|
+
#
|
27
|
+
# === Parameters
|
28
|
+
# +host+:: SSH host to connect to
|
29
|
+
# +password+:: SSH password
|
30
|
+
# +key+:: Public key hash. Have a look at +Railshoster::Utilities.select_public_ssh_key+ for more details about the key structure.
|
31
|
+
# +remote_dot_ssh_path+:: Remote path to the user's .ssh path. Usually this is relative to the ssh-users's home path. Use absolute path names to avoid that.
|
32
|
+
# +target_username+:: Optional. If this parameter is set .ssh directory and the authorized_keys file will be assegned to the user with the given username.
|
33
|
+
def create_remote_authorized_key_file(host, ssh_username, password, key, remote_dot_ssh_path = ".ssh", target_username = nil)
|
34
|
+
|
35
|
+
remote_authorized_keys_path = remote_dot_ssh_path + "/authorized_keys"
|
36
|
+
Net::SFTP.start(host, ssh_username, :password => password) do |sftp|
|
37
|
+
|
38
|
+
#TODO Smarter way to determine home directory
|
39
|
+
stats = sftp.stat!("/home/#{target_username}") if target_username
|
40
|
+
|
41
|
+
begin
|
42
|
+
sftp.mkdir!(remote_dot_ssh_path)
|
43
|
+
sftp.setstat(remote_dot_ssh_path, :uid => stats.uid, :gid => stats.gid) if target_username
|
44
|
+
rescue Net::SFTP::StatusException => e
|
45
|
+
# Most likely the .ssh folder already exists raise again if not.
|
46
|
+
raise e unless e.code == 4
|
47
|
+
end
|
48
|
+
sftp.upload!(key[:path].to_s, remote_authorized_keys_path)
|
49
|
+
sftp.setstat(remote_authorized_keys_path, :uid => stats.uid, :gid => stats.gid) if target_username
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'sane'
|
2
|
+
|
3
|
+
module Railshoster
|
4
|
+
|
5
|
+
# == Assumptions
|
6
|
+
# * +@project_dir+ is defined.
|
7
|
+
module InitValidationHelpers
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def check_system_requirements
|
12
|
+
check_os
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_project_requirements
|
16
|
+
#TOOD implement
|
17
|
+
# check_git
|
18
|
+
|
19
|
+
check_gemfile_exists
|
20
|
+
check_gemfile_lock_exists
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_gemfile_exists
|
24
|
+
gemfile = File.join(@project_dir, "Gemfile")
|
25
|
+
unless File.exists?(gemfile) then
|
26
|
+
puts "\nWarning: Your project does not seem to have a Gemfile. Please ensure your are using bundler."
|
27
|
+
raise("Initialization aborted. No Gemfile found.")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_gemfile_lock_exists
|
32
|
+
unless File.exists?(gemfilelock_filepath) then
|
33
|
+
puts "\nWarning: Can't find Gemfile.lock. Are you using bundler? Try to perform bundle install AND/OR bundle update to create a Gemfile.lock. You will need it in order to deploy your app."
|
34
|
+
raise("Abortet. No Gemfile.lock found.")
|
35
|
+
end
|
36
|
+
gemfilelock_filepath
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_os
|
40
|
+
if OS.windows? then
|
41
|
+
puts "\nWarning: This software requires a Unix/Linux/BSD OS. Do you really want to proceed?"
|
42
|
+
decision = STDIN.gets.chomp
|
43
|
+
unless %w(y Y).include?(decision) then
|
44
|
+
raise("Initialization aborted. Bad operating system.")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/railshoster/version.rb
CHANGED
data/spec/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
acts_as_commentable (3.0.1)
|
32
|
+
arel (2.0.10)
|
33
|
+
authlogic (3.0.3)
|
34
|
+
activerecord (>= 3.0.7)
|
35
|
+
activerecord (>= 3.0.7)
|
36
|
+
builder (2.1.2)
|
37
|
+
cocaine (0.2.0)
|
38
|
+
erubis (2.6.6)
|
39
|
+
abstract (>= 1.0.0)
|
40
|
+
haml (3.1.3)
|
41
|
+
i18n (0.5.0)
|
42
|
+
mail (2.2.19)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.17.2)
|
48
|
+
mysql (0.2.7)
|
49
|
+
paperclip (2.3.16)
|
50
|
+
activerecord (>= 2.3.0)
|
51
|
+
activesupport (>= 2.3.2)
|
52
|
+
cocaine (>= 0.0.2)
|
53
|
+
mime-types
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.2.4)
|
56
|
+
rack-mount (0.6.14)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (0.5.7)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.0.7)
|
61
|
+
actionmailer (= 3.0.7)
|
62
|
+
actionpack (= 3.0.7)
|
63
|
+
activerecord (= 3.0.7)
|
64
|
+
activeresource (= 3.0.7)
|
65
|
+
activesupport (= 3.0.7)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.0.7)
|
68
|
+
railties (3.0.7)
|
69
|
+
actionpack (= 3.0.7)
|
70
|
+
activesupport (= 3.0.7)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
thor (~> 0.14.4)
|
73
|
+
rake (0.8.7)
|
74
|
+
sass (3.1.10)
|
75
|
+
thor (0.14.6)
|
76
|
+
treetop (1.4.10)
|
77
|
+
polyglot
|
78
|
+
polyglot (>= 0.3.1)
|
79
|
+
tzinfo (0.3.31)
|
80
|
+
will_paginate (3.0.2)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
acts_as_commentable (>= 3.0.1)
|
87
|
+
authlogic (~> 3.0.3)
|
88
|
+
haml (>= 3.1.1)
|
89
|
+
mysql (= 0.2.7)
|
90
|
+
paperclip (~> 2.3.6)
|
91
|
+
rails (= 3.0.7)
|
92
|
+
rake (= 0.8.7)
|
93
|
+
sass (>= 3.1.1)
|
94
|
+
will_paginate (>= 3.0.pre2)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
acts_as_commentable (3.0.1)
|
32
|
+
arel (2.0.10)
|
33
|
+
authlogic (3.0.3)
|
34
|
+
activerecord (>= 3.0.7)
|
35
|
+
activerecord (>= 3.0.7)
|
36
|
+
builder (2.1.2)
|
37
|
+
cocaine (0.2.0)
|
38
|
+
erubis (2.6.6)
|
39
|
+
abstract (>= 1.0.0)
|
40
|
+
haml (3.1.3)
|
41
|
+
i18n (0.5.0)
|
42
|
+
mail (2.2.19)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.17.2)
|
48
|
+
mysql2 (0.2.7)
|
49
|
+
paperclip (2.3.16)
|
50
|
+
activerecord (>= 2.3.0)
|
51
|
+
activesupport (>= 2.3.2)
|
52
|
+
cocaine (>= 0.0.2)
|
53
|
+
mime-types
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.2.4)
|
56
|
+
rack-mount (0.6.14)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (0.5.7)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.0.7)
|
61
|
+
actionmailer (= 3.0.7)
|
62
|
+
actionpack (= 3.0.7)
|
63
|
+
activerecord (= 3.0.7)
|
64
|
+
activeresource (= 3.0.7)
|
65
|
+
activesupport (= 3.0.7)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.0.7)
|
68
|
+
railties (3.0.7)
|
69
|
+
actionpack (= 3.0.7)
|
70
|
+
activesupport (= 3.0.7)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
thor (~> 0.14.4)
|
73
|
+
rake (0.8.7)
|
74
|
+
sass (3.1.10)
|
75
|
+
thor (0.14.6)
|
76
|
+
treetop (1.4.10)
|
77
|
+
polyglot
|
78
|
+
polyglot (>= 0.3.1)
|
79
|
+
tzinfo (0.3.31)
|
80
|
+
will_paginate (3.0.2)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
acts_as_commentable (>= 3.0.1)
|
87
|
+
authlogic (~> 3.0.3)
|
88
|
+
haml (>= 3.1.1)
|
89
|
+
mysql2 (= 0.2.7)
|
90
|
+
paperclip (~> 2.3.6)
|
91
|
+
rails (= 3.0.7)
|
92
|
+
rake (= 0.8.7)
|
93
|
+
sass (>= 3.1.1)
|
94
|
+
will_paginate (>= 3.0.pre2)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
acts_as_commentable (3.0.1)
|
32
|
+
arel (2.0.10)
|
33
|
+
authlogic (3.0.3)
|
34
|
+
activerecord (>= 3.0.7)
|
35
|
+
activerecord (>= 3.0.7)
|
36
|
+
builder (2.1.2)
|
37
|
+
cocaine (0.2.0)
|
38
|
+
erubis (2.6.6)
|
39
|
+
abstract (>= 1.0.0)
|
40
|
+
haml (3.1.3)
|
41
|
+
i18n (0.5.0)
|
42
|
+
mail (2.2.19)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.17.2)
|
48
|
+
pg (0.2.7)
|
49
|
+
paperclip (2.3.16)
|
50
|
+
activerecord (>= 2.3.0)
|
51
|
+
activesupport (>= 2.3.2)
|
52
|
+
cocaine (>= 0.0.2)
|
53
|
+
mime-types
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.2.4)
|
56
|
+
rack-mount (0.6.14)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (0.5.7)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.0.7)
|
61
|
+
actionmailer (= 3.0.7)
|
62
|
+
actionpack (= 3.0.7)
|
63
|
+
activerecord (= 3.0.7)
|
64
|
+
activeresource (= 3.0.7)
|
65
|
+
activesupport (= 3.0.7)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.0.7)
|
68
|
+
railties (3.0.7)
|
69
|
+
actionpack (= 3.0.7)
|
70
|
+
activesupport (= 3.0.7)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
thor (~> 0.14.4)
|
73
|
+
rake (0.8.7)
|
74
|
+
sass (3.1.10)
|
75
|
+
thor (0.14.6)
|
76
|
+
treetop (1.4.10)
|
77
|
+
polyglot
|
78
|
+
polyglot (>= 0.3.1)
|
79
|
+
tzinfo (0.3.31)
|
80
|
+
will_paginate (3.0.2)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
acts_as_commentable (>= 3.0.1)
|
87
|
+
authlogic (~> 3.0.3)
|
88
|
+
haml (>= 3.1.1)
|
89
|
+
pg (= 0.2.7)
|
90
|
+
paperclip (~> 2.3.6)
|
91
|
+
rails (= 3.0.7)
|
92
|
+
rake (= 0.8.7)
|
93
|
+
sass (>= 3.1.1)
|
94
|
+
will_paginate (>= 3.0.pre2)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
production:
|
2
|
+
adapter: mysql
|
3
|
+
database: rails1
|
4
|
+
username: rails1
|
5
|
+
password: Nut4KBvOqHJ5
|
6
|
+
socket: /var/run/mysqld/mysqld.sock
|
7
|
+
|
8
|
+
development:
|
9
|
+
adapter: mysql
|
10
|
+
database: rails1_development
|
11
|
+
username: rails1
|
12
|
+
password: Nut4KBvOqHJ5
|
13
|
+
socket: /var/run/mysqld/mysqld.sock
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -2,6 +2,16 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
2
|
|
3
3
|
describe Railshoster::Command do
|
4
4
|
describe "#Basics" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
git_dir = File.join(File.dirname(__FILE__), "..", "..", "..")
|
8
|
+
@init = Railshoster::Command.new(git_dir)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should read the git repo url" do
|
12
|
+
@init.send(:get_git_remote_url_from_git_config).should =~ /railshoster/
|
13
|
+
end
|
14
|
+
|
5
15
|
it "should instanciate a Command instance also initializing the project git repo" do
|
6
16
|
|
7
17
|
# We use the gem's dir as this should be a valid git repo
|
@@ -4,14 +4,11 @@ describe Railshoster::InitCommand do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
# We use the gem's dir as this should be a valid git repo
|
7
|
-
git_dir = File.join(File.dirname(__FILE__), "..", "..", "..")
|
8
|
-
@init = Railshoster::InitCommand.new(git_dir)
|
7
|
+
@git_dir = File.join(File.dirname(__FILE__), "..", "..", "..")
|
8
|
+
# @init = Railshoster::InitCommand.new(@git_dir, '{"t":"v","u":"rails1","a":"rails1","aid":1, "h":"server1717.railsvserver.de","p":"xxx"}')
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "#Git" do
|
12
|
-
it "should read the git repo url" do
|
13
|
-
@init.send(:get_git_remote_url_from_git_config).should =~ /railshoster/
|
14
|
-
end
|
11
|
+
describe "#Git" do
|
15
12
|
|
16
13
|
#TODO
|
17
14
|
it "should do sth useful if the given project dir has no remote url" do
|
@@ -33,7 +30,8 @@ describe Railshoster::InitCommand do
|
|
33
30
|
end
|
34
31
|
|
35
32
|
it "should raise an BadApplicationJSONHashError error for an invalid incoming JSON hash" do
|
36
|
-
|
33
|
+
@init = Railshoster::InitCommand.new(@git_dir, '')
|
34
|
+
expect { @init.send(:parse_application_json_hash, '') }.to raise_error(Railshoster::BadApplicationJSONHashError)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -43,7 +41,7 @@ describe Railshoster::InitCommand do
|
|
43
41
|
end
|
44
42
|
|
45
43
|
it "should raise an BadApplicationTokenError error for an invalid incoming application token" do
|
46
|
-
expect {
|
44
|
+
expect { Railshoster::InitCommand.run_by_application_token(@git_dir, "abab") }.to raise_error(Railshoster::BadApplicationTokenError)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
|
3
|
+
|
4
|
+
class MyInitDatabaseHelpersTestClass
|
5
|
+
include Railshoster::InitDatabaseHelpers
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@app_hash = {"t" => "v", "u" => "rails1", "a" => "rails1", "aid" => 1, "h" => "server1717.railsvserver.de", "p" => "xxx", "db_gem" => "mysql2"}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Railshoster::InitDatabaseHelpers do
|
13
|
+
describe "#Database.yml" do
|
14
|
+
before do
|
15
|
+
@my = MyInitDatabaseHelpersTestClass.new
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should receive a database.yml" do
|
19
|
+
pending("mock sftp")
|
20
|
+
@my.send(:get_database_yml, "server1717.railsvserver.de", "rails1", "/var/www/rails1/shared/config/database.yml")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should read and update a remote database.yml" do
|
24
|
+
pending("mock sftp")
|
25
|
+
@my.send(:update_database_yml_db_adapters_via_ssh, "server1717.railsvserver.de", "rails1", "/var/www/rails1/shared/config/database.yml")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should updatea a database.yml" do
|
29
|
+
mysql_database_yml = File.open(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "database_yml", "database.mysql.yml")).read
|
30
|
+
@my.send(:update_database_yml_db_adapters_in_yml, mysql_database_yml).should eql("--- \nproduction: \n username: rails1\n adapter: mysql2\n database: rails1\n password: Nut4KBvOqHJ5\n socket: /var/run/mysqld/mysqld.sock\ndevelopment: \n username: rails1\n adapter: mysql2\n database: rails1_development\n password: Nut4KBvOqHJ5\n socket: /var/run/mysqld/mysqld.sock\n")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Railshoster::InitGemHelpers do
|
4
|
+
|
5
|
+
# Evil: Create a fake class to test the module.
|
6
|
+
class MyInitGemHelpersTestClass
|
7
|
+
include Railshoster::InitGemHelpers
|
8
|
+
|
9
|
+
def initialize(project_dir)
|
10
|
+
@project_dir = project_dir
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#Mysql2" do
|
15
|
+
before do
|
16
|
+
@cl = MyInitGemHelpersTestClass.new(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "mysql2"))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should determine a valid Gemfile.lock path" do
|
20
|
+
@cl.send(:gemfilelock_filepath).should eql(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "mysql2", "Gemfile.lock"))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should extract the database gem from the Gemfile.lock file" do
|
24
|
+
@cl.send(:get_db_gem).name.should eql("mysql2")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#Mysql" do
|
29
|
+
before do
|
30
|
+
@cl = MyInitGemHelpersTestClass.new(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "mysql"))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should determine a valid Gemfile.lock path" do
|
34
|
+
@cl.send(:gemfilelock_filepath).should eql(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "mysql", "Gemfile.lock"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should extract the database gem from the Gemfile.lock file" do
|
38
|
+
@cl.send(:get_db_gem).name.should eql("mysql")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#Postgres" do
|
43
|
+
before do
|
44
|
+
@cl = MyInitGemHelpersTestClass.new(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "pg"))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should determine a valid Gemfile.lock path" do
|
48
|
+
@cl.send(:gemfilelock_filepath).should eql(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "bundler", "pg", "Gemfile.lock"))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should extract the database gem from the Gemfile.lock file" do
|
52
|
+
expect { @cl.send(:get_db_gem) }.to raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -69,21 +69,21 @@ describe Railshoster::Utilities do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should parse a public ssh key file" do
|
72
|
-
keys = Railshoster::Utilities.find_public_ssh_keys(File.join(File.dirname(__FILE__), "..", "..", "fake_dot_ssh", "1_valid_key"), :verbose => false)
|
72
|
+
keys = Railshoster::Utilities.find_public_ssh_keys(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "fake_dot_ssh", "1_valid_key"), :verbose => false)
|
73
73
|
keys.size.should be(1)
|
74
74
|
keys.first[:format].should eql("ssh-rsa")
|
75
75
|
keys.first[:key_data].should eql("AAAAB3NzaC1yc2EAAAADAQABAAABAQDwnMABQ9xWwYdhHaaoNSzFMfXmytWHgkBmDg6v8Fn3oILqOMs99IPd7ChPetDdUWYV2pzLVVKB/kwrcoodRC4H6YHn8xk1oI+gDsv4Yg7ytWwgnDf5zXwWMVQ/IqfOdfxRwS1UCrKL7UsVfIUPzXmkia7PoMoQNnM8jbDRDcfyis3Q1VZ9OjIlM/RfqjH0hGFS95nd6geNwpSbSpg4HxNmfltQ6GpoqclQXX0QdBO+q93sn33JjFPEhYuLvQcoea7Tl0zRY0AGQ9r7562QFlWqMmB+9YXcsZu2OZSk7t5a39jral0jEuEeJB56kb5ZUqRA1DJI5En09/WUPLCYprdb")
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should select a public ssh key without a dialog if there is only a single valid key" do
|
79
|
-
key = Railshoster::Utilities.select_public_ssh_key(File.join(File.dirname(__FILE__), "..", "..", "fake_dot_ssh", "1_valid_key"), :verbose => false)
|
79
|
+
key = Railshoster::Utilities.select_public_ssh_key(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "fake_dot_ssh", "1_valid_key"), :verbose => false)
|
80
80
|
key[:format].should eql("ssh-rsa")
|
81
81
|
key[:key_data].should eql("AAAAB3NzaC1yc2EAAAADAQABAAABAQDwnMABQ9xWwYdhHaaoNSzFMfXmytWHgkBmDg6v8Fn3oILqOMs99IPd7ChPetDdUWYV2pzLVVKB/kwrcoodRC4H6YHn8xk1oI+gDsv4Yg7ytWwgnDf5zXwWMVQ/IqfOdfxRwS1UCrKL7UsVfIUPzXmkia7PoMoQNnM8jbDRDcfyis3Q1VZ9OjIlM/RfqjH0hGFS95nd6geNwpSbSpg4HxNmfltQ6GpoqclQXX0QdBO+q93sn33JjFPEhYuLvQcoea7Tl0zRY0AGQ9r7562QFlWqMmB+9YXcsZu2OZSk7t5a39jral0jEuEeJB56kb5ZUqRA1DJI5En09/WUPLCYprdb")
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should select a public ssh key using a dialog if there is more than one valid public ssh key" do
|
85
85
|
STDIN.stubs(:gets).returns("1")
|
86
|
-
key = Railshoster::Utilities.select_public_ssh_key(File.join(File.dirname(__FILE__), "..", "..", "fake_dot_ssh", "2_valid_keys"), :verbose => false)
|
86
|
+
key = Railshoster::Utilities.select_public_ssh_key(File.join(File.dirname(__FILE__), "..", "..", "fakefs", "fake_dot_ssh", "2_valid_keys"), :verbose => false)
|
87
87
|
key[:format].size.should > 1
|
88
88
|
end
|
89
89
|
end
|
data/templates/h/deploy.rb.erb
CHANGED
@@ -51,11 +51,7 @@ set :use_sudo, false
|
|
51
51
|
|
52
52
|
# set the location where to deploy the new project
|
53
53
|
|
54
|
-
|
55
|
-
set :deploy_to, "/home/#{user}/#{application}"
|
56
|
-
<% else %>
|
57
|
-
set :deploy_to, "/var/www/#{user}"
|
58
|
-
<% end %>
|
54
|
+
set :deploy_to, "<%= app["deploy_to"] %>"
|
59
55
|
|
60
56
|
# live
|
61
57
|
role :app, "<%= app["h"]%>"
|
@@ -84,12 +80,7 @@ namespace :railshoster do
|
|
84
80
|
desc "Show the url of your app."
|
85
81
|
task :appurl do
|
86
82
|
puts "\nThe default RailsHoster.com URL of your app is:"
|
87
|
-
|
88
|
-
<% if app["t"].eql?("h") then %>
|
89
|
-
puts "\nhttp://#{user}-<%= app["aid"] %>.<%= app["h"]%>"
|
90
|
-
<% else %>
|
91
|
-
puts "\nhttp://#{user}.<%= app["h"]%>"
|
92
|
-
<% end %>
|
83
|
+
puts "\n<%= app["app_url"] %>"
|
93
84
|
puts "\n"
|
94
85
|
end
|
95
86
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railshoster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Julian Fischer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- CHANGELOG.textile
|
191
191
|
- CONTRIB.txt
|
192
192
|
- Gemfile
|
193
|
+
- Gemfile.lock
|
193
194
|
- LICENSE
|
194
195
|
- README.textile
|
195
196
|
- ROADMAP.textile
|
@@ -206,19 +207,31 @@ files:
|
|
206
207
|
- lib/railshoster/command.rb
|
207
208
|
- lib/railshoster/deploy_command.rb
|
208
209
|
- lib/railshoster/error.rb
|
210
|
+
- lib/railshoster/init_capistrano_helpers.rb
|
209
211
|
- lib/railshoster/init_command.rb
|
212
|
+
- lib/railshoster/init_database_helpers.rb
|
213
|
+
- lib/railshoster/init_gem_helpers.rb
|
214
|
+
- lib/railshoster/init_ssh_helpers.rb
|
215
|
+
- lib/railshoster/init_validation_helpers.rb
|
210
216
|
- lib/railshoster/invalid_public_ssh_key_error.rb
|
211
217
|
- lib/railshoster/possibly_not_a_git_repo_error.rb
|
212
218
|
- lib/railshoster/unsupported_application_type_error.rb
|
213
219
|
- lib/railshoster/utilities.rb
|
214
220
|
- lib/railshoster/version.rb
|
215
221
|
- railshoster.gemspec
|
216
|
-
- spec
|
217
|
-
- spec/
|
218
|
-
- spec/
|
219
|
-
- spec/
|
222
|
+
- spec/.DS_Store
|
223
|
+
- spec/fakefs/bundler/mysql/Gemfile.lock
|
224
|
+
- spec/fakefs/bundler/mysql2/Gemfile.lock
|
225
|
+
- spec/fakefs/bundler/pg/Gemfile.lock
|
226
|
+
- spec/fakefs/database_yml/database.mysql.yml
|
227
|
+
- spec/fakefs/fake_dot_ssh/1_valid_key/bullshit.pub
|
228
|
+
- spec/fakefs/fake_dot_ssh/1_valid_key/id_rsa.pub
|
229
|
+
- spec/fakefs/fake_dot_ssh/2_valid_keys/github_rsa.pub
|
230
|
+
- spec/fakefs/fake_dot_ssh/2_valid_keys/id_dsa.pub
|
220
231
|
- spec/lib/railshoster/command_spec.rb
|
221
232
|
- spec/lib/railshoster/init_command_spec.rb
|
233
|
+
- spec/lib/railshoster/init_database_helpers_spec.rb
|
234
|
+
- spec/lib/railshoster/init_gem_helpers_spec.rb
|
222
235
|
- spec/lib/railshoster/utilities_spec.rb
|
223
236
|
- spec/spec_helper.rb
|
224
237
|
- templates/h/deploy.rb.erb
|
@@ -256,11 +269,17 @@ signing_key:
|
|
256
269
|
specification_version: 3
|
257
270
|
summary: RailsHoster Applicatoin Deployment Suite
|
258
271
|
test_files:
|
259
|
-
- spec/
|
260
|
-
- spec/
|
261
|
-
- spec/
|
262
|
-
- spec/
|
272
|
+
- spec/fakefs/bundler/mysql/Gemfile.lock
|
273
|
+
- spec/fakefs/bundler/mysql2/Gemfile.lock
|
274
|
+
- spec/fakefs/bundler/pg/Gemfile.lock
|
275
|
+
- spec/fakefs/database_yml/database.mysql.yml
|
276
|
+
- spec/fakefs/fake_dot_ssh/1_valid_key/bullshit.pub
|
277
|
+
- spec/fakefs/fake_dot_ssh/1_valid_key/id_rsa.pub
|
278
|
+
- spec/fakefs/fake_dot_ssh/2_valid_keys/github_rsa.pub
|
279
|
+
- spec/fakefs/fake_dot_ssh/2_valid_keys/id_dsa.pub
|
263
280
|
- spec/lib/railshoster/command_spec.rb
|
264
281
|
- spec/lib/railshoster/init_command_spec.rb
|
282
|
+
- spec/lib/railshoster/init_database_helpers_spec.rb
|
283
|
+
- spec/lib/railshoster/init_gem_helpers_spec.rb
|
265
284
|
- spec/lib/railshoster/utilities_spec.rb
|
266
285
|
- spec/spec_helper.rb
|