From 198c807eb6d901e34a25267279284bca0bd794e2 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 30 Aug 2018 23:37:11 +0200 Subject: [PATCH 1/4] nouveau serveur --- config/deploy.rb | 197 ++++++++++++++++++++++++---------------------- config/env_init | 7 ++ config/nginx.conf | 32 ++++++-- config/unicorn.rb | 12 +-- 4 files changed, 142 insertions(+), 106 deletions(-) mode change 100755 => 100644 config/deploy.rb create mode 100644 config/env_init mode change 100755 => 100644 config/unicorn.rb diff --git a/config/deploy.rb b/config/deploy.rb old mode 100755 new mode 100644 index 567e76b..290dd67 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,140 +1,147 @@ set :application, 'heylium_app' - set :domain, 'heylium.quartz.xyz' +set :domain, 'quartz-www02.sysnove.net' - set :user, 'web' - set :scm_user, "git" - set :scm_host, "gitlab.quartz.xyz" +set :user, 'web' +set :scm_user, "git" +set :scm_host, "quartz.snlab.fr" - set :rvm_ruby_string, 'ruby-2.1.2' - set :rvm_autolibs_flag, "read-only" +set :rvm_ruby_string, 'ruby-2.1.2' +set :rvm_autolibs_flag, "read-only" - set :bundle_cmd, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" - set :bundle_dir, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}" - set :use_sudo, false +set :bundle_cmd, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" +set :bundle_dir, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}" +set :use_sudo, false - set :deploy_to, "/home/#{user}/#{application}/" - set :deploy_via, :remote_cache +set :deploy_to, "/srv/www/#{user}/#{application}/" +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 +role :app, domain +role :web, domain +role :db, domain, :primary => true - set :scm, :git +set :scm, :git - set :repository, "#{scm_user}@#{scm_host}:nbally/#{application}.git" +set :repository, "#{scm_user}@#{scm_host}:nicolas/#{application}.git" - set :branch, "master" +set :branch, "master" - default_run_options[:pty] = true +default_run_options[:pty] = true - require "rvm/capistrano" - require 'bundler/capistrano' +require "rvm/capistrano" +require 'bundler/capistrano' - load 'deploy/assets' +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 + +# 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 + + + + desc "Symlink shared config files" + task :symlink_config_files do + run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias" + + run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias" + + + run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3" - desc "Symlink shared config files" - task :symlink_config_files do + sudo "cp #{current_path}/config/env_init #{deploy_to}env_init" + + sudo "sudo systemctl enable quartz_app@#{application}" - run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias" - - run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias" - - - run "ln -s #{deploy_to}shared/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 " - end - - - - task :start do - sudo "service #{application} start" - end - task :stop do - run "service #{application} stop" - end - task :restart do - sudo "service #{application} restart" - 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 - #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 + + task :start do + sudo "systemctl start quartz_app@#{application}" + end + task :stop do + sudo "systemctl stop quartz_app@#{application}" + end + task :restart do + sudo "systemctl stop 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" + run "mkdir #{deploy_to}shared/tmp" + end + - - after "deploy:setup", "deploy:create_files_folders" - - #after "deploy:restart", "deploy:cleanup" +end - before "deploy:restart", "deploy:symlink_config_files" +#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", "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" - \ No newline at end of file + + + diff --git a/config/env_init b/config/env_init new file mode 100644 index 0000000..8d61bfe --- /dev/null +++ b/config/env_init @@ -0,0 +1,7 @@ + +APP_RUBY=2.1.2 +ENV=production +APP_ROOT=/srv/www/web/heylium_app/current/ +GEM_HOME=/srv/www/web/.rvm/gems/ruby-$APP_RUBY +UNICORN_OPTS="-D -E ${ENV} -c ${APP_ROOT}/config/unicorn.rb" + diff --git a/config/nginx.conf b/config/nginx.conf index 8101e0e..db812f2 100755 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,9 +1,9 @@ upstream heylium_app_unicorn { - server unix:/home/web/heylium_app/shared/unicorn.sock fail_timeout=0; + server unix:/srv/www/web/heylium_app/shared/tmp/unicorn.sock fail_timeout=0; } server { - listen 80; + listen [::]:443 ssl; server_name heylium.quartz.xyz heylium.io; root /home/web/heylium_app/current/public; try_files $uri/index.html $uri @unicorn; @@ -18,12 +18,34 @@ server { error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; + + ssl on; + ssl_certificate /etc/letsencrypt/live/heylium.io/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/heylium.io/privkey.pem; + + include snippets/letsencrypt.conf; + } server { - listen 80; - server_name www.heylium.io; - rewrite ^(.*) http://heylium.io permanent; + listen [::]:80; + server_name *.heylium.io www.heylium.io; + + return 301 https://heylium.io$request_uri; + + include snippets/letsencrypt.conf; } +server { + listen [::]:443 ssl; + server_name *.heylium.io; + + ssl on; + ssl_certificate /etc/letsencrypt/live/heylium.io/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/heylium.io/privkey.pem; + + return 301 https://heylium.io$request_uri; + + include snippets/letsencrypt.conf; +} diff --git a/config/unicorn.rb b/config/unicorn.rb old mode 100755 new mode 100644 index cf53910..0cffffa --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,10 +1,10 @@ @rails_app = "heylium_app" -working_directory "/home/web/#{@rails_app}/current" -pid "/home/web/#{@rails_app}/shared/unicorn.pid" -stderr_path "/home/web/#{@rails_app}/shared/log/unicorn.log" -stdout_path "/home/web/#{@rails_app}/shared/log/unicorn.log" +working_directory "/srv/www/web/#{@rails_app}/current" +pid "/srv/www/web/#{@rails_app}/shared/unicorn.pid" +stderr_path "/srv/www/web/#{@rails_app}/shared/log/unicorn.log" +stdout_path "/srv/www/web/#{@rails_app}/shared/log/unicorn.log" -listen "/home/web/#{@rails_app}/shared/unicorn.sock" +listen "/srv/www/web/#{@rails_app}/shared/tmp/unicorn.sock" worker_processes 2 -timeout 30 \ No newline at end of file +timeout 600 From 6b8afa04b44481bd4dfae507a290eb9f2c97eb58 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 30 Aug 2018 23:57:45 +0200 Subject: [PATCH 2/4] suite --- config/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/nginx.conf b/config/nginx.conf index db812f2..a2bdcc2 100755 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -5,7 +5,7 @@ upstream heylium_app_unicorn { server { listen [::]:443 ssl; server_name heylium.quartz.xyz heylium.io; - root /home/web/heylium_app/current/public; + root /srv/www/web/heylium_app/current/public; try_files $uri/index.html $uri @unicorn; location @unicorn { From 0530b125fa98e6fc1bbffac5a44bf64d9dde42e6 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 31 Aug 2018 00:02:19 +0200 Subject: [PATCH 3/4] suite --- app/views/layouts/public.html.haml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/views/layouts/public.html.haml b/app/views/layouts/public.html.haml index 6cb3c97..22c5b60 100755 --- a/app/views/layouts/public.html.haml +++ b/app/views/layouts/public.html.haml @@ -71,9 +71,10 @@ #home =image_tag "/heylium-logo.png", :id => "logo" %h3 L’application géolocalisée pour tous, partout, tout le temps - .links - =link_to image_tag("/heylium-ios.png"), "https://itunes.apple.com/fr/app/heylium/id1079057397?l=fr&ls=1&mt=8", :class => "ios" - =link_to image_tag("/heylium-android.png"), "https://play.google.com/store/apps/details?id=com.olwen_capital.afunda_ios", :class => "ios" + -if false + .links + =link_to image_tag("/heylium-ios.png"), "https://itunes.apple.com/fr/app/heylium/id1079057397?l=fr&ls=1&mt=8", :class => "ios" + =link_to image_tag("/heylium-android.png"), "https://play.google.com/store/apps/details?id=com.olwen_capital.afunda_ios", :class => "ios" #intro @@ -152,6 +153,7 @@ %h2 Commencez dès maintenant ! - .links - =link_to image_tag("/heylium-ios.png"), "https://itunes.apple.com/fr/app/heylium/id1079057397?l=fr&ls=1&mt=8", :class => "ios" - =link_to image_tag("/heylium-android.png"), "https://play.google.com/store/apps/details?id=com.olwen_capital.afunda_ios", :class => "ios" + -if false + .links + =link_to image_tag("/heylium-ios.png"), "https://itunes.apple.com/fr/app/heylium/id1079057397?l=fr&ls=1&mt=8", :class => "ios" + =link_to image_tag("/heylium-android.png"), "https://play.google.com/store/apps/details?id=com.olwen_capital.afunda_ios", :class => "ios" From ad4364be6bb151b4f5b2853dc641ef8a9715530a Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Sat, 1 Sep 2018 00:53:50 +0200 Subject: [PATCH 4/4] suite --- config/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/nginx.conf b/config/nginx.conf index a2bdcc2..8f99320 100755 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -29,7 +29,7 @@ server { server { listen [::]:80; - server_name *.heylium.io www.heylium.io; + server_name *.heylium.io heylium.io; return 301 https://heylium.io$request_uri;