aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2013-12-11 14:03:50 +0100
committerLuc Donnet2013-12-11 14:03:50 +0100
commit62dac463665bbe9c5255162c0bbb3b6217a067cb (patch)
treefd67f6465f97fc4bb2991331984e4f0adffb38b5
parentadb8844abec23b4ab0382d59397cd2e6a0caaa58 (diff)
downloadchouette-core-62dac463665bbe9c5255162c0bbb3b6217a067cb.tar.bz2
Add capistrano to chouette2
-rw-r--r--Capfile8
-rw-r--r--config/deploy.rb92
-rw-r--r--config/deploy/production.rb5
-rw-r--r--config/deploy/sandbox.rb2
-rw-r--r--config/deploy/staging.rb6
-rw-r--r--config/deploy/unstable.rb1
6 files changed, 114 insertions, 0 deletions
diff --git a/Capfile b/Capfile
new file mode 100644
index 000000000..6f2b99a42
--- /dev/null
+++ b/Capfile
@@ -0,0 +1,8 @@
+load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+require 'bundler/capistrano'
+# Uncomment if you are using Rails' asset pipeline
+load 'deploy/assets'
+
+Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+
+load 'config/deploy' # remove this line to skip loading any of the default tasks \ No newline at end of file
diff --git a/config/deploy.rb b/config/deploy.rb
new file mode 100644
index 000000000..f0ddfded5
--- /dev/null
+++ b/config/deploy.rb
@@ -0,0 +1,92 @@
+require 'capistrano/ext/multistage'
+require './config/boot'
+
+set :stages, %w(sandbox unstable staging production)
+set :application, "chouette2"
+set :user, "ldonnet"
+set :scm, :git
+set :repository, "git@github.com:afimb/chouette2.git"
+set :deploy_to, "/var/www/chouette2"
+set :use_sudo, false
+default_run_options[:pty] = true
+set :group_writable, true
+set :rake, "bundle exec rake"
+set :keep_releases, 4
+set :rails_env, "production" #added for delayed job
+
+after "deploy:update", "deploy:cleanup", "deploy:group_writable"
+after "deploy:update_code", "deploy:symlink_shared", "deploy:chouette_command", "deploy:gems"
+# ugly workaround for bug https://github.com/capistrano/capistrano/issues/81
+before "deploy:assets:precompile", "deploy:symlink_shared"
+after "deploy:restart", "delayed_job:restart"
+after "deploy:migrate", "deploy:migrate_tenants"
+
+# If you want to use command line options, for example to start multiple workers,
+# define a Capistrano variable delayed_job_args:
+#
+# set :delayed_job_args, "-n 2"
+
+namespace :deploy do
+ task :start do ; end
+ task :stop do ; end
+ task :restart, :roles => :app, :except => { :no_release => true } do
+ run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
+ end
+
+ # Prevent errors when chmod isn't allowed by server
+ task :setup, :except => { :no_release => true } do
+ dirs = [deploy_to, releases_path, shared_path]
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
+ run "mkdir -p #{dirs.join(' ')} && (chmod g+w #{dirs.join(' ')} || true)"
+ end
+
+ desc "Runs rake task which migrates database tables for all tenants"
+ task :migrate_tenants do
+ run "cd #{release_path} && rake apartment:migrate"
+ end
+
+ desc "Install gems"
+ task :gems, :roles => :app do
+ run "cd #{release_path} && umask 02 && bundle install --path=#{shared_path}/bundle --without=development:test:cucumber"
+ end
+
+ desc "Symlinks shared configs and folders on each release"
+ task :symlink_shared, :except => { :no_release => true } do
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/"
+ run "ln -nfs #{shared_path}/config/production.rb #{release_path}/config/environments/"
+ end
+
+ desc "Install chouette command"
+ task :chouette_command, :except => { :no_release => true } do
+ run "mkdir -p /var/lib/chouette/imports"
+ run "mkdir -p /var/lib/chouette/imports"
+ run "mkdir -p /var/lib/chouette/validations"
+ run "mkdir -p /usr/local/opt/chouette-command/"
+ end
+
+ desc "Make group writable all deployed files"
+ task :group_writable do
+ run "sudo /usr/local/sbin/cap-fix-permissions /var/www/chouette2"
+ end
+
+ # desc "Generate jekyll static sites"
+ # task :jekyll, :except => { :no_release => true } do
+ # run "cd #{release_path} && jekyll --auto doc/functional public/help"
+ # end
+
+ desc "tail log files"
+ task :tail, :roles => :app do
+ #run "tail -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
+ run "tail -f /var/log/syslog" do |channel, stream, data|
+ puts "#{channel[:host]}: #{data}"
+ break if stream == :err
+ end
+ end
+
+end
+
+namespace :delayed_job do
+ task :restart do
+ run "sudo /etc/init.d/chouette2 restart"
+ end
+end
diff --git a/config/deploy/production.rb b/config/deploy/production.rb
new file mode 100644
index 000000000..43a1351cb
--- /dev/null
+++ b/config/deploy/production.rb
@@ -0,0 +1,5 @@
+server "chouette.cityway.fr", :app, :web, :db, :primary => true
+set :copy_exclude, ".git/*"
+set :branch, "V2_1_0"
+ssh_options[:forward_agent] = true
+ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa")]
diff --git a/config/deploy/sandbox.rb b/config/deploy/sandbox.rb
new file mode 100644
index 000000000..f9e1354d6
--- /dev/null
+++ b/config/deploy/sandbox.rb
@@ -0,0 +1,2 @@
+server "sandbox", :app, :web, :db, :primary => true
+set :deploy_via, :remote_cache
diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb
new file mode 100644
index 000000000..41cedd594
--- /dev/null
+++ b/config/deploy/staging.rb
@@ -0,0 +1,6 @@
+server "chouette-int.aix.cityway.fr", :app, :web, :db, :primary => true
+set :deploy_via, :copy
+set :copy_cache, true
+set :copy_via, :scp
+set :copy_exclude, ".git/*"
+set :branch, "V2_1_0"
diff --git a/config/deploy/unstable.rb b/config/deploy/unstable.rb
new file mode 100644
index 000000000..1eecaf323
--- /dev/null
+++ b/config/deploy/unstable.rb
@@ -0,0 +1 @@
+server "chouette-int.cityway.fr", :app, :web, :db, :primary => true