uberspacify 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uberspacify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jan Schulz-Hofen, LAUNCH/CO GmbH
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Uberspacify
2
+
3
+ Uberspacify helps you deploy a Ruby on Rails app on Uberspace, a popular German shared hosting provider.
4
+
5
+ All the magic is built into a couple nice Capistrano scripts. Uberspacify will create an environment for your app, install Passenger, run it in standalone mode, monitor it using Daemontools, and configure Apache to reverse-proxy to it. Uberspacify will also find out your Uberspace MySQL password and create databases as well as a `database.yml`
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'uberspacify'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ This should install uberspacify as well as Capistrano and some other gems for you.
20
+
21
+ Now execute the following to get a `Capfile` and a `deploy.rb`:
22
+
23
+ $ capify .
24
+
25
+ If you are using Rails' asset pipeline, add this line to your `Capfile`:
26
+
27
+ ```ruby
28
+ load 'deploy/assets'
29
+ ```
30
+
31
+ Now, you need to add a few lines regarding your Uberspace to your `config/deploy.rb`. It is safe to copy, paste & adapt the following:
32
+
33
+ ```ruby
34
+ require 'uberspacify/recipes'
35
+
36
+ # the Uberspace server you are on
37
+ server 'phoenix.uberspace.de', :web, :app, :db, :primary => true
38
+
39
+ # your Uberspace username
40
+ set :user, 'ubernaut'
41
+
42
+ # a name for your app, [a-z0-9] should be safe, will be used for your gemset,
43
+ # databases, directories, etc.
44
+ set :application, 'dummyapp'
45
+
46
+ # the repo where your code is hosted
47
+ set :scm, :git
48
+ set :repository, 'https://github.com/yeah/dummyapp.git'
49
+
50
+ # optional stuff from here
51
+
52
+ # By default, your app will be available in the root of your Uberspace. If you
53
+ # have your own domain set up, you can configure it here
54
+ # set :domain, 'www.dummyapp.com'
55
+
56
+ # By default, uberspacify will generate a random port number for Passenger to
57
+ # listen on. This is fine, since only Apache will use it. Your app will always
58
+ # be available on port 80 and 443 from the outside. However, if you'd like to
59
+ # set this yourself, go ahead.
60
+ # set :passenger_port, 55555
61
+ ```
62
+
63
+ Done. That was the hard part. It's easy from here on out. Next, add all new/modified files to version control. If you use Git, the following will do:
64
+
65
+ $ git add . ; git commit -m 'uberspacify my app!' ; git push
66
+
67
+ And here comes the fun part - get it all up and running on Uberspace! These commands should teleport your app to the Uberspace (execute them one by one and keep an eye on the output):
68
+
69
+ $ bundle exec cap deploy:setup
70
+ $ bundle exec cap deploy:migrations
71
+
72
+ (Be sure to have your public key set up on your Uberspace account already.)
73
+
74
+ This will do a whole lot of things, so don't get nervous, it takes some time. After Capistrano is done, **please wait some more**. When Passenger starts for the first time, it will actually compile an nginx server. Don't worry though, subsequent starts will be fast.
75
+
76
+ Now, **after some time**, your app should be available on your Uberspace URI.
77
+
78
+ Should you ever need to stop/start/restart your app, you can do so using Capistrano's standard:
79
+
80
+ $ bundle exec cap deploy:{stop|start|restart}
81
+
82
+ That's it folks. Have fun.
83
+
84
+
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,139 @@
1
+ require 'capistrano_colors'
2
+ require 'rvm/capistrano'
3
+ require 'bundler/capistrano'
4
+
5
+ def abort_red(msg)
6
+ abort " * \e[#{1};31mERROR: #{msg}\e[0m"
7
+ end
8
+
9
+ Capistrano::Configuration.instance.load do
10
+
11
+ # required variables
12
+ _cset(:user) { abort_red "Please configure your Uberspace user in config/deploy.rb using 'set :user, <username>'" }
13
+ _cset(:repository) { abort_red "Please configure your code repository config/deploy.rb using 'set :repository, <repo uri>'" }
14
+
15
+ # optional variables
16
+ _cset(:domain) { nil }
17
+ _cset(:passenger_port) { rand(61000-32768+1)+32768 } # random ephemeral port
18
+
19
+ _cset(:deploy_via) { :remote_cache }
20
+ _cset(:git_enable_submodules) { 1 }
21
+ _cset(:branch) { 'master' }
22
+
23
+ _cset(:keep_releases) { 3 }
24
+
25
+ # uberspace presets
26
+ set(:deploy_to) { "/var/www/virtual/#{user}/rails/#{application}" }
27
+ set(:home) { "/home/#{user}" }
28
+ set(:use_sudo) { false }
29
+ set(:rvm_type) { :user }
30
+ set(:rvm_install_ruby) { :install }
31
+ set(:rvm_ruby_string) { "ree@rails-#{application}" }
32
+
33
+ ssh_options[:forward_agent] = true
34
+ default_run_options[:pty] = true
35
+
36
+ # callbacks
37
+ before 'deploy:setup', 'rvm:install_rvm'
38
+ before 'deploy:setup', 'rvm:install_ruby'
39
+ after 'deploy:setup', 'uberspace:setup_svscan'
40
+ after 'deploy:setup', 'daemontools:setup_daemon'
41
+ after 'deploy:setup', 'apache:setup_reverse_proxy'
42
+ after 'deploy:setup', 'mysql:setup_database_and_config'
43
+ after 'deploy:update_code', 'deploy:symlink_shared'
44
+ after 'deploy', 'deploy:cleanup'
45
+
46
+ # custom recipes
47
+ namespace :uberspace do
48
+ task :setup_svscan do
49
+ run 'uberspace-setup-svscan ; echo 0'
50
+ end
51
+ end
52
+
53
+ namespace :daemontools do
54
+ task :setup_daemon do
55
+ daemon_script = <<-EOF
56
+ #!/bin/bash
57
+ export HOME=#{fetch :home}
58
+ source $HOME/.bash_profile
59
+ cd #{fetch :deploy_to}/current
60
+ rvm use #{fetch :rvm_ruby_string}
61
+ exec bundle exec passenger start -p #{fetch :passenger_port} -e production 2>&1
62
+ EOF
63
+
64
+ log_script = <<-EOF
65
+ #!/bin/sh
66
+ exec multilog t ./main
67
+ EOF
68
+
69
+ run "mkdir -p #{fetch :home}/etc/run-rails-#{fetch :application}"
70
+ run "mkdir -p #{fetch :home}/etc/run-rails-#{fetch :application}/log"
71
+ put daemon_script, "#{fetch :home}/etc/run-rails-#{fetch :application}/run"
72
+ put log_script, "#{fetch :home}/etc/run-rails-#{fetch :application}/log/run"
73
+ run "chmod +x #{fetch :home}/etc/run-rails-#{fetch :application}/run"
74
+ run "chmod +x #{fetch :home}/etc/run-rails-#{fetch :application}/log/run"
75
+ run "ln -nfs #{fetch :home}/etc/run-rails-#{fetch :application} #{fetch :home}/service/rails-#{fetch :application}"
76
+
77
+ end
78
+ end
79
+
80
+ namespace :apache do
81
+ task :setup_reverse_proxy do
82
+ htaccess = <<-EOF
83
+ RewriteEngine On
84
+ RewriteRule ^(.*)$ http://localhost:#{fetch :passenger_port}/$1 [P]
85
+ EOF
86
+ path = fetch(:domain) ? "/var/www/virtual/#{fetch :user}/#{fetch :domain}" : "#{fetch :home}/html"
87
+ run "mkdir -p #{path}"
88
+ put htaccess, "#{path}/.htaccess"
89
+ end
90
+ end
91
+
92
+ namespace :mysql do
93
+ task :setup_database_and_config do
94
+ my_cnf = capture('cat ~/.my.cnf')
95
+ config = {}
96
+ %w(development production test).each do |env|
97
+
98
+ config[env] = {
99
+ 'adapter' => 'mysql2',
100
+ 'encoding' => 'utf8',
101
+ 'database' => "#{fetch :user}_rails_#{fetch :application}_#{env}",
102
+ 'host' => 'localhost'
103
+ }
104
+
105
+ my_cnf.match(/^user=(\w+)/)
106
+ config[env]['username'] = $1
107
+
108
+ my_cnf.match(/^password=(\w+)/)
109
+ config[env]['password'] = $1
110
+
111
+ my_cnf.match(/^port=(\d+)/)
112
+ config[env]['port'] = $1.to_i
113
+
114
+ run "mysql -e 'CREATE DATABASE IF NOT EXISTS #{config[env]['database']} CHARACTER SET utf8 COLLATE utf8_general_ci;'"
115
+ end
116
+
117
+ run "mkdir -p #{fetch :shared_path}/config"
118
+ put config.to_yaml, "#{fetch :shared_path}/config/database.yml"
119
+
120
+ end
121
+ end
122
+
123
+ namespace :deploy do
124
+ task :start do
125
+ run "svc -u #{fetch :home}/service/rails-#{fetch :application}"
126
+ end
127
+ task :stop do
128
+ run "svc -d #{fetch :home}/service/rails-#{fetch :application}"
129
+ end
130
+ task :restart do
131
+ run "svc -du #{fetch :home}/service/rails-#{fetch :application}"
132
+ end
133
+
134
+ task :symlink_shared do
135
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,3 @@
1
+ module Uberspacify
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "uberspacify/version"
2
+
3
+ module Uberspacify
4
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/uberspacify/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jan Schulz-Hofen"]
6
+ gem.email = ["jan@launchco.com"]
7
+ gem.description = %q{Deploy Rails apps on Uberspace}
8
+ gem.summary = %q{Uberspacify helps you deploy a Ruby on Rails app on Uberspace, a popular German shared hosting provider.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "uberspacify"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Uberspacify::VERSION
17
+
18
+ # dependencies for capistrano
19
+ gem.add_dependency 'capistrano', '>=2.12.0'
20
+ gem.add_dependency 'capistrano_colors', '>=0.5.5'
21
+ gem.add_dependency 'rvm-capistrano', '>=1.2.5'
22
+
23
+ # dependencies for passenger on Uberspace
24
+ gem.add_dependency 'passenger', '>=3.0.15'
25
+ gem.add_dependency 'rack', '>=1.4.1'
26
+ gem.add_dependency 'daemon_controller', '>=1.0.0'
27
+
28
+ # dependency for mysql on Uberspace
29
+ gem.add_dependency 'mysql2', '>=0.3.11'
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uberspacify
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - Jan Schulz-Hofen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-07 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: 63
29
+ segments:
30
+ - 2
31
+ - 12
32
+ - 0
33
+ version: 2.12.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: capistrano_colors
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 1
45
+ segments:
46
+ - 0
47
+ - 5
48
+ - 5
49
+ version: 0.5.5
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rvm-capistrano
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 21
61
+ segments:
62
+ - 1
63
+ - 2
64
+ - 5
65
+ version: 1.2.5
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: passenger
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 25
77
+ segments:
78
+ - 3
79
+ - 0
80
+ - 15
81
+ version: 3.0.15
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: rack
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 5
93
+ segments:
94
+ - 1
95
+ - 4
96
+ - 1
97
+ version: 1.4.1
98
+ type: :runtime
99
+ version_requirements: *id005
100
+ - !ruby/object:Gem::Dependency
101
+ name: daemon_controller
102
+ prerelease: false
103
+ requirement: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 23
109
+ segments:
110
+ - 1
111
+ - 0
112
+ - 0
113
+ version: 1.0.0
114
+ type: :runtime
115
+ version_requirements: *id006
116
+ - !ruby/object:Gem::Dependency
117
+ name: mysql2
118
+ prerelease: false
119
+ requirement: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 5
125
+ segments:
126
+ - 0
127
+ - 3
128
+ - 11
129
+ version: 0.3.11
130
+ type: :runtime
131
+ version_requirements: *id007
132
+ description: Deploy Rails apps on Uberspace
133
+ email:
134
+ - jan@launchco.com
135
+ executables: []
136
+
137
+ extensions: []
138
+
139
+ extra_rdoc_files: []
140
+
141
+ files:
142
+ - .gitignore
143
+ - Gemfile
144
+ - LICENSE
145
+ - README.md
146
+ - Rakefile
147
+ - lib/uberspacify.rb
148
+ - lib/uberspacify/recipes.rb
149
+ - lib/uberspacify/version.rb
150
+ - uberspacify.gemspec
151
+ homepage: ""
152
+ licenses: []
153
+
154
+ post_install_message:
155
+ rdoc_options: []
156
+
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.24
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: Uberspacify helps you deploy a Ruby on Rails app on Uberspace, a popular German shared hosting provider.
184
+ test_files: []
185
+