require 'rubygems' require 'bundler/setup' require 'capistrano/ext/multistage' set :application, "swarm" set :stages, ["dev", "staging", "production"] set :default_stage, "dev" # no access to Perforce from the DMZ, so we have to file copy from the workspace set :scm, :none set :repository, "." set :deploy_via, :copy set :deploy_to, "/var/www/swarm" # not shared hosting, sudo up set :use_sudo, true set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules", ".p4ignore", "Capfile", "config/deploy.rb", ".vagrant", "Vagrantfile", "config", "manifests", "data", "perforce", "tests", "git-fusion", "collateral", "build", "build.xml", "packaging", "p4-doc", "logs", "Jamrules", "Gemfile", "Gemfile.lock"] set :default_run_options, {:pty => true} # only keep the last four releases on the server set :keep_releases, 4 set :owner, "www-data:www-data" before 'deploy:update', 'swarm:deploy_prep' after 'deploy:setup', 'swarm:setup' after 'deploy:create_symlink', 'swarm:permissions:fix', "swarm:link_data", "swarm:setup_config", "apache:restart" depend :remote, :command, "p4" depend :remote, :command, "wget" # TODO: verify the Apache vhost is setup # swarm specific tasks namespace :swarm do desc '[internal] generate the documentation and Version file' task :deploy_prep do run_locally "ant clean" run_locally "ant deploy -Ddoc.bld.dir='p4-doc/manuals/_build'" run_locally "ant get-version-file" end desc '[internal] we have to clean up the file permissions after setting up the directories' task :setup do run "#{sudo} mkdir -m 770 -p #{shared_path}/data" run "#{sudo} chown -R www-data:www-data #{deploy_to}" end desc '[internal] make sure ownership is correct after updating the files' namespace :permissions do task :fix do run "#{sudo} chown -R www-data:www-data #{latest_release}" end end desc "[internal] add a link to the shared path where we store the config information" task :link_data do run "ln -nfs #{shared_path}/data #{release_path}" end desc "setup the Swarm config file for this installation" task :setup_config do upload "data/#{stage}.config.php", "#{shared_path}/data/#{stage}.config.php" # setup the super password run "cat #{shared_path}/data/spassword | p4 -p #{p4port} -u #{super_user} login -p | grep -v Enter > #{shared_path}/data/ticket.super" # reset password for swarm-user run "p4 -p #{p4port} -P `cat #{shared_path}/data/ticket.super` -u #{super_user} passwd -P `cat #{shared_path}/data/password` #{swarm_user} " # setup swarm-user ticket run "cat #{shared_path}/data/password | p4 -p #{p4port} -u #{swarm_user} login -p | grep -v Enter > #{shared_path}/data/ticket.swarm" run "cat #{shared_path}/data/#{stage}.config.php | sed \"s/ADMIN_TICKET/$(cat #{shared_path}/data/ticket.swarm)/\" > #{shared_path}/data/config.tmp" # then the super ticket run "cat #{shared_path}/data/config.tmp | sed \"s/SUPER_TICKET/$(cat #{shared_path}/data/ticket.super)/\" > #{shared_path}/data/config2.tmp" # put the config file in place run "#{sudo} chown www-data:www-data #{shared_path}/data/config2.tmp" run "mv -f #{shared_path}/data/config2.tmp #{shared_path}/data/config.php" run "rm #{shared_path}/data/ticket.* #{shared_path}/data/#{stage}.config.php #{shared_path}/data/config.tmp" end end # we need to restart Apache to pick up new versions of P4PHP namespace :apache do desc 'restart Apache' task :restart do run "#{sudo} service apache2 restart" end end