Skip to content
Browse files

added capistrano into the mix

  • Loading branch information...
1 parent f8c7b5b commit 8e9c40d2e134f98f3db8efaeddffe6c8d38e53dd @pacifists committed Nov 6, 2011
Showing with 158 additions and 1 deletion.
  1. +4 −0 Capfile
  2. +4 −1 Gemfile
  3. +16 −0 Gemfile.lock
  4. +40 −0 config/deploy.rb
  5. +94 −0 config/deploy/production.rb
View
4 Capfile
@@ -0,0 +1,4 @@
+load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+
+load 'config/deploy' # remove this line to skip loading any of the default tasks
View
5 Gemfile
@@ -8,4 +8,7 @@ gem 'kaminari'
gem 'acts_as_list_mongoid'
-gem 'unicorn', :group => 'development'
+gem 'unicorn', :group => 'development'
+
+gem 'capistrano'
+gem 'capistrano-ext'
View
16 Gemfile.lock
@@ -91,6 +91,14 @@ GEM
orm_adapter (~> 0.0.3)
rest-client (>= 1.6.1)
cancan (1.6.7)
+ capistrano (2.9.0)
+ highline
+ net-scp (>= 1.0.0)
+ net-sftp (>= 2.0.0)
+ net-ssh (>= 2.0.14)
+ net-ssh-gateway (>= 1.1.0)
+ capistrano-ext (1.2.1)
+ capistrano (>= 1.0.0)
carrierwave (0.5.6)
activesupport (~> 3.0)
cells (3.7.0)
@@ -189,7 +197,13 @@ GEM
mongoid (>= 2.0.1)
mongoid_adjust (>= 0.1.1)
mongoid_adjust (>= 0.1.1)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-sftp (2.0.5)
+ net-ssh (>= 2.0.9)
net-ssh (2.2.1)
+ net-ssh-gateway (1.1.0)
+ net-ssh (>= 1.99.1)
nokogiri (1.5.0)
open4 (1.2.0)
orm_adapter (0.0.5)
@@ -253,6 +267,8 @@ PLATFORMS
DEPENDENCIES
acts_as_list_mongoid
+ capistrano
+ capistrano-ext
kaminari
locomotive_cms!
rails (= 3.0.10)
View
40 config/deploy.rb
@@ -0,0 +1,40 @@
+set :stages, %w(testing production)
+set :default_stage, "production"
+#require File.expand_path("#{File.dirname(__FILE__)}/../vendor/gems/capistrano-ext-1.2.1/lib/capistrano/ext/multistage")
+require "capistrano/ext/multistage"
+#require 'config/sitemap/sitemap_tasks'
+#require "bundler/capistrano"
+
+namespace :db do
+ desc 'Dumps the production database to db/production_data.sql on the remote server'
+ task :remote_db_dump, :roles => :db, :only => { :primary => true } do
+ run "cd #{deploy_to}/#{current_dir} && " +
+ "rake RAILS_ENV=#{rails_env} db:database_dump --trace"
+ end
+
+ desc 'Downloads db/production_data.sql from the remote production environment to your local machine'
+ task :remote_db_download, :roles => :db, :only => { :primary => true } do
+ execute_on_servers(options) do |servers|
+ self.sessions[servers.first].sftp.connect do |tsftp|
+ tsftp.download!("#{deploy_to}/#{current_dir}/db/production_data.sql", "db/production_data.sql")
+ end
+ end
+ end
+
+ desc 'Cleans up data dump file'
+ task :remote_db_cleanup, :roles => :db, :only => { :primary => true } do
+ execute_on_servers(options) do |servers|
+ self.sessions[servers.first].sftp.connect do |tsftp|
+ tsftp.remove! "#{deploy_to}/#{current_dir}/db/production_data.sql"
+ end
+ end
+ end
+
+ desc 'Dumps, downloads and then cleans up the production data dump'
+ task :remote_db_runner do
+ remote_db_dump
+ remote_db_download
+ remote_db_cleanup
+ end
+end
+require 'bundler/capistrano'
View
94 config/deploy/production.rb
@@ -0,0 +1,94 @@
+#############################################################
+# Application
+#############################################################
+
+set :application, "myliufoto"
+set :deploy_to, "/home/myliufoto/www/myliufoto.lt"
+
+#############################################################
+# Settings
+#############################################################
+
+default_run_options[:pty] = true
+ssh_options[:forward_agent] = true
+ssh_options[:port] = 30820
+set :use_sudo, false
+set :scm_verbose, true
+set :rails_env, "production"
+set :keep_releases, 10
+
+#############################################################
+# Servers
+#############################################################
+
+set :user, "myliufoto"
+set :domain, "server.zinom.lt"
+server domain, :app, :web
+role :db, domain, :primary => true
+
+#############################################################
+# Git
+#############################################################
+set :shell, "/bin/bash"
+set :scm, :git
+set :branch, "master"
+set :scm_user, 'git'
+#set :git_enable_submodules, 1
+#set :scm_passphrase, "PASSWORD"
+# set :repository, "git@server.zinom.lt:myliufoto.git"
+set :repository, "git@github.com:pacifists/myliufoto.lt.git"
+set :deploy_via, :copy
+set :copy_cache, true
+set :copy_exclude, [".git"]
+
+#############################################################
+# Passenger
+#############################################################
+
+namespace :deploy do
+ desc "This is run after each deployment"
+ task :after_update_code do
+ # db_config = <<-EOF
+ # production:
+ # adapter: mysql2
+ # encoding: utf8
+ # reconnect: false
+ # database: myliufoto
+ # pool: 5
+ # username: myliufoto_user
+ # password: SesiosFotoMyletojos
+ # EOF
+
+ # put db_config, "#{release_path}/config/database.yml"
+
+ end
+
+ # Restart passenger on deploy
+ desc "Restarting mod_rails with restart.txt"
+ task :restart, :roles => :app, :except => { :no_release => true } do
+ run "ln -s #{shared_path}/bundle #{current_path}/vendor/bundle"
+ run "touch #{current_path}/tmp/restart.txt"
+ end
+
+ [:start, :stop].each do |t|
+ desc "#{t} task is a no-op with mod_rails"
+ task t, :roles => :app do ; end
+ end
+
+ namespace :web do
+ task :disable do
+ require 'rubygems'
+ require 'erb'
+ file = File.open("./app/views/layouts/maintenance.html.erb", 'r')
+ engine = ERB.new(file.read)
+ reason = ENV['REASON']
+ deadline = ENV['UNTIL']
+ maintenance = engine.result(binding)
+ put maintenance, "#{shared_path}/system/maintenance.html", :mode => 0644
+ end
+
+ # task :enable do
+ # delete "#{shared_path}/system/maintenance.html"
+ # end
+ end
+end

0 comments on commit 8e9c40d

Please sign in to comment.
Something went wrong with that request. Please try again.