class Vpsb::Resources::DeployRb
Public Instance Methods
call(data)
click to toggle source
# File lib/vpsb/resources/deploy_rb.rb, line 6 def call(data) template(data) end
Private Instance Methods
template(data)
click to toggle source
# File lib/vpsb/resources/deploy_rb.rb, line 12 def template(data) application = '#{application}' deploy_to = '#{deploy_to}' command = '#{command}' <<-EOF # config valid only for Capistrano 3.1 # set :rsync_options, %w[--recursive --delete --delete-excluded --exclude .git*] lock '3.1.0' application = 'rails' set :user, 'deploy' set :application, application set :repo_url, "." # set :repository, '.' set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master" set :deploy_to, "/opt/www/#{application}" set :scm, :rsync set :rsync_cache, false set :rsync_stage, "tmp/repository" # set :rsync_cache, "" # set :deploy_via, :copy set :use_sudo, false stage = :production # Default branch is :master # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } # Default value for :scm is :git # set :scm, :git # Default value for :format is :pretty # set :format, :pretty # Default value for :log_level is :debug set :log_level, :debug # Default value for :pty is false # set :pty, true set :default_shell, "/bin/bash -l" # Default value for :linked_files is [] # set :linked_files, %w{config/database.yml} # Default value for linked_dirs is [] set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} # Default value for default_env is {} # set :default_env, { path: "/opt/ruby/bin:$PATH" } # Default value for keep_releases is 5 set :keep_releases, 5 set :rvm_ruby_version, '#{data.get(:ruby_version)}' set :rvm_type, :user set :rvm_ruby_string, "#{data.get(:ruby_version)}@#{application}" namespace :unicorn do %w{start stop restart reload upgrade}.each do |command| desc "#{command} unicorn" task command.to_sym do on roles(:app), pty: true, shell: true do within shared_path do execute :sudo, :service, "unicorn_#{application}", command end end end end end namespace :nginx do %w{restart reload}.each do |command| desc "#{command} nginx" task command.to_sym do on roles(:app), pty: true, shell: true do within shared_path do execute :sudo, :service, :nginx, command end end end end end namespace :db do desc "Create database" task :create do on roles(:db) do within release_path do execute :rake, "db:create" end end end end namespace :es do %w{ create_indexes delete_indexes recreate_indexes insert_dicts_plants_data insert_dicts_precinct_data insert_dicts_agri_pack_data }.each do |command| desc "Elasticsearch #{command} task" task command.to_sym do on roles(:app) do within release_path do execute :rake, "es:#{command}" end end end end end namespace :deploy do before 'deploy:migrate', 'db:create' before 'deploy', 'deploy:rsync' task :rsync do on roles(:app), in: :sequence, pty: true, shell: true do `rsync -avz -e ssh "./" deploy@#{data.get(:do_host_ip)}:#{deploy_to}/shared/deploy` end end desc "First deploy setup unicorn and nginx" task :init_env do on roles(:app), in: :sequence, wait: 5, pty: true, shell: true do Rake::Task['unicorn:start'].invoke Rake::Task['nginx:restart'].invoke end end before :production, :warn do info 'Deploying to production, hold tight!' stage = :production end after :finishing, 'deploy:cleanup' desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do Rake::Task['unicorn:upgrade'].invoke # Rake::Task['nginx:restart'].invoke end end after :publishing, :restart end EOF end