mina-puma-nginx 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0c5b99967e0d48cb5e9c99be0bd3447dccb029f1faac8b6cba2630edd2ecc58c
4
+ data.tar.gz: b65ac99351ac4adf51267ee4759709b3ec10dd5829e7a014024bec6b6ecf355d
5
+ SHA512:
6
+ metadata.gz: df7ec3ad66a0174c7db9ecdadcaab80ebe48ad1cda024a09c34ba39623993243dbf34f9901ca372735d3bdee22182d39fbe27e5fecf618af9643e5fe7b2150da
7
+ data.tar.gz: 79fc2f58ba3ad30132a4260e6588b0e37694f6a7dee9d711031ac35265db9e7ff304fc941ce2e6a6bf08bcb64aa5b0ddb7ed2c45429c75af8a9fa145e1f8326f
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ TAGS
20
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mina-nginx.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 hbin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Mina Nginx
2
+
3
+ [Mina](https://github.com/nadarei/mina) tasks for handle with
4
+ [Nginx](http://nginx.com/).
5
+
6
+ This gem provides several mina tasks:
7
+
8
+ mina nginx:install # Install template config to host repo for easy overrides
9
+ mina nginx:setup # Install config file to the server's shared dir + symlink
10
+ mina nginx:print # Parse & print the nginx config
11
+
12
+ mina nginx:reload # Reload Nginx
13
+ mina nginx:restart # Restart Nginx
14
+ mina nginx:start # Start Nginx
15
+ mina nginx:status # Status Nginx
16
+ mina nginx:stop # Stop Nginx
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile, then `bundle install`:
21
+
22
+ gem 'mina-nginx', :require => false
23
+
24
+ Once installed, add this to your `config/deploy.rb` file:
25
+
26
+ require 'mina/nginx'
27
+
28
+ Install the base template to your repo's `lib/mina/templates` directory:
29
+
30
+ $ bundle exec mina nginx:install
31
+
32
+ Consider variables used by the nginx config, particularly:
33
+
34
+ * `application` - application name; defaults to 'application'
35
+ * `nginx_socket_path` - path to socket file used in nginx upstream directive
36
+ * `server_name` - application's nginx server_name (e.g. example.com); defaults to value for `domain`
37
+ * `domain` - fqdn you are deploying to
38
+ * `deploy_to` - deployment path
39
+ * `current_path` - current revision path
40
+
41
+ Edit installed template as required.
42
+
43
+ ## Recommended Usage
44
+
45
+ 1. Follow install steps above; and
46
+ 2. Invoke `nginx:setup` in your main `setup` task
47
+ 3. Run `nginx:setup` (or base `setup`) to install config changes
48
+
49
+ n.b. if the config template has not been installed locally, `mina-nginx` will
50
+ fall back to the default template gracefully.
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( http://github.com/hbin/mina-nginx/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,5 @@
1
+ module Mina
2
+ module Nginx
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
data/lib/mina/nginx.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'mina/nginx/version'
2
+ require "erb"
3
+
4
+ namespace :nginx do
5
+ set :nginx_path, '/etc/nginx'
6
+ set :nginx_socket_path, -> { "#{fetch(:shared_path)}/tmp/sockets/puma.sock" }
7
+ set :nginx_socket_flags, "fail_timeout=0"
8
+ set :nginx_config_unit, -> { "#{fetch(:application)}_#{fetch(:stage, fetch(:rails_env))}" }
9
+ set :nginx_config_name, -> { "#{fetch(:nginx_config_unit)}.conf" }
10
+
11
+ set :nginx_sites_available_path, -> { "#{fetch(:nginx_path)}/sites-available" }
12
+ set :nginx_sites_enabled_path, -> { "#{fetch(:nginx_path)}/sites-enabled" }
13
+
14
+
15
+ set :nginx_config, -> { "#{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)}" }
16
+ set :nginx_config_e, -> { "#{fetch(:nginx_sites_enabled_path)}/#{fetch(:nginx_config_name)}" }
17
+ set :nginx_use_ssl, true
18
+ set :nginx_use_http2, true
19
+ set :nginx_sts, true
20
+ set :nginx_ssl_stapling, true
21
+ set :nginx_ssl_certificate, nil
22
+ set :nginx_ssl_certificate_key, nil
23
+ set :nginx_ssl_dhparam, nil
24
+
25
+
26
+
27
+ desc 'Install Nginx config to repo'
28
+ task :install do
29
+ run :local do
30
+ installed_path = path_for_template
31
+
32
+ if File.exist? installed_path
33
+ error! %(file exists; please rm to continue: #{installed_path})
34
+ else
35
+ command %(mkdir -p config/deploy/templates)
36
+ command %(cp #{nginx_template} #{installed_path})
37
+ end
38
+ end
39
+ end
40
+
41
+ desc 'Print nginx config in local terminal'
42
+ task :print do
43
+ puts processed_nginx_template
44
+ end
45
+
46
+ desc 'Setup Nginx on server'
47
+ task :setup do
48
+ nginx_config = fetch(:nginx_config)
49
+ nginx_enabled_config = fetch(:nginx_config_e)
50
+
51
+ comment %(Installing nginx config file to #{nginx_config})
52
+ command %(sudo echo -ne '#{escaped_nginx_template}' > #{nginx_config})
53
+
54
+ comment %(Symlinking nginx config file to #{nginx_enabled_config})
55
+ command %(sudo ln -nfs #{nginx_config} #{nginx_enabled_config})
56
+
57
+ invoke :'nginx:restart'
58
+ end
59
+
60
+ %w(stop start restart reload status).each do |action|
61
+ desc "#{action.capitalize} Nginx"
62
+ task action.to_sym do
63
+ comment %(#{action.capitalize} Nginx)
64
+ command "sudo service nginx #{action}"
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def nginx_template
71
+ installed_path = path_for_template
72
+ template_path = path_for_template installed: false
73
+
74
+ File.exist?(installed_path) ? installed_path : template_path
75
+ end
76
+
77
+ def processed_nginx_template
78
+ erb = File.read(nginx_template)
79
+ ERB.new(erb, trim_mode: '-').result(binding)
80
+ end
81
+
82
+ def escaped_nginx_template
83
+ processed_nginx_template.gsub("\n","\\n").gsub("'","\\'")
84
+ end
85
+
86
+ def path_for_template installed: true
87
+ installed ?
88
+ File.expand_path('./config/deploy/templates/nginx.conf.erb') :
89
+ File.expand_path('../templates/nginx.conf.erb', __FILE__)
90
+ end
91
+ end
@@ -0,0 +1,99 @@
1
+ upstream puma_<%= fetch(:nginx_config_unit) %> {
2
+ server unix:<%= fetch(:nginx_socket_path) %> <%= fetch(:nginx_socket_flags) %>;
3
+ }
4
+ <% if fetch(:nginx_use_ssl) -%>
5
+ server {
6
+ listen 80;
7
+ server_name <%= fetch(:nginx_server_name) %>;
8
+ return 301 https://$host$1$request_uri;
9
+ }
10
+ <% end -%>
11
+
12
+ server {
13
+ <% if fetch(:nginx_use_ssl) -%>
14
+ <% if fetch(:nginx_use_http2) -%>
15
+ listen 443 ssl http2;
16
+ <% else -%>
17
+ listen 443 ssl;
18
+ <% end -%>
19
+ <% if fetch(:nginx_ssl_certificate) -%>
20
+ ssl_certificate <%= fetch(:nginx_ssl_certificate) %>;
21
+ <% end -%>
22
+ <% if fetch(:nginx_ssl_certificate_key) -%>
23
+ ssl_certificate_key <%= fetch(:nginx_ssl_certificate_key) %>;
24
+ <% end -%>
25
+ <% if fetch(:nginx_ssl_dhparam) -%>
26
+ ssl_dhparam <%= fetch(:nginx_ssl_dhparam) %>;
27
+ <% end -%>
28
+ <% if fetch(:nginx_sts) -%>
29
+ add_header Strict-Transport-Security max-age=15768000;
30
+ <% end -%>
31
+ <% if fetch(:nginx_ssl_stapling) -%>
32
+ ssl_stapling on;
33
+ <% end -%>
34
+
35
+ <% else -%>
36
+ listen 80;
37
+ <% end -%>
38
+ server_name <%= fetch(:nginx_server_name) %>;
39
+ root <%= fetch(:current_path) %>/public;
40
+ try_files $uri/index.html $uri @puma_<%= fetch(:nginx_config_unit) %>;
41
+
42
+ client_max_body_size 4G;
43
+ keepalive_timeout 10;
44
+
45
+ error_page 500 502 504 /500.html;
46
+ error_page 503 @503;
47
+
48
+ location @puma_<%= fetch(:nginx_config_unit) %> {
49
+ proxy_http_version 1.1;
50
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
51
+ proxy_set_header X-Forwarded-Proto $scheme;
52
+ proxy_set_header Host $host;
53
+ proxy_redirect off;
54
+ proxy_set_header Upgrade $http_upgrade;
55
+ proxy_set_header Connection "Upgrade";
56
+ <% if fetch(:nginx_use_ssl) -%>
57
+ proxy_set_header X-Forwarded-Proto https;
58
+ # custom
59
+ proxy_set_header X-Forwarded-Ssl on;
60
+ <% else -%>
61
+ <% if fetch(:nginx_downstream_uses_ssl) -%>
62
+ proxy_set_header X-Forwarded-Proto https;
63
+ <% else -%>
64
+ proxy_set_header X-Forwarded-Proto http;
65
+ <% end -%>
66
+ <% end -%>
67
+
68
+ # custom
69
+ proxy_set_header X-Forwarded-Port $server_port;
70
+ proxy_set_header X-Forwarded-Host $host;
71
+
72
+ proxy_pass http://puma_<%= fetch(:nginx_config_unit) %>;
73
+ # limit_req zone=one;
74
+ access_log /var/log/nginx/<%= fetch(:nginx_config_unit) %>.access.log;
75
+ error_log /var/log/nginx/<%= fetch(:nginx_config_unit) %>.error.log;
76
+ }
77
+
78
+ location ^~ /assets/ {
79
+ gzip_static on;
80
+ expires max;
81
+ add_header Cache-Control public;
82
+ }
83
+
84
+ location @503 {
85
+ error_page 405 = /system/maintenance.html;
86
+ if (-f $document_root/system/maintenance.html) {
87
+ rewrite ^(.*)$ /system/maintenance.html break;
88
+ }
89
+ rewrite ^(.*)$ /503.html break;
90
+ }
91
+
92
+ if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
93
+ return 405;
94
+ }
95
+
96
+ if (-f $document_root/system/maintenance.html) {
97
+ return 503;
98
+ }
99
+ }
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mina/nginx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mina-puma-nginx'
8
+ spec.version = Mina::Nginx::VERSION
9
+ spec.authors = ['Vladimir Elchinov']
10
+ spec.email = ['elik@elik.ru']
11
+ spec.summary = %(Mina tasks for handle with Nginx.)
12
+ spec.description = %(Configuration and managements Mina tasks for Nginx.)
13
+ spec.homepage = 'https://github.com/railsblueprint/mina-puma-nginx.git'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($RS)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'mina'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 0'
25
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-puma-nginx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Elchinov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mina
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Configuration and managements Mina tasks for Nginx.
56
+ email:
57
+ - elik@elik.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/mina/nginx.rb
68
+ - lib/mina/nginx/version.rb
69
+ - lib/mina/templates/nginx.conf.erb
70
+ - mina-puma-nginx.gemspec
71
+ homepage: https://github.com/railsblueprint/mina-puma-nginx.git
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.0.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Mina tasks for handle with Nginx.
94
+ test_files: []