diff --git a/Capfile b/Capfile index d04de11..6c8fe2a 100644 --- a/Capfile +++ b/Capfile @@ -1,4 +1,29 @@ -load 'deploy' if respond_to?(:namespace) # cap2 differentiator -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 +# Load DSL and Setup Up Stages +require 'capistrano/setup' + +# Includes default deployment 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 } \ No newline at end of file diff --git a/Gemfile b/Gemfile index 61cfa8f..0aa3bc5 100644 --- a/Gemfile +++ b/Gemfile @@ -28,14 +28,18 @@ gem 'haml-rails' gem "therubyracer" +gem 'capistrano', '~> 3.0', require: false, group: :development + + group :development, :test do gem 'byebug' - #gem 'capistrano-rails' - #gem "rvm-capistrano" - gem "capistrano", '2.15.5', group: :development - gem "rvm-capistrano",'1.4.1', group: :development - gem 'net-ssh', '~>2.7.0' + + gem 'capistrano-rails', '~> 1.1', require: false + gem 'capistrano-bundler', '~> 1.1', require: false + gem 'capistrano-rvm', '~> 0.1', require: false + gem 'sshkit-sudo', require: false + #gem 'net-ssh', '~>2.7.0' gem 'web-console', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index c9175d4..bb9d76f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,16 +44,21 @@ GEM binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) - byebug (3.5.1) - columnize (~> 0.8) - debugger-linecache (~> 1.2) - slop (~> 3.6) - capistrano (2.15.5) - highline - net-scp (>= 1.0.0) - net-sftp (>= 2.0.0) - net-ssh (>= 2.0.14) - net-ssh-gateway (>= 1.1.0) + byebug (5.0.0) + columnize (= 0.9.0) + capistrano (3.4.0) + i18n + rake (>= 10.0.0) + sshkit (~> 1.3) + capistrano-bundler (1.1.4) + capistrano (~> 3.1) + 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) activemodel (>= 3.2.0) activesupport (>= 3.2.0) @@ -62,39 +67,37 @@ GEM coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.3.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1) + coffee-script-source (1.9.1.1) + colorize (0.7.7) columnize (0.9.0) debug_inspector (0.0.2) - debugger-linecache (1.2.0) erubis (2.7.0) - execjs (2.3.0) + execjs (2.5.2) formtastic (2.3.0) actionpack (>= 3.0) formtastic-bootstrap (3.0.0) formtastic (>= 2.2) - globalid (0.3.3) + globalid (0.3.5) activesupport (>= 4.1.0) gravatar_image_tag (1.2.0) haml (4.0.6) tilt - haml-rails (0.8.2) + haml-rails (0.9.0) actionpack (>= 4.0.1) activesupport (>= 4.0.1) - haml (>= 3.1, < 5.0) + haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - highline (1.7.2) - hike (1.2.3) html2haml (2.0.0) erubis (~> 2.7.0) haml (~> 4.0.0) nokogiri (~> 1.6.0) ruby_parser (~> 3.5) i18n (0.7.0) - jbuilder (2.2.8) + jbuilder (2.2.16) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jquery-rails (4.0.3) @@ -110,25 +113,21 @@ GEM rails kgio (2.9.3) libv8 (3.16.14.7) - loofah (2.0.1) + loofah (2.0.2) nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) - mime-types (2.4.3) + mime-types (2.5) mini_portile (0.6.2) - minitest (5.5.1) - multi_json (1.10.1) + minitest (5.6.1) + multi_json (1.11.0) mysql2 (0.3.18) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) - net-ssh (2.7.0) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) + net-ssh (2.9.2) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) - rack (1.6.0) + rack (1.6.1) rack-test (0.6.3) rack (>= 1.0) rails (4.2.0) @@ -144,11 +143,11 @@ GEM sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.5) + rails-dom-testing (1.0.6) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.1) + rails-html-sanitizer (1.0.2) loofah (~> 2.0) railties (4.2.0) actionpack (= 4.2.0) @@ -160,13 +159,11 @@ GEM rdoc (4.2.0) json (~> 1.4) ref (1.0.5) - rmagick (2.13.4) - ruby_parser (3.6.4) + rmagick (2.15.0) + ruby_parser (3.6.6) sexp_processor (~> 4.1) - rvm-capistrano (1.4.1) - capistrano (>= 2.0.0) - sass (3.4.12) - sass-rails (5.0.1) + sass (3.4.14) + sass-rails (5.0.3) railties (>= 4.0.0, < 5.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) @@ -175,23 +172,25 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - sexp_processor (4.4.5) - slop (3.6.0) - spring (1.3.2) - sprockets (2.12.3) - hike (~> 1.2) - multi_json (~> 1.0) + sexp_processor (4.5.1) + spring (1.3.6) + sprockets (3.1.0) rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.2.4) + sprockets-rails (2.3.1) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - therubyracer (0.12.1) + 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) - thread_safe (0.3.4) + thread_safe (0.3.5) tilt (1.4.1) turbolinks (2.5.3) coffee-rails @@ -202,17 +201,17 @@ GEM railties (~> 4.1) tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (2.7.0) + uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) - unicorn (4.8.3) + unicorn (4.9.0) kgio (~> 2.6) rack raindrops (~> 0.7) - web-console (2.0.0) - activemodel (~> 4.0) + web-console (2.1.2) + activemodel (>= 4.0) binding_of_caller (>= 0.7.2) - railties (~> 4.0) + railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) PLATFORMS @@ -223,7 +222,10 @@ DEPENDENCIES acts_as_tree bcrypt (~> 3.1.7) byebug - capistrano (= 2.15.5) + capistrano (~> 3.0) + capistrano-bundler (~> 1.1) + capistrano-rails (~> 1.1) + capistrano-rvm (~> 0.1) carrierwave coffee-rails (~> 4.1.0) formtastic (= 2.3.0) @@ -234,13 +236,12 @@ DEPENDENCIES jquery-rails kaminari-bootstrap mysql2 - net-ssh (~> 2.7.0) rails (= 4.2.0) rmagick - rvm-capistrano (= 1.4.1) sass-rails (~> 5.0) sdoc (~> 0.4.0) spring + sshkit-sudo therubyracer turbolinks twitter-bootstrap-rails diff --git a/app/views/layouts/public.html.haml b/app/views/layouts/public.html.haml index 10bb6bd..b9f067f 100644 --- a/app/views/layouts/public.html.haml +++ b/app/views/layouts/public.html.haml @@ -90,7 +90,7 @@ =link_to "envoyer un mail", "mailto:info@nicolasbally.com" lors de toute utilisation de ce contenu - =link_to "Mentions légales", "#", :id => "legals" - ="- :)" + #legals_large .content diff --git a/config/deploy.rb b/config/deploy.rb index b23a044..d2a9ab9 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,118 +1,167 @@ -set :application, 'blog_perso_app' - set :domain, 'blog.nicolasbally.com' +# config valid only for current version of Capistrano +lock '3.4.0' + +application = "blog_perso_app" +set :application, application + +set :stages, ["production"] + +scm_user = "git" +scm_host = "git.nicolasbally.com" + +set :scm_user, scm_user +set :scm_host, scm_host + +set :pty, true + +set :rvm_ruby_version, 'ruby-2.1.2' +#set :rvm_autolibs_flag, "read-only" + +#set :bundle_cmd, "/home/web/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" +#set :bundle_dir, "/home/web/.rvm/gems/#{rvm_ruby_string}" +#set :use_sudo, false - require "rvm/capistrano" - set :rvm_ruby_string, 'ruby-2.1.2' - set :rvm_type, :user +set :deploy_to, "/home/web/#{application}/" - set :user, 'web' +set :deploy_via, :remote_cache + +set :normalize_asset_timestamps, false + +set :rails_env, "production" + + +set :scm, :git + +set :repo_url, "#{scm_user}@#{scm_host}:root/#{application}.git" + +set :branch, "master" + + +set :shared_path, "#{deploy_to}shared" + +#default_run_options[:pty] = true - set :deploy_to, "/home/#{user}/#{application}/" - set :deploy_via, :remote_cache - - set :normalize_asset_timestamps, false - - - set :rails_env, "production" - role :app, domain - role :web, domain - role :db, domain, :primary => true - set :scm, :git - set :repository, "git@git.nicolasbally.com:root/#{application}.git" - set :branch, "master" - - default_run_options[:pty] = true - - - - before "deploy:symlink", "deploy:bundle_gems" - after "deploy:bundle_gems", "deploy:make_simlinks" - after "deploy:make_simlinks", "assets:precompile" - - - -# after "deploy", "deploy:restart" - after "deploy:restart", "deploy:cleanup" - - - #after "deploy", "deploy:bundle_gems" - #after "deploy:bundle_gems", "deploy:make_simlinks" - #after "deploy:make_simlinks", "assets:precompile" - #after "assets:precompile", "deploy:restart" - #after "deploy:restart", "deploy:cleanup" - - - namespace :assets do - task :precompile, :roles => :web do - run "rm -rf #{release_path}/public/assets" - run "ln -s #{deploy_to}shared/assets #{release_path}/public/assets" - - - run "cd #{release_path} && bundle exec rake assets:precompile --trace" - end - - task :cleanup, :roles => :web do - run "cd #{current_path} && RAILS_ENV=production bundle exec rake assets:clean" - end - end - - - - - - namespace :deploy do - - 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 :bundle_gems do - run "cd #{release_path} && bundle install" - end - - task :make_simlinks do - run "rm -rf #{release_path}/private_medias" - run "ln -s #{deploy_to}shared/storage/private #{release_path}/private_medias" - run "rm -rf #{release_path}/public/public_medias" - run "ln -s #{deploy_to}shared/storage/public #{release_path}/public/public_medias" +namespace :deploy do + + + desc "Symlink shared config files" + task :symlink_config_files do + + on roles(:app) do + execute :ln, "-s #{shared_path}/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" + + + + sudo :cp, "#{current_path}/config/unicorn_init_d /etc/init.d/#{application}" + sudo :chmod, "+x /etc/init.d/#{application}" + sudo :"update-rc.d", "#{application} defaults " - sudo "cp #{current_path}/config/unicorn_init_d /etc/init.d/#{application}" - - sudo "chmod +x /etc/init.d/#{application}" - sudo "update-rc.d #{application} defaults " - end + end - task :start do - sudo "service #{application} start" - end - task :stop do - run "service #{application} stop" - end - task :restart, :roles => :app, :except => { :no_release => true } do - sudo "service #{application} restart" - end - task :migrate do - run "cd #{deploy_to}current && rake db:migrate RAILS_ENV=#{rails_env}" - end - - task :seeds do - run "cd #{deploy_to}current && rake db:seeds RAILS_ENV=#{rails_env}" + end + - end - end - \ No newline at end of file + desc 'Restart application' + task :restart do + on roles(:app) do + + sudo "/etc/init.d/#{application} restart" + + + + + + 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" + +#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