mratorr
9/20/2017 - 3:11 AM

deploy.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'

set :user, 'root'
set :domain, '111.111.111.111'
set :deploy_to, '/home/rails/project-rails'
set :repository, 'repository-git'
set :shared_paths, ['config/database.yml', 'log', 'tmp', 'public/system']
set :keep_releases, 2
set :term_mode, nil
set :forward_agent, true
set :port, '22'
set :branch, 'master'
set :rails_env, 'production'

set :rvm_use_path, '/usr/local/rvm/scripts/rvm'

task :environment do
  invoke :'rvm:use', 'ruby-2.4.0'
end

desc "Creates shared directories, set permissions, touches database.yml"
task :setup do
    command %{mkdir -p "#{fetch(:deploy_to)}/shared/public/assets"}
    command %{mkdir -p "#{fetch(:deploy_to)}/shared/log"}
    command %{mkdir -p "#{fetch(:deploy_to)}/shared/tmp/pids"}
    command %{chmod g+rx,u+rwx "#{fetch(:deploy_to)}/shared/log"}

    command %{mkdir -p "#{fetch(:deploy_to)}/shared/config"}
    command %{chmod g+rx,u+rwx "#{fetch(:deploy_to)}/shared/config"}

    command %{touch "#{fetch(:deploy_to)}/shared/config/database.yml"}
    comment "Be sure to edit 'shared/config/database.yml'."
end

desc "Deploys the current version to the server."
task :deploy => :environment do
    invoke :environment
    deploy do
      invoke :'git:clone'
      invoke :'deploy:link_shared_paths'
      # in_path(fetch(:deploy_to)) do
        command %{ln -s "#{fetch(:deploy_to)}/shared/config/database.yml" "./config/database.yml"}
        command %{ln -s "#{fetch(:deploy_to)}/shared/config/secrets.yml" "./config/secrets.yml"}
      # end
      # command %{source "/usr/local/rvm/bin"}
      invoke :'bundle:install'
      invoke :'rails:db_migrate'
      invoke :'rails:assets_precompile'
      invoke :'deploy:cleanup'
      command %{chmod 777 -R #{fetch(:deploy_to)}/shared/tmp}
      command %{chmod 777 -R #{fetch(:deploy_to)}/shared/log}
      command %{chmod 777 -R #{fetch(:deploy_to)}/shared/public/system}

      on :launch do
        invoke :restart
      end
    end
end

task :restart do

  # in_path(fetch(:current_path)) do
    command %{mkdir -p tmp/}
    command %{touch tmp/restart.txt}
  # end

end

task :setup_nginx do
  command "cp -r #{fetch(:deploy_to)}/current/evento-coletivo.conf /etc/nginx/conf/sites-enabled/"
  command "sudo service nginx restart"
end