railshoster 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
@@ -0,0 +1,8 @@
1
+ h2. 0.0.1
2
+
3
+ * Implementation of init command started.
4
+ * Current status:
5
+ ** Decode and parse credentials - done
6
+ ** Gather Git Repository URL using git gem - done
7
+ * Stil to be done:
8
+ ** Write deploy.rb
data/CONTRIB.txt ADDED
@@ -0,0 +1,13 @@
1
+ Contributing
2
+ ======================
3
+
4
+ To contribute to the RailsHoster project:
5
+
6
+ * Fork railshoster/railshoster
7
+
8
+ * Push your contribution to a branch named after your change
9
+ ie: git push origin master:fixed-whatever
10
+
11
+ * Send me a pull request through GitHub with a description of
12
+ what you are contributing.
13
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Julian Fischer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,11 @@
1
+ h1. RailsHoster Deployment Suite
2
+
3
+ INTRDUCTON TEXT. TO BE DONE.
4
+
5
+ h2. Installation
6
+
7
+ TO BE DONE.
8
+
9
+ h2. Usage
10
+
11
+ TO BE DONE.
data/ROADMAP.markdown ADDED
@@ -0,0 +1,14 @@
1
+ h2. 0.0.1
2
+
3
+ * Prepare a deployment for a RailsHoster shared hosting.
4
+ * Be prepared to at RailsHoster vps deployments later.
5
+
6
+ h2. 1.0.0
7
+
8
+ h2. 2.0.0
9
+
10
+ * RailsHoster VPS Deployments
11
+
12
+ h3. General TODOs
13
+
14
+ * Railshoster::InitCommand - Check wether it is possible to replace "system" call with a pure ruby version possibly by using the capistrano gem directly via ruby.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/railshoster ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ # require 'bundler/setup'
5
+
6
+ gem "json"
7
+ gem "git"
8
+ gem 'erubis'
9
+ gem "gli"
10
+
11
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'railshoster')
12
+ require 'fileutils'
13
+
14
+ require 'gli'
15
+ include GLI
16
+
17
+ version Railshoster::VERSION
18
+
19
+ program_desc "RailsHoster.com Application Deployment Suite"
20
+
21
+ desc 'Create new RailsHoster.com application deployment'
22
+ arg_name 'dir_name'
23
+ long_desc 'This command helps to deploy a Ruby on Rails application to your RailsHoster account using the application token you have received after signing up.'
24
+ command [:init] do |c|
25
+
26
+ c.desc "Use the RailsHoster application_token pass your account credentials."
27
+ c.flag [:a, :apptoken]
28
+
29
+ c.action do |global_options,options,args|
30
+
31
+ raise "Argument 'dir_name' is required for the 'init' command." if args.empty?
32
+ raise "Option '-a' or '--apptoken' is require for the 'init' comannd" unless options[:a]
33
+
34
+ project_git_dir_name = args[0]
35
+
36
+ init_command = RailsHoster::InitCommand.new(project_git_dir_name)
37
+ init_command.run_by_application_token(options[:a])
38
+ end
39
+ end
40
+
41
+ desc "Deploy your application to RailsHoster.com"
42
+ arg_name 'dir_name'
43
+ long_desc "Use this command to deploy your application to RailsHoster.com after you have successfully initialized it using the 'init' command."
44
+ command [:deploy] do |c|
45
+ c.action do |global_options,options,args|
46
+ project_git_dir_name = args[0] || FileUtils.pwd
47
+ RailsHoster::DeployCommand.new(project_git_dir_name).deploy
48
+ end
49
+ end
50
+
51
+ pre do |global,command,options,args|
52
+ # Pre logic here
53
+ # Return true to proceed; false to abourt and not call the
54
+ # chosen command
55
+ true
56
+ end
57
+
58
+ post do |global,command,options,args|
59
+ # Post logic here
60
+ end
61
+
62
+ on_error do |exception|
63
+ puts "\n"
64
+ puts "-" * 50
65
+ puts "Sorry. An Exception has occured. Don't worry I try to explain what happened:"
66
+ puts "-" * 50
67
+ puts "The Exception class is: #{exception.class}"
68
+ puts "The Exception message is:\n"
69
+ puts exception.message
70
+ puts "Here is the backtrace:"
71
+ puts "-" * 50
72
+ puts exception.backtrace
73
+ puts "-" * 50
74
+ puts "If this does not help write to support@railshoster.com."
75
+ puts "Please provide the command you invoked, in which directory as well as information about your runtime environment (Ruby Version, OS, ...)."
76
+
77
+ # Error logic here
78
+ # return false to skip default error handling
79
+ false
80
+ end
81
+
82
+ exit GLI.run(ARGV)
@@ -0,0 +1,18 @@
1
+ require 'erubis'
2
+
3
+ module Railshoster
4
+ module Capistrano
5
+
6
+ # Strategy to generate a capistrano config for a shared hosting
7
+ class H
8
+
9
+ #### Static
10
+
11
+ def self.render_deploy_rb_to_s(application_hash)
12
+ deployrb_template = File.read(File.join(File.dirname(__FILE__), "../../../templates/h/deploy.rb.erb"))
13
+ eruby = Erubis::Eruby.new(deployrb_template)
14
+ eruby.result(:app => application_hash)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module Railshoster
2
+ module Capistrano
3
+ class V
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ module RailsHoster
2
+
3
+ # This action class helps to setup a new rails applicaton
4
+ class Command
5
+
6
+ def initialize(project_dir)
7
+ @project_dir = project_dir
8
+
9
+ begin
10
+ @git = Git.open(project_dir)
11
+ rescue ArgumentError => e
12
+ raise PossiblyNotAGitRepoError.new(e)
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def capfile_exists?
19
+ File.exists?(capfile_path)
20
+ end
21
+
22
+ def capfile_path
23
+ File.join(@project_dir, "Capfile")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module RailsHoster
2
+
3
+ # This action class helps to setup a new rails applicaton
4
+ class DeployCommand < Command
5
+
6
+ def initialize(project_dir)
7
+ super(project_dir)
8
+ end
9
+
10
+ def deploy
11
+ if capfile_exists? then
12
+ system("cap deploy")
13
+ else
14
+ puts "\nDeployment abortet!\nYou haven't initialized your application, yet."
15
+ puts "Please use the 'railshoster init' command as described in your account information mail you have received from RailsHoster.com and try again.\n\n"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,111 @@
1
+ require 'base64'
2
+ require 'json'
3
+ require 'git'
4
+ require 'fileutils'
5
+
6
+ require File.join(File.dirname(__FILE__), '/capistrano/h')
7
+
8
+ module RailsHoster
9
+
10
+ # This action class helps to setup a new rails applicaton
11
+ class InitCommand < Command
12
+
13
+ def initialize(project_dir)
14
+ super(project_dir)
15
+ end
16
+
17
+ def run_by_application_token(application_token)
18
+ decoded_token = decode_token(application_token)
19
+ run_by_application_hash(decoded_token)
20
+ end
21
+
22
+ def run_by_application_hash(application_hash_as_json_string)
23
+ app_hash = parse_application_json_hash(application_hash_as_json_string)
24
+
25
+ git_url = get_git_remote_url_from_git_config
26
+ app_hash["git"] = git_url
27
+
28
+ deployrb_str = ""
29
+
30
+ # Choose the further process depending on the application type by applying a strategy pattern.
31
+ case app_hash["t"].to_sym
32
+ when :h
33
+ # Shared Hosting Deployments
34
+ deployrb_str = Railshoster::Capistrano::H.render_deploy_rb_to_s(app_hash)
35
+ # Later also support VPS Deployments
36
+ # when :v
37
+ else
38
+ raise UnsupportedApplicationTypeError.new
39
+ end
40
+
41
+ write_deploy_rb(deployrb_str)
42
+ capify_project
43
+ success_message
44
+ end
45
+
46
+ protected
47
+
48
+ # Decodoes token to get the JSON hash back.
49
+ # gQkUSMakKRPhm0EIaer => {"key":"value"}
50
+ def decode_token(token)
51
+ Base64.decode64(token)
52
+ end
53
+
54
+ def parse_application_json_hash(app_hash_as_json_string)
55
+ ruby_app_hash = ::JSON.parse(app_hash_as_json_string)
56
+ end
57
+
58
+ def get_git_remote_url_from_git_config
59
+
60
+ #TODO Error management: what if there is not remote url (local repo)?
61
+ @git.config('remote.origin.url')
62
+ end
63
+
64
+ def write_deploy_rb(deployrb_str)
65
+ deployrb_basepath = File.join(@project_dir, "config")
66
+ FileUtils.mkdir_p(deployrb_basepath)
67
+
68
+ deployrb_path = File.join(deployrb_basepath, "deploy.rb")
69
+ backup_file(deployrb_path) if File.exists?(deployrb_path)
70
+
71
+ File.open(deployrb_path, "w+") do |f|
72
+ f << deployrb_str
73
+ end
74
+ end
75
+
76
+ # Creates a backup of a file.
77
+ # If there is already a backup
78
+ #TODO Test
79
+ def backup_file(path)
80
+ backup_path = path + ".bak"
81
+
82
+ if File.exists?(backup_path) then
83
+ # There is already a backup, so we need to backup the backup first.
84
+ backup_file(backup_path)
85
+ end
86
+
87
+ FileUtils.cp(path, backup_path)
88
+ end
89
+
90
+ def capify_project
91
+ puts "\n\tWarning: You are initializing a project with an existing Capfile.\n" if capfile_exists?
92
+ successful = system("capify #{@project_dir}")
93
+ raise CapifyProjectFailedError.new("Couldn't capify project at #{@project_dir}") unless successful
94
+ end
95
+
96
+ def success_message
97
+ puts "Your application has been successfully initialized."
98
+ puts "\n\tYou can now use 'railshoster deploy' to deploy your app.\n\n"
99
+ puts "Alternatively, you can use capistrano commands such as 'cap deploy' and 'cap shell'."
100
+ end
101
+ end
102
+
103
+ class PossiblyNotAGitRepoError < ArgumentError
104
+ end
105
+
106
+ class UnsupportedApplicationTypeError < StandardError
107
+ end
108
+
109
+ class CapifyProjectFailedError < StandardError
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module Railshoster
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), 'railshoster/version')
2
+ require File.join(File.dirname(__FILE__), 'railshoster/command')
3
+ require File.join(File.dirname(__FILE__), 'railshoster/init_command')
4
+ require File.join(File.dirname(__FILE__), 'railshoster/deploy_command')
5
+
6
+ module Railshoster
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "railshoster/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "railshoster"
7
+ s.version = Railshoster::VERSION
8
+ s.authors = ["Julian Fischer"]
9
+ s.email = ["fischer@enterprise-rails.de"]
10
+ s.homepage = "http://www.railshoster.com"
11
+ s.summary = %q{RailsHoster Applicatoin Deployment Suite}
12
+ s.description = %q{Easily deploy your Rails app to RailsHoster.com by using this gem.}
13
+
14
+ s.rubyforge_project = "railshoster"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "capistrano"
22
+ s.add_dependency "capistrano-ext"
23
+ s.add_dependency "gli", ">= 1.2.5"
24
+ s.add_dependency "json"
25
+ s.add_dependency "git"
26
+ s.add_dependency 'erubis'
27
+ end
@@ -0,0 +1,71 @@
1
+ ###############################
2
+ #
3
+ # Capistrano Deployment on shared Webhosting by RailsHoster
4
+ #
5
+ # maintained by support@railshoster.de
6
+ #
7
+ ###############################
8
+
9
+ # BITTE ENTFERNEN SIE DIE FOLGENDE ZEILE WENN SIE BUNDLER NICHT BENUTZEN
10
+ require 'bundler/capistrano'
11
+
12
+
13
+ #### Personal Settings
14
+ ## User and Password
15
+
16
+ # user to login to the target server
17
+ set :user, "<%= app["u"] %>"
18
+
19
+ # password to login to the target server
20
+ set :password, "<%= app["p"] %>"
21
+
22
+ # allow SSH-Key-Forwarding
23
+ set :ssh_options, { :forward_agent => true }
24
+
25
+ ## Application name and repository
26
+
27
+ # application name ( should be rails1 rails2 rails3 ... )
28
+ set :application, "<%= app["a"] %>"
29
+
30
+ # repository location
31
+ set :repository, "<%= app["git"]%>"
32
+
33
+ # :subversionn or :git
34
+ set :scm, :git
35
+ set :scm_verbose, true
36
+
37
+ #### System Settings
38
+ ## General Settings ( don't change them please )
39
+
40
+ # run in pty to allow remote commands via ssh
41
+ default_run_options[:pty] = true
42
+
43
+ # don't use sudo it's not necessary
44
+ set :use_sudo, false
45
+
46
+ # set the location where to deploy the new project
47
+ set :deploy_to, "/home/#{user}/#{application}"
48
+
49
+ # live
50
+ role :app, "<%= app["h"]%>"
51
+ role :web, "<%= app["h"]%>"
52
+ role :db, "<%= app["h"]%>", :primary => true
53
+
54
+
55
+ ############################################
56
+ # Default Tasks by RailsHoster.de
57
+ ############################################
58
+ namespace :deploy do
59
+
60
+ desc "Restarting mod_rails with restart.txt"
61
+ task :restart, :roles => :app, :except => { :no_release => true } do
62
+ run "touch #{current_path}/tmp/restart.txt"
63
+ end
64
+
65
+ desc "Additional Symlinks ( database.yml, etc. )"
66
+ task :additional_symlink, :roles => :app do
67
+ run "ln -s #{shared_path}/config/database.yml #{current_path}/config/database.yml"
68
+ end
69
+
70
+ end
71
+ after "deploy:symlink","deploy:additional_symlink","deploy:migrate"
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railshoster
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Julian Fischer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: capistrano
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: capistrano-ext
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: gli
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 21
57
+ segments:
58
+ - 1
59
+ - 2
60
+ - 5
61
+ version: 1.2.5
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: json
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: git
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :runtime
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: erubis
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :runtime
105
+ version_requirements: *id006
106
+ description: Easily deploy your Rails app to RailsHoster.com by using this gem.
107
+ email:
108
+ - fischer@enterprise-rails.de
109
+ executables:
110
+ - railshoster
111
+ extensions: []
112
+
113
+ extra_rdoc_files: []
114
+
115
+ files:
116
+ - .gitignore
117
+ - CHANGELOG.markdown
118
+ - CONTRIB.txt
119
+ - LICENSE
120
+ - README.markdown
121
+ - ROADMAP.markdown
122
+ - Rakefile
123
+ - bin/railshoster
124
+ - lib/railshoster.rb
125
+ - lib/railshoster/capistrano/h.rb
126
+ - lib/railshoster/capistrano/v.rb
127
+ - lib/railshoster/command.rb
128
+ - lib/railshoster/deploy_command.rb
129
+ - lib/railshoster/init_command.rb
130
+ - lib/railshoster/version.rb
131
+ - railshoster.gemspec
132
+ - templates/h/deploy.rb.erb
133
+ homepage: http://www.railshoster.com
134
+ licenses: []
135
+
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project: railshoster
162
+ rubygems_version: 1.8.6
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: RailsHoster Applicatoin Deployment Suite
166
+ test_files: []
167
+