Skip to content

Commit

Permalink
Initial commit. Works as is, needs polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schulz-Hofen committed Aug 5, 2012
0 parents commit 6deedd7
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in uberspacify.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2012 Jan Schulz-Hofen, LAUNCH/CO GmbH

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
@@ -0,0 +1,29 @@
# Uberspacify

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'uberspacify'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uberspacify

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
4 changes: 4 additions & 0 deletions lib/uberspacify.rb
@@ -0,0 +1,4 @@
require "uberspacify/version"

module Uberspacify
end
108 changes: 108 additions & 0 deletions lib/uberspacify/recipes.rb
@@ -0,0 +1,108 @@
require 'capistrano_colors'
require 'rvm/capistrano'
require 'bundler/capistrano'

def abort_red(msg)
abort " * \e[#{1};31mERROR: #{msg}\e[0m"
end

Capistrano::Configuration.instance.load do

# required variables
_cset(:user) { abort_red "Please configure your Uberspace user in config/deploy.rb using 'set :user, <username>'" }
_cset(:repository) { abort_red "Please configure your code repository config/deploy.rb using 'set :repository, <repo uri>'" }

# optional variables
_cset(:domain) { nil }
_cset(:passenger_port) { rand(61000-32768+1)+32768 } # random ephemeral port

_cset(:scm) { :git }
_cset(:deploy_via) { :remote_cache }
_cset(:git_enable_submodules) { 1 }
_cset(:branch) { 'master' }

_cset(:keep_releases) { 3 }

# uberspace presets
set(:deploy_to) { "/var/www/virtual/#{user}/rails/#{application}" }
set(:home) { "/home/#{user}" }
set(:use_sudo) { false }
set(:rvm_type) { :user }
set(:rvm_install_ruby) { :install }
set(:rvm_ruby_string) { "ree@rails-#{application}" }

ssh_options[:forward_agent] = true
default_run_options[:pty] = true

# callbacks
before 'deploy:setup', 'rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'
before 'deploy:setup', 'uberspace:setup_svscan'
before 'deploy:setup', 'daemontools:setup_daemon'
before 'deploy:setup', 'apache:setup_reverse_proxy'
after 'deploy', 'deploy:cleanup'

# custom recipes
namespace :uberspace do
task :setup_svscan do
run 'uberspace-setup-svscan ; echo 0'
end
end

namespace :daemontools do
task :setup_daemon do
daemon_script = <<-EOF
#!/bin/bash
export HOME=#{fetch :home}
source $HOME/.bash_profile
cd #{fetch :deploy_to}/current
rvm use #{fetch :rvm_ruby_string}
exec bundle exec passenger start -p #{fetch :passenger_port} -e production 2>&1
EOF

log_script = <<-EOF
#!/bin/sh
exec multilog t ./main
EOF

run "mkdir -p #{fetch :home}/etc/run-rails-#{fetch :application}"
run "mkdir -p #{fetch :home}/etc/run-rails-#{fetch :application}/log"
put daemon_script, "#{fetch :home}/etc/run-rails-#{fetch :application}/run"
put log_script, "#{fetch :home}/etc/run-rails-#{fetch :application}/log/run"
run "chmod +x #{fetch :home}/etc/run-rails-#{fetch :application}/run"
run "chmod +x #{fetch :home}/etc/run-rails-#{fetch :application}/log/run"
run "ln -nfs #{fetch :home}/etc/run-rails-#{fetch :application} #{fetch :home}/service/rails-#{fetch :application}"

end
end

namespace :apache do
task :setup_reverse_proxy do
htaccess = <<-EOF
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:#{fetch :passenger_port}/$1 [P]
EOF
path = fetch(:domain) ? "/var/www/virtual/#{fetch :user}/#{fetch :domain}" : "#{fetch :home}/html"
run "mkdir -p #{path}"
put htaccess, "#{path}/.htaccess"
end
end

namespace :deploy do
task :start do
run "svc -u #{fetch :home}/service/rails-#{fetch :application}"
end
task :stop do
run "svc -d #{fetch :home}/service/rails-#{fetch :application}"
end
task :restart do
run "svc -du #{fetch :home}/service/rails-#{fetch :application}"
end

# desc 'Symlink shared configs and folders on each release.'
# task :symlink_shared do
# run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
# end
end

end
3 changes: 3 additions & 0 deletions lib/uberspacify/version.rb
@@ -0,0 +1,3 @@
module Uberspacify
VERSION = "0.0.1"
end
28 changes: 28 additions & 0 deletions uberspacify.gemspec
@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/uberspacify/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Jan Schulz-Hofen"]
gem.email = ["jan@launchco.com"]
gem.description = %q{Deploy Rails apps on Uberspace}
gem.summary = %q{Deploy Rails apps on Uberspace}
gem.homepage = ""

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "uberspacify"
gem.require_paths = ["lib"]
gem.version = Uberspacify::VERSION

# dependencies for capistrano
gem.add_dependency 'capistrano', '>=2.12.0'
gem.add_dependency 'capistrano_colors', '>=0.5.5'
gem.add_dependency 'rvm-capistrano', '>=1.2.5'

# dependencies for passenger on Uberspace
gem.add_dependency 'passenger' , '>=3.0.15'
gem.add_dependency 'rack' , '>=1.4.1'
gem.add_dependency 'daemon_controller', '>=1.0.0'

end

0 comments on commit 6deedd7

Please sign in to comment.