capistrano3-unicorn-nginx 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52c5d9a913f2c7d99c928d5a8aa432602378bba
4
- data.tar.gz: '0804623ecb45c5d8dfe40bde11f9d559f1757261'
3
+ metadata.gz: 268ff5997cf5171e1ccef2d62caa8924ca9c43b7
4
+ data.tar.gz: 85760a9a734e566285707337af792f6b07a8ca56
5
5
  SHA512:
6
- metadata.gz: 518e991b941a0110f17c8e589cf307582b8fb43800734c687ef7a2ff48ab669624e48713e410cbb4334091e782851544911ae3d4e515fa4f8dc2d9a645dc0d65
7
- data.tar.gz: 18116972c62d23818a0ae48b3a70bc368341e5d96ef05984bbfa13e3d1d574d9c6ef6cdd1b83c4a863e9d6b12fd13c524063f29507d9c4875fcbf911cb4cb402
6
+ metadata.gz: 58364e7056ab54925e08828589f0279d86551f3417c61804856d7aad49fa77966e3ec30b76f1955eb8dbeeb53fb27ae2001a2c03735d1bd1ffe0028e5c20ff49
7
+ data.tar.gz: fc27e0f6d85184717338b5fc7b60c864d91e53da97ddf4c0886fdcfc538ac39fd5ce01ea509f5123463fd768ebc01ea85bc19f335039840ed376c64c08b555d2
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'capistrano3-unicorn-nginx'
7
- s.version = '0.0.3'
7
+ s.version = '0.0.4'
8
8
  s.date = '2019-02-01'
9
9
  s.summary = "Capistrano tasks for automatic and sensible unicorn configuration"
10
10
  s.description = <<-EOF.gsub(/^\s+/, '')
@@ -0,0 +1,35 @@
1
+ require 'capistrano/unicorn_nginx/helpers'
2
+ include Capistrano::UnicornNginx::Helpers
3
+
4
+ namespace :load do
5
+ task :defaults do
6
+ set :nginx_listen_port, 80
7
+ set :nginx_server_name, "_"
8
+ set :nginx_upstream_name, -> { "#{fetch(:application)}" }
9
+ set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
10
+ set :nginx_fail_timeout, 0
11
+ set :nginx_access_log_file, -> { "#{shared_path}/#{fetch(:nginx_config_name)}.access.log" }
12
+ set :nginx_error_log_file, -> { "#{shared_path}/#{fetch(:nginx_config_name)}.error.log" }
13
+ set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_path)}" }
14
+ set :nginx_config_path, -> { nginx_config_file }
15
+ set :templates_path, 'config/deploy/templates'
16
+ end
17
+ end
18
+
19
+ namespace :nginx do
20
+ desc 'Setup nginx configuration'
21
+ task :setup do
22
+ on roles :web do
23
+ sudo_upload! template('nginx_conf.erb'), fetch(:nginx_config_path)
24
+ end
25
+ end
26
+
27
+ %w[stop start restart reload].each do |action|
28
+ desc "#{action} nginx"
29
+ task action do
30
+ on roles :web do
31
+ sudo :service, "nginx", action
32
+ end
33
+ end
34
+ end
35
+ end
@@ -14,6 +14,7 @@ namespace :load do
14
14
  set :unicorn_restart_sleep_time, 3
15
15
  set :unicorn_options, -> { '' }
16
16
  set :unicorn_env, -> { fetch(:rails_env) || 'deployment' }
17
+ set :templates_path, 'config/deploy/templates'
17
18
  set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
18
19
  set :unicorn_worker_processes, 2
19
20
  set :unicorn_timeout, 30
@@ -8,7 +8,10 @@ module Capistrano3
8
8
  end
9
9
 
10
10
  def template_to_s template_name
11
- config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano3/unicorn_nginx/templates/#{template_name}")
11
+ config_file = "#{fetch(:templates_path)}/#{template_name}"
12
+ unless File.exists?(config_file)
13
+ config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano3/unicorn_nginx/templates/#{template_name}")
14
+ end
12
15
  ERB.new(File.read(config_file), nil, '-').result(binding)
13
16
  end
14
17
 
@@ -0,0 +1,18 @@
1
+ module Capistrano3
2
+ module UnicornNginx
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ desc "Create local nginx and unicorn configuration files for customization"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, type: :string,
8
+ default: "config/deploy/templates",
9
+ banner: "path to templates"
10
+
11
+ def copy_template
12
+ copy_file "nginx_conf.erb", "#{templates_path}/nginx_conf.erb"
13
+ copy_file "unicorn.rb.erb", "#{templates_path}/unicorn.rb.erb"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ upstream <%= fetch(:nginx_upstream_name) %> {
2
+ server unix:<%= fetch(:nginx_upstream_file) %> fail_timeout=<%= fetch(:nginx_fail_timeout) %>;
3
+ }
4
+
5
+ server {
6
+ server_tokens off;
7
+ add_header X-Content-Type-Options nosniff;
8
+ client_max_body_size 4G;
9
+ keepalive_timeout 10;
10
+
11
+ error_page 500 502 504 /500.html;
12
+ error_page 503 @503;
13
+
14
+ server_name <%= fetch(:nginx_server_name) %>;
15
+ root <%= current_path %>/public;
16
+ try_files $uri/index.html $uri @<%= fetch(:nginx_upstream_name) %>;
17
+
18
+ location @<%= fetch(:nginx_upstream_name) %> {
19
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
20
+ proxy_set_header Host $http_host;
21
+ proxy_redirect off;
22
+ proxy_pass http://<%= fetch(:nginx_upstream_name) %>;
23
+
24
+ access_log <%= fetch(:nginx_access_log_file) %>;
25
+ error_log <%= fetch(:nginx_error_log_file) %>;
26
+ }
27
+
28
+ location ^~ /assets/ {
29
+ gzip_static on;
30
+ expires max;
31
+ add_header Cache-Control public;
32
+ }
33
+
34
+ location = /50x.html {
35
+ root html;
36
+ }
37
+
38
+ location = /404.html {
39
+ root html;
40
+ }
41
+
42
+ location @503 {
43
+ error_page 405 = /system/maintenance.html;
44
+ if (-f $document_root/system/maintenance.html) {
45
+ rewrite ^(.*)$ /system/maintenance.html break;
46
+ }
47
+ rewrite ^(.*)$ /503.html break;
48
+ }
49
+
50
+ if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
51
+ return 405;
52
+ }
53
+
54
+ if (-f $document_root/system/maintenance.html) {
55
+ return 503;
56
+ }
57
+ }
@@ -5,7 +5,7 @@ listen "<%= fetch(:unicorn_sock_path) %>"
5
5
  pid "<%= fetch(:unicorn_pid_path) %>"
6
6
 
7
7
  stderr_path "<%= fetch(:unicorn_stderr_path) %>"
8
- stdout_path "<%= fetch(:unicorn_stdout_path %>"
8
+ stdout_path "<%= fetch(:unicorn_stdout_path) %>"
9
9
 
10
10
  preload_app true
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-unicorn-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - truongkma
@@ -67,9 +67,12 @@ files:
67
67
  - Rakefile
68
68
  - capistrano3-unicorn-nginx.gemspec
69
69
  - lib/capistrano3-unicorn-nginx.rb
70
+ - lib/capistrano3/tasks/nginx.rake
70
71
  - lib/capistrano3/tasks/unicorn.rake
71
72
  - lib/capistrano3/unicorn_nginx.rb
72
73
  - lib/capistrano3/unicorn_nginx/helpers.rb
74
+ - lib/generators/capistrano3/unicorn_nginx/generators/config_generator.rb
75
+ - lib/generators/capistrano3/unicorn_nginx/templates/nginx_conf.erb
73
76
  - lib/generators/capistrano3/unicorn_nginx/templates/unicorn.rb.erb
74
77
  homepage: https://github.com/truongkma/capistrano3-unicorn-nginx
75
78
  licenses: