diff --git a/Capfile b/Capfile index 8cc52f1..53de04b 100644 --- a/Capfile +++ b/Capfile @@ -30,10 +30,12 @@ require "capistrano/rvm" # require "capistrano/rbenv" # require "capistrano/chruby" require "capistrano/rails/assets" -require 'capistrano/nginx' +#require 'capistrano/nginx' require "capistrano/bundler" require "capistrano/rails/migrations" # require "capistrano/passenger" + + # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile index 49d4b24..e6c0a4f 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'rails', '~> 6.0.0.rc1' # Use sqlite3 as the database for Active Record gem 'mysql2' # Use Puma as the app server -gem 'puma', '~> 3.11' + # Use SCSS for stylesheets gem 'sass-rails', '~> 5' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker @@ -36,9 +36,17 @@ gem 'bootsnap', '>= 1.4.2', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + + +end + +group :production do + gem 'unicorn' end group :development do + + gem 'puma', '~> 3.11' # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' @@ -91,5 +99,6 @@ group :development do gem 'capistrano-bundler', '~> 1.1', require: false gem "capistrano-rvm", group: :development gem 'capistrano3-nginx', '~> 2.0', group: :development + end diff --git a/Gemfile.lock b/Gemfile.lock index 56f1311..1cbfeba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,6 +179,7 @@ GEM kaminari (>= 0.13.0) rails kaminari-core (1.1.1) + kgio (2.11.2) less (2.6.0) commonjs (~> 0.2.7) less-rails (4.0.0) @@ -250,6 +251,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.20.3, < 2.0) + raindrops (0.19.0) rake (12.3.2) rb-fsevent (0.10.3) rb-inotify (0.10.0) @@ -313,6 +315,9 @@ GEM tzinfo (1.2.5) thread_safe (~> 0.1) unicode_utils (1.4.0) + unicorn (5.5.1) + kgio (~> 2.6) + raindrops (~> 0.7) web-console (4.0.0) actionview (>= 6.0.0.a) activemodel (>= 6.0.0.a) @@ -378,6 +383,7 @@ DEPENDENCIES turbolinks (~> 5) twitter-bootstrap-rails tzinfo-data + unicorn web-console (>= 3.3.0) webdrivers webpacker (~> 4.0) diff --git a/config/deploy.rb b/config/deploy.rb index 6af8449..d68520c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -10,3 +10,6 @@ set :domain, 'quartz-www02.sysnove.net' set :rvm_ruby_version, '2.6.0' # use the same ruby as used locally for deployment set :rvm_autolibs_flag, "read-only" + + +#set :nginx_template, "#{stage_config_path}/nginx.conf.erb" \ No newline at end of file diff --git a/config/deploy/nginx.conf.erb b/config/deploy/nginx.conf.erb new file mode 100644 index 0000000..057f4a4 --- /dev/null +++ b/config/deploy/nginx.conf.erb @@ -0,0 +1,23 @@ +upstream qi6_app_unicorn { + server unix:/srv/www/web/qi6_app/shared/unicorn.sock fail_timeout=0; +} + +server { + listen [::]:80; + server_name qi6_app.quartz.xyz ; + root /srv/www/web/qi6_app/current/public; + try_files $uri/index.html $uri @unicorn; + + location @unicorn { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://qi6_app_unicorn; + proxy_read_timeout 6000; + } + + error_page 500 502 503 504 /500.html; + client_max_body_size 4G; + keepalive_timeout 6000; +} + diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 61f6543..44c2b73 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -5,7 +5,7 @@ server "quartz.snlab.fr", user: "web", roles: %w{web app db} set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master" puts stage_config_path -set :nginx_template, "#{stage_config_path}/#{fetch :stage}/nginx.conf.erb" +#set :nginx_template, "#{stage_config_path}/#{fetch :stage}/nginx.conf.erb" # server-based syntax # ====================== @@ -72,3 +72,50 @@ append :linked_files, "config/master.key" # auth_methods: %w(publickey password) # # password: "please use keys" # } + +set :pty, true +set :ssh_options, {:forward_agent => true} + +namespace :deploy do + before :starting, :ensure_user do + #on roles(:app) do + # sudo "cp #{current_path}/config/env_init #{deploy_to}env_init" + # end + #puts "A" + + + end + + before :finishing, :make_unicorn do + puts "FINISHIG" + + on roles(:app) do + sudo "cp #{current_path}/config/env_init #{deploy_to}env_init" + + sudo "sudo systemctl enable quartz_app@#{fetch(:application)}" + sudo "systemctl stop quartz_app@#{fetch(:application)}" + sudo "systemctl start quartz_app@#{fetch(:application)}" + + sudo "rm -rf /etc/nginx/sites-enabled/#{fetch(:application)}" + sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{fetch(:application)} " + + sudo "service nginx reload" + + end + + + + + + #sudo "sudo systemctl enable quartz_app@#{application}" + + + +# sudo "systemctl stop quartz_app@#{application}" + + # sudo "systemctl start quartz_app@#{application}" + + + + end +end \ No newline at end of file diff --git a/config/env_init b/config/env_init new file mode 100644 index 0000000..c1edee7 --- /dev/null +++ b/config/env_init @@ -0,0 +1,7 @@ + +APP_RUBY=2.6.0 +ENV=production +APP_ROOT=/srv/www/web/qi6_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/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..7fe2aed --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,10 @@ +@rails_app = "qi6_app" + +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 "/srv/www/web/#{@rails_app}/shared/unicorn.sock" +worker_processes 4 +timeout 9999