rails-nginx 1.0.0.pre.alpha → 1.0.0.pre.beta

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
  SHA256:
3
- metadata.gz: 15c1730eca41e2227f246633756a27130a5e4c5bf87796a9a88893357be441a4
4
- data.tar.gz: a372053d911522bf503522ebed38b8a2605bd91032541210a5ffd8092d02d88d
3
+ metadata.gz: b509ef92a5f9976f4a3861fef1049fd3d2002cc28600292da5221898508712b7
4
+ data.tar.gz: a2dfd4812dfedbfed4d50c0d03b930fbd8d37c3eae58d31ec9e3f6ce94fb98a9
5
5
  SHA512:
6
- metadata.gz: 83d060932d2b1c76be3081b280525e893f918e0d10350827e67add23352d0c0da1eb25a8d2ccfb7c3e47626154b4199000ef0913a0744952f5696b78b09f86f4
7
- data.tar.gz: a4314d08cbb951387f5a20420187f91916f841aa355752e55180c11e2a66fd3e5042a6124630ab44302d0e8cfafeb02c3bbc0af6795af53fd384a625b3704f4b
6
+ metadata.gz: f2f8e5d2cd168828389987d512b4fc44000b0556ffff35c131f3a16c716fed5ea6a4292099e6d8106be725ec1c28fb0b0dd1a96423193440757e1b381eb2713f
7
+ data.tar.gz: 01f238f9c4e310ff12f41d19dd44ebbf319d040ebb1c95f8cd0dc5d14a700f8e7b573f75f0016377105f14668e33544114c86a714867f4d8bdca199781435589
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0-alpha.1] - 2024-11-22
4
+
5
+ Added missing require for the gem's VERSION file.
6
+
3
7
  ## [1.0.0-alpha] - 2024-11-21
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -1,15 +1,39 @@
1
1
  # Rails NGINX
2
2
 
3
- Automatically configure NGINX with SSL upon boot for Rails applications.
3
+ Rails Puma plugin convenience wrapper for Ruby NGINX. Take a look at the [Ruby NGINX project documentation](https://github.com/bert-mccutchen/ruby-nginx) for more in depth details.
4
4
 
5
- 1. ERB for NGINX configuration templating.
6
- 2. Mkcert for SSL certificate generation.
7
- 3. Tried and true NGINX for reverse proxying.
5
+ :heart: ERB for NGINX configuration templating.
8
6
 
9
- This gem is intended to be an aid to your development environment. **Don't use this in production.**
7
+ :yellow_heart: Self-signed certificate generation via mkcert for HTTPS.
8
+
9
+ :green_heart: Tried and true NGINX for reverse proxying, and hosts mapping for DNS.
10
10
 
11
11
  [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/M4M76DVZR)
12
12
 
13
+ ---
14
+
15
+ > [!WARNING]
16
+ >This gem is intended to be an aid to your development environment - powered by [Ruby NGINX](https://github.com/bert-mccutchen/ruby-nginx). **Don't use this gem in production.**
17
+
18
+ ---
19
+
20
+ ### Contents
21
+
22
+ - [Installation](#installation)
23
+ - [Usage](#usage)
24
+ - [Basic Usage](#basic-usage)
25
+ - [Default Configuration](#default-configuration)
26
+ - [Advanced Usage](#advanced-usage)
27
+ - [Multiple Configurations](#multiple-configurations)
28
+ - [Inheriting Configurations](#inheriting-configurations)
29
+ - [Development](#development)
30
+ - [Setup](#setup)
31
+ - [Lint / Test](#lint--test)
32
+ - [Debug Console](#debug-console)
33
+ - [Release](#release)
34
+ - [Contributing](#contributing)
35
+ - [License](#license)
36
+
13
37
  ## Installation
14
38
 
15
39
  Install via Bundler:
@@ -24,44 +48,141 @@ gem install rails-nginx
24
48
 
25
49
  ## Usage
26
50
 
27
- ### config/puma.rb
28
- ```ruby
29
- port ENV.fetch('PORT') { 3000 } unless Rails.env.development?
51
+ ### Basic Usage
52
+
53
+ Add the Puma plugin to your configuration, and limit it to your development environment.
30
54
 
55
+ **config/puma.rb**
56
+ ```ruby
31
57
  plugin :rails_nginx if Rails.env.development?
58
+ ```
32
59
 
33
- # All configuration is entirely optional, the following blocks are not required.
34
- rails_nginx_config(:primary) do |config|
35
- config[:domain] = 'route1.spline-reticulator.test' # default eg. rails-app-name.test
36
- config[:host] = '0.0.0.0' # default '127.0.0.1'
37
- config[:root_path] = './public' # default `Rails.public_path`
38
- config[:ssl] = false # default true
39
- config[:log] = false # default true
60
+ > [!IMPORTANT]
61
+ > **If you skip this, NGINX reverse proxy will have a randomized port while Puma will not. The reverse proxy will not work.**
62
+ >
63
+ > Puma's `port` configuration option makes it impossible for Rails NGINX to assign a random open port back to Puma.
64
+ >
65
+ > To fix this issue, simply remove it from our Puma configuration.
66
+ >
67
+ > **config/puma.rb**
68
+ > ```ruby
69
+ > port ENV.fetch("PORT") { 3000 }
70
+ > ```
71
+ >
72
+ > OR simply disable it in your development environment:
73
+ > ```ruby
74
+ > port ENV.fetch("PORT") { 3000 } unless Rails.env.development?
75
+ > ```
76
+ >
77
+ > OR always manually provide an open port when starting Rails:
78
+ > ```
79
+ > ./bin/rails server -p 3001
80
+ > ```
81
+
82
+ ### Default Configuration
83
+ By default, Rails NGINX will configure [Ruby NGINX](https://github.com/bert-mccutchen/ruby-nginx) with the following options. For the examples, pretend I have an application called "HelloWorld".
84
+
85
+ | Option | Default | Example |
86
+ |---|---|---|
87
+ | `domain` | Your rails app name as dashes, with the test TLD. | `hello-world.test` |
88
+ | `host` | `127.0.0.1` | |
89
+ | `root_path` | `Rails.public_path` | `/home/bert/hello_world/public` |
90
+ | `ssl` | `true` | |
91
+ | `log` | `true` | |
92
+ | `ssl_certificate_path` | `Rails.root` + `tmp/nginx/_[DOMAIN].pem` | `/home/bert/hello_world/tmp/nginx/_hello-world.test.pem` |
93
+ | `ssl_certificate_key_path` | `Rails.root` + `tmp/nginx/_[DOMAIN]-key.pem` | `/home/bert/hello_world/tmp/nginx/_hello-world.test-key.pem` |
94
+ | `access_log_path` | `Rails.root` + `log/nginx/[DOMAIN].access.log` | `/home/bert/hello_world/log/hello-world.test.access.log` |
95
+ | `error_log_path` | `Rails.root` + `log/nginx/[DOMAIN].error.log` | `/home/bert/hello_world/log/hello-world.test.error.log` |
96
+
97
+ ### Advanced Usage
98
+
99
+ You can override all the default values and provide your own configuration. Rails NGINX will use your configuration automatically if one is present. Default values are retained if not overridden.
100
+
101
+ **config/puma.rb**
102
+ ```ruby
103
+ rails_nginx_config do |config|
104
+ config[:domain] = "example.test"
105
+ config[:host] = "localhost"
106
+ # etc.
107
+ end
108
+ ```
109
+
110
+ #### Multiple Configurations
111
+
112
+ Let's say you have a multi-tenant Rails application, and you want to simulate the application running behind two separate domains in your development environment. No problem, Rails NGINX can support multiple configurations, no matter how wildly different they may be.
113
+
114
+ **config/puma.rb**
115
+ ```ruby
116
+ rails_nginx_config(:work) do |config|
117
+ config[:domain] = "work.todo-list.test"
118
+ config[:ssl] = true
119
+ config[:log] = true
40
120
 
41
- # default location Rails.root + tmp/nginx/
42
- config[:ssl_certificate_path] = './tmp/certs/_spline-reticulator.test.pem'
43
- config[:ssl_certificate_key_path] = './tmp/certs/_spline-reticulator-key.test.pem'
121
+ config[:ssl_certificate_path] = "~/work/my-cert.pem"
122
+ config[:ssl_certificate_key_path] = "~/work/my-cert-key.pem"
44
123
 
45
124
  # default location Rails.root + log/nginx/
46
- config[:access_log_path] = './log/route1.nginx.access.log'
47
- config[:error_log_path] = './log/route1.nginx.error.log'
125
+ config[:access_log_path] = "~/work/logs/todo-list.access.log"
126
+ config[:error_log_path] = "~/work/logs/todo-list.error.log"
127
+ end
128
+
129
+ rails_nginx_config(:home) do |config|
130
+ config[:domain] = "home.todo-list.test"
131
+ config[:ssl] = false
132
+ config[:log] = false
48
133
  end
134
+ ```
135
+
136
+ #### Inheriting Configurations
49
137
 
50
- # You can define multiple configurations and all will be created on puma boot.
51
- rails_nginx_config(:secondary) do |config|
52
- config.merge!(rails_nginx_config(:primary))
138
+ Since Rails NGINX configurations are a simple Ruby Hash, you can merge configurations to prevent needless duplication. This is possible because Rails NGINX allows you to read back previously defined configurations.
53
139
 
54
- config[:domain] = 'route2.spline-reticulator.test'
55
- config[:access_log_path] = './log/route2.nginx.access.log'
56
- config[:error_log_path] = './log/route2.nginx.error.log'
140
+ **config/puma.rb**
141
+ ```ruby
142
+ rails_nginx_config(:kids) do |config|
143
+ config.merge!(rails_nginx_config(:home))
144
+
145
+ config[:domain] = "kids.todo-list.test"
146
+ config[:log] = true
57
147
  end
58
148
  ```
59
149
 
60
150
  ## Development
61
151
 
62
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
152
+ ### Setup
153
+
154
+ Install development dependencies.
155
+ ```
156
+ ./bin/setup
157
+ ```
158
+
159
+ ### Lint / Test
160
+
161
+ Run the Standard Ruby linter, and RSpec test suite.
162
+ ```
163
+ bundle exec rake
164
+ ```
165
+
166
+ #### Generating a new Dummy server
167
+
168
+ There's a built-in executable if you'd like to generate a new Dummy server to upgrade the regression tests to work with the latest version of Rails.
169
+
170
+ This executable will delete the current `spec/dummy` directory, update the `rails` gem to the latest version, and generate a new `spec/dummy` application using the options defined in the `.dummy.railsrc` file.
171
+ ```
172
+ ./bin/dummy
173
+ ```
174
+
175
+ ### Debug Console
176
+
177
+ Start an interactive Ruby console (IRB).
178
+ ```
179
+ ./bin/console
180
+ ```
181
+
182
+ ### Release
183
+
184
+ A new release will automatically be built and uploaded to RubyGems by a [GitHub Actions workflow](./.github/workflows/gem-push.yml) upon the push of a new Git tag.
63
185
 
64
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
186
 
66
187
  ## Contributing
67
188
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rails
4
4
  module Nginx
5
- VERSION = "1.0.0-alpha"
5
+ VERSION = "1.0.0-beta"
6
6
  end
7
7
  end
data/lib/rails/nginx.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "socket"
4
4
  require "ruby/nginx"
5
+ require_relative "nginx/version"
5
6
 
6
7
  module Rails
7
8
  module Nginx
@@ -16,13 +17,17 @@ module Rails
16
17
 
17
18
  config = Ruby::Nginx.add!(options.reverse_merge(defaults(options)), &block)
18
19
 
19
- puts start_message(config.options) # rubocop:disable Rails/Output
20
+ puts start_message(config.options)
21
+ rescue Ruby::Nginx::Error => e
22
+ abort "[Ruby::Nginx] #{e.message}"
20
23
  end
21
24
 
22
25
  def self.stop!(options = {}, &block)
23
26
  return unless rails_server?
24
27
 
25
28
  Ruby::Nginx.remove!(options.reverse_merge(defaults(options)), &block)
29
+ rescue Ruby::Nginx::Error => e
30
+ abort "[Ruby::Nginx] #{e.message}"
26
31
  end
27
32
 
28
33
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha
4
+ version: 1.0.0.pre.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bert McCutchen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-22 00:00:00.000000000 Z
11
+ date: 2025-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -74,7 +74,7 @@ metadata:
74
74
  source_code_uri: https://github.com/bert-mccutchen/rails-nginx
75
75
  changelog_uri: https://github.com/bert-mccutchen/rails-nginx/blob/main/CHANGELOG.md
76
76
  rubygems_mfa_required: 'true'
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubygems_version: 3.5.22
93
- signing_key:
93
+ signing_key:
94
94
  specification_version: 4
95
95
  summary: Automatic NGINX+SSL configuration for Rails.
96
96
  test_files: []