This commit is contained in:
Nicolas Bally 2018-03-14 02:06:03 +01:00
parent e45e4894d8
commit 000ce04cd9
4 changed files with 124 additions and 190 deletions

31
Capfile
View File

@ -1,29 +1,4 @@
# Load DSL and Setup Up Stages load 'deploy' if respond_to?(:namespace) # cap2 differentiator
require 'capistrano/setup' Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
# Includes default deployment tasks load 'config/deploy' # remove this line to skip loading any of the default tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
#
require 'capistrano/rvm'
# We're going to use the full capistrano/rails since
# it includes the asset compilation, DB migrations
# and bundler
require 'capistrano/rails'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
require 'sshkit/sudo'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

12
Gemfile
View File

@ -28,18 +28,16 @@ gem 'haml-rails'
gem "therubyracer" gem "therubyracer"
gem 'capistrano', '~> 3.0', require: false, group: :development
group :development, :test do group :development, :test do
gem 'byebug' gem 'byebug'
#gem 'capistrano-rails'
#gem "rvm-capistrano"
gem "capistrano", '2.15.5', group: :development, require: false
gem 'capistrano-rails', '~> 1.1', require: false gem "rvm-capistrano",'1.4.1', group: :development
gem 'capistrano-bundler', '~> 1.1', require: false gem 'net-ssh', '~>2.7.0'
gem 'capistrano-rvm', '~> 0.1', require: false
gem 'sshkit-sudo', require: false
#gem 'net-ssh', '~>2.7.0'
gem 'web-console', '~> 2.0' gem 'web-console', '~> 2.0'

View File

@ -46,19 +46,12 @@ GEM
builder (3.2.2) builder (3.2.2)
byebug (5.0.0) byebug (5.0.0)
columnize (= 0.9.0) columnize (= 0.9.0)
capistrano (3.4.0) capistrano (2.15.5)
i18n highline
rake (>= 10.0.0) net-scp (>= 1.0.0)
sshkit (~> 1.3) net-sftp (>= 2.0.0)
capistrano-bundler (1.1.4) net-ssh (>= 2.0.14)
capistrano (~> 3.1) net-ssh-gateway (>= 1.1.0)
sshkit (~> 1.2)
capistrano-rails (1.1.3)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
carrierwave (0.10.0) carrierwave (0.10.0)
activemodel (>= 3.2.0) activemodel (>= 3.2.0)
activesupport (>= 3.2.0) activesupport (>= 3.2.0)
@ -71,7 +64,6 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.9.1.1) coffee-script-source (1.9.1.1)
colorize (0.7.7)
columnize (0.9.0) columnize (0.9.0)
debug_inspector (0.0.2) debug_inspector (0.0.2)
erubis (2.7.0) erubis (2.7.0)
@ -91,6 +83,7 @@ GEM
haml (>= 4.0.6, < 5.0) haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1) html2haml (>= 1.0.1)
railties (>= 4.0.1) railties (>= 4.0.1)
highline (1.7.10)
html2haml (2.0.0) html2haml (2.0.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
haml (~> 4.0.0) haml (~> 4.0.0)
@ -124,7 +117,11 @@ GEM
mysql2 (0.3.18) mysql2 (0.3.18)
net-scp (1.2.1) net-scp (1.2.1)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.9.2) net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
net-ssh-gateway (1.3.0)
net-ssh (>= 2.6.5)
nokogiri (1.6.6.2) nokogiri (1.6.6.2)
mini_portile (~> 0.6.0) mini_portile (~> 0.6.0)
rack (1.6.1) rack (1.6.1)
@ -158,10 +155,11 @@ GEM
rake (10.4.2) rake (10.4.2)
rdoc (4.2.0) rdoc (4.2.0)
json (~> 1.4) json (~> 1.4)
ref (1.0.5)
rmagick (2.15.0) rmagick (2.15.0)
ruby_parser (3.6.6) ruby_parser (3.6.6)
sexp_processor (~> 4.1) sexp_processor (~> 4.1)
rvm-capistrano (1.4.1)
capistrano (>= 2.0.0)
sass (3.4.14) sass (3.4.14)
sass-rails (5.0.3) sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -180,15 +178,6 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sshkit (1.7.1)
colorize (>= 0.7.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
sshkit-sudo (0.0.3)
sshkit
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1) tilt (1.4.1)
@ -222,10 +211,7 @@ DEPENDENCIES
acts_as_tree acts_as_tree
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
byebug byebug
capistrano (~> 3.0) capistrano (= 2.15.5)
capistrano-bundler (~> 1.1)
capistrano-rails (~> 1.1)
capistrano-rvm (~> 0.1)
carrierwave carrierwave
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
formtastic (= 2.3.0) formtastic (= 2.3.0)
@ -236,15 +222,19 @@ DEPENDENCIES
jquery-rails jquery-rails
kaminari-bootstrap kaminari-bootstrap
mysql2 mysql2
net-ssh (~> 2.7.0)
rails (= 4.2.0) rails (= 4.2.0)
rmagick rmagick
rvm-capistrano (= 1.4.1)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
spring spring
sshkit-sudo
therubyracer therubyracer
turbolinks turbolinks
twitter-bootstrap-rails twitter-bootstrap-rails
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
unicorn unicorn
web-console (~> 2.0) web-console (~> 2.0)
BUNDLED WITH
1.16.1

View File

@ -1,173 +1,144 @@
# config valid only for current version of Capistrano set :application, 'blog_perso_app'
lock '3.4.0' set :domain, 'quartz-www02.sysnove.net'
application = "blog_perso_app"
set :application, application
set :stages, ["production"]
scm_user = "git" set :user, 'web'
scm_host = "quartz.snlab.fr" set :scm_user, "git"
set :scm_host, "quartz.snlab.fr"
set :scm_user, scm_user
set :scm_host, scm_host
set :pty, true
set :rvm_ruby_version, 'ruby-2.1.2' set :rvm_ruby_string, 'ruby-2.1.2'
#set :rvm_autolibs_flag, "read-only" set :rvm_autolibs_flag, "read-only"
#set :bundle_cmd, "/srv/www/web/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" set :bundle_cmd, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle"
#set :bundle_dir, "/srv/www/web/.rvm/gems/#{rvm_ruby_string}" set :bundle_dir, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}"
#set :use_sudo, false set :use_sudo, false
set :deploy_to, "/srv/www/web/#{application}/" set :deploy_to, "/srv/www/#{user}/#{application}/"
set :deploy_via, :remote_cache
set :deploy_via, :remote_cache set :normalize_asset_timestamps, false
set :normalize_asset_timestamps, false set :rails_env, "production"
set :rails_env, "production" role :app, domain
role :web, domain
role :db, domain, :primary => true
set :scm, :git
set :repository, "#{scm_user}@#{scm_host}:nicolas/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
set :scm, :git require "rvm/capistrano"
require 'bundler/capistrano'
set :repo_url, "#{scm_user}@#{scm_host}:nicolas/#{application}.git"
set :branch, "master"
set :shared_path, "#{deploy_to}shared"
#default_run_options[:pty] = true
load 'deploy/assets'
namespace :deploy do
# namespace :assets do
# task :precompile, :roles => :web, :except => { :no_release => true } do
# from = source.next_revision(current_revision)
# if releases.length <= 1 || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
# run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
# else
# logger.info "Skipping asset pre-compilation because there were no asset changes"
# end
# end
# end
namespace :deploy do
desc "Symlink shared config files" desc "Symlink shared config files"
task :symlink_config_files do task :symlink_config_files do
on roles(:app) do
execute :ln, "-s #{shared_path}/storage/private #{current_path}/private_medias" run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias"
execute :ln, "-s #{shared_path}/storage/public #{current_path}/public/public_medias"
execute :ln, "-s #{shared_path}/production.sqlite3 #{current_path}/db/production.sqlite3" run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias"
execute :ln, "-s #{shared_path}/env_init #{current_path}/config/env_init"
run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3"
sudo "cp #{current_path}/config/env_init #{deploy_to}env_init"
sudo :cp, "#{current_path}/config/unicorn_init_d /etc/init.d/#{application}"
sudo "sudo systemctl enable quartz_app@#{application}" sudo "sudo systemctl enable quartz_app@#{application}"
end
end end
desc 'Restart application'
task :start do
sudo "systemctl start quartz_app@#{application}"
end
task :stop do
sudo "systemctl stop quartz_app@#{application}"
end
task :restart do task :restart do
on roles(:app) do
sudo "systemctl stop quartz_app@#{application}" sudo "systemctl stop quartz_app@#{application}"
sudo "systemctl start quartz_app@#{application}" sudo "systemctl start quartz_app@#{application}"
end
task :reload_nginx do
sudo "rm -rf /etc/nginx/sites-enabled/#{application}"
sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application} "
sudo "service nginx reload"
end
task :seeds do
run "cd #{deploy_to}current && rake db:seed RAILS_ENV=#{rails_env}"
end
task :create_files_folders do
run "mkdir #{deploy_to}shared/storage"
run "mkdir #{deploy_to}shared/storage/private"
run "mkdir #{deploy_to}shared/storage/public"
end
end end
end
after :publishing, :symlink_config_files
after :symlink_config_files, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
#nothing here
end
end
end
#before 'deploy:setup', 'rvm:install_rvm' # install RVM
#before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR:
#before 'deploy:setup', 'rvm:create_gemset' # only create gemset
#after "deploy:setup", "deploy:create_files_folders" #before 'deploy:setup', 'rvm:install_rvm' # install RVM
#before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR:
#after "deploy:restart", "deploy:cleanup" #before 'deploy:setup', 'rvm:create_gemset' # only create gemset
#before "deploy:restart", "deploy:symlink_config_files"
#after "deploy", "deploy:cleanup" after "deploy:setup", "deploy:create_files_folders"
#after "deploy:restart", "deploy:cleanup"
before "deploy:restart", "deploy:symlink_config_files"
after "deploy", "deploy:cleanup"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'
# 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
# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('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
#namespace :deploy do
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
# end
# end
#end