dockerfile-rails 1.5.1 → 1.5.3

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: 1aca228134c031de432e9c059c2451da36827f11334c25498506e1dc1a5f7819
4
- data.tar.gz: b661bfc9e1d9a3aafa0a10181a33927616e06162bb4ea24f960d33ff5598337c
3
+ metadata.gz: b14b8dc852c4d34ae6fa48251cb680e89a9c08fe81942d336d21f18418643e38
4
+ data.tar.gz: 3d61361b94688abd9545d59a43cb22fda5fc4ecd947353a7397ee88e5cfa0b68
5
5
  SHA512:
6
- metadata.gz: b432aedcdafad7b3aea076ad4501252aa2dc51f3cd980be1e6d4761d43b57773ec76ebc862d4f9cdd8526f1d5e3cf77c5f24b48d615fe558e0055b54aabd0803
7
- data.tar.gz: c20b0900280252cef4eab686b3f0b2718e99e46779504174fd4898d86ec68868607acc1cc5179d5c815334c2d911e0bd587169dfe6ca023af40e2caa743f66fc
6
+ metadata.gz: becc43052f96c77dc89fa920039c43151737bfd284a8b533185e7334989506b28db8c6ab87da9748712c9c52de0cb7b344ef0308992d4306fc7b47a6be0eeac6
7
+ data.tar.gz: 11210697f2034ea5295611f7b6548cad9e5712bdd8906e0acc083edde2e35404f51c22fb2624d8e4c087c02be7319c6f71a7f76d98f5054f85d6472012767fbc
data/README.md CHANGED
@@ -46,6 +46,10 @@ bin/rails generate dockerfile
46
46
  * `--no-lock` - don't add linux platforms, set `BUNDLE_DEPLOY`, or `--frozen-lockfile`. May be needed at times to work around a [rubygems bug](https://github.com/rubygems/rubygems/issues/6082#issuecomment-1329756343).
47
47
  * `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment
48
48
 
49
+ #### Error Tracking & Alerting:
50
+ * `--rollbar` - install gem and a default initializer for [Rollbar](https://rollbar.com/#)
51
+ * `--sentry` - install gems and a default initializer for [Sentry](https://sentry.io/welcome/)
52
+
49
53
  ### Add a Database:
50
54
 
51
55
  Generally the dockerfile generator will be able to determine what dependencies you
@@ -31,8 +31,10 @@ class DockerfileGenerator < Rails::Generators::Base
31
31
  "procfile" => "",
32
32
  "redis" => false,
33
33
  "registry" => "",
34
+ "rollbar" => false,
34
35
  "root" => false,
35
36
  "sqlite3" => false,
37
+ "sentry" => false,
36
38
  "sudo" => false,
37
39
  "swap" => nil,
38
40
  "variant" => "slim",
@@ -169,6 +171,12 @@ class DockerfileGenerator < Rails::Generators::Base
169
171
  class_option :sudo, type: :boolean, default: OPTION_DEFAULTS.sudo,
170
172
  desc: "Install and configure sudo to enable running as rails with full environment"
171
173
 
174
+ class_option :sentry, type: :boolean, default: OPTION_DEFAULTS.sentry,
175
+ desc: "Install gems and a default initializer for Sentry"
176
+
177
+ class_option :rollbar, type: :boolean, default: OPTION_DEFAULTS.rollbar,
178
+ desc: "Install gem and a default initializer for Rollbar"
179
+
172
180
  class_option "migrate", type: :string, default: OPTION_DEFAULTS.migrate,
173
181
  desc: "custom migration/db:prepare script"
174
182
 
@@ -282,7 +290,7 @@ class DockerfileGenerator < Rails::Generators::Base
282
290
  fly_attach_consul
283
291
  end
284
292
 
285
- if File.exist?("fly.toml") && (fly_processes || !options.prepare)
293
+ if File.exist?("fly.toml") && (fly_processes || !options.prepare || options.swap)
286
294
  if File.stat("fly.toml").size > 0
287
295
  template "fly.toml.erb", "fly.toml"
288
296
  else
@@ -291,6 +299,14 @@ class DockerfileGenerator < Rails::Generators::Base
291
299
  end
292
300
  end
293
301
 
302
+ if options.sentry? && (not File.exist?("config/initializers/sentry.rb"))
303
+ template "sentry.rb.erb", "config/initializers/sentry.rb"
304
+ end
305
+
306
+ if options.rollbar? && (not File.exist?("config/initializers/rollbar.rb"))
307
+ template "rollbar.rb.erb", "config/initializers/rollbar.rb"
308
+ end
309
+
294
310
  if @gemfile.include?("vite_ruby")
295
311
  package = JSON.load_file("package.json")
296
312
  unless package.dig("scripts", "build")
@@ -432,6 +448,15 @@ private
432
448
  system "bundle add redis --skip-install" unless @gemfile.include? "redis"
433
449
  end
434
450
 
451
+ if options.sentry?
452
+ system "bundle add sentry-ruby --skip-install" unless @gemfile.include? "sentry-ruby"
453
+ system "bundle add sentry-rails --skip-install" unless @gemfile.include? "sentry-rails"
454
+ end
455
+
456
+ if options.rollbar?
457
+ system "bundle add rollbar --skip-install" unless @gemfile.include? "rollbar"
458
+ end
459
+
435
460
  # https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp/70500221#70500221
436
461
  if @gemfile.include? "mail"
437
462
  %w(net-smtp net-imap net-pop).each do |gem|
@@ -644,7 +669,7 @@ private
644
669
  repos += [
645
670
  "curl https://dl-ssl.google.com/linux/linux_signing_key.pub |",
646
671
  " gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg &&",
647
- 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
672
+ 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
648
673
  ]
649
674
  end
650
675
 
@@ -723,12 +748,7 @@ private
723
748
  end
724
749
 
725
750
  if options.jemalloc? && !options.fullstaq?
726
- if (options.platform || Gem::Platform.local.cpu).include? "arm"
727
- env["LD_PRELOAD"] = "/usr/lib/aarch64-linux-gnu/libjemalloc.so.2"
728
- else
729
- env["LD_PRELOAD"] = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
730
- end
731
-
751
+ env["LD_PRELOAD"] = "libjemalloc.so.2"
732
752
  env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
733
753
  end
734
754
 
@@ -1078,6 +1098,29 @@ private
1078
1098
  end
1079
1099
  end
1080
1100
 
1101
+ if options.swap
1102
+ suffixes = {
1103
+ "kib" => 1024,
1104
+ "k" => 1024,
1105
+ "kb" => 1000,
1106
+ "mib" => 1048576,
1107
+ "m" => 1048576,
1108
+ "mb" => 100000,
1109
+ "gib" => 1073741824,
1110
+ "g" => 1073741824,
1111
+ "gb" => 100000000,
1112
+ }
1113
+
1114
+ pattern = Regexp.new("^(\\d+)(#{suffixes.keys.join('|')})?$", "i")
1115
+
1116
+ match = pattern.match(options.swap.downcase)
1117
+
1118
+ if match
1119
+ size = ((match[1].to_i * (suffixes[match[2]] || 1)) / 1048576.0).round
1120
+ toml += "swap_size_mb = #{size}"
1121
+ end
1122
+ end
1123
+
1081
1124
  toml
1082
1125
  end
1083
1126
  end
@@ -3,14 +3,14 @@ RUN gem install foreman && \
3
3
  <% unless run_as_root? -%>
4
4
  sed -i 's|pid /run|pid /rails/tmp/pids|' /etc/nginx/nginx.conf && \
5
5
  <% end -%>
6
- sed -i 's/access_log\s.*;/access_log \/dev\/stdout;/' /etc/nginx/nginx.conf && \
7
- sed -i 's/error_log\s.*;/error_log \/dev\/stderr info;/' /etc/nginx/nginx.conf
6
+ sed -i 's/access_log\s.*;/access_log <% unless run_as_root? %>\/dev\/<% end %>stdout;/' /etc/nginx/nginx.conf && \
7
+ sed -i 's/error_log\s.*;/error_log <% unless run_as_root? %>\/dev\/<% end %>stderr info;/' /etc/nginx/nginx.conf
8
8
 
9
9
  COPY <<-"EOF" /etc/nginx/sites-available/default
10
10
  server {
11
11
  listen 3000 default_server;
12
12
  listen [::]:3000 default_server;
13
- access_log /dev/stdout;
13
+ access_log <% unless run_as_root? %>/dev/<% end %>stdout;
14
14
 
15
15
  root /rails/public;
16
16
 
@@ -28,7 +28,7 @@ server {
28
28
 
29
29
  location @backend {
30
30
  proxy_pass http://localhost:3001;
31
- proxy_set_header origin 'http://localhost:3000';
31
+ proxy_set_header Host $http_host;
32
32
  }
33
33
  }
34
34
  EOF
@@ -10,6 +10,7 @@ server {
10
10
  passenger_pool_idle_time <%= max_idle %>;
11
11
  <% end -%>
12
12
  }
13
+ EOF
13
14
  <% if options['max-idle'] -%>
14
15
  COPY <<-'EOF' /etc/nginx/sites-enabled/hook_detached_process
15
16
  #!/usr/bin/env ruby
@@ -18,12 +19,11 @@ processes = status[/^Processes\s*:\s*(\d*)/, 1].to_i
18
19
  system 'nginx -s stop' if processes == 0
19
20
  EOF
20
21
  <% end -%>
21
- EOF
22
22
  RUN echo "daemon off;" >> /etc/nginx/nginx.conf && \
23
- sed -i 's/access_log\s.*;/access_log \/dev\/stdout;/' /etc/nginx/nginx.conf && \
24
- sed -i 's/error_log\s.*;/error_log \/dev\/stderr info;/' /etc/nginx/nginx.conf && \
23
+ sed -i 's/access_log\s.*;/access_log stdout;/' /etc/nginx/nginx.conf && \
24
+ sed -i 's/error_log\s.*;/error_log stderr info;/' /etc/nginx/nginx.conf && \
25
25
  <% if options['max-idle'] -%>
26
26
  chmod +sx /etc/nginx/sites-enabled/hook_detached_process && \
27
27
  <% end -%>
28
28
  sed -i 's/user www-data/user rails/' /etc/nginx/nginx.conf && \
29
- mkdir /var/run/passenger-instreg
29
+ mkdir /var/run/passenger-instreg
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash -e
2
2
 
3
- <% if options.swap -%>
3
+ <% if options.swap && !File.exist?("fly.toml")-%>
4
4
  <% if run_as_root? or using_passenger? -%>
5
5
  <% @space = "" -%>
6
6
  <% else -%>
@@ -0,0 +1,73 @@
1
+ if ENV['ROLLBAR_ENV']
2
+ Rollbar.configure do |config|
3
+ # Without configuration, Rollbar is enabled in all environments.
4
+ # To disable in specific environments, set config.enabled=false.
5
+
6
+ config.access_token = ENV['ROLLBAR_ACCESS_TOKEN']
7
+
8
+ # Here we'll disable in 'test':
9
+ if Rails.env.test?
10
+ config.enabled = false
11
+ end
12
+
13
+ # By default, Rollbar will try to call the `current_user` controller method
14
+ # to fetch the logged-in user object, and then call that object's `id`
15
+ # method to fetch this property. To customize:
16
+ # config.person_method = "my_current_user"
17
+ # config.person_id_method = "my_id"
18
+
19
+ # Additionally, you may specify the following:
20
+ # config.person_username_method = "username"
21
+ # config.person_email_method = "email"
22
+
23
+ # If you want to attach custom data to all exception and message reports,
24
+ # provide a lambda like the following. It should return a hash.
25
+ # config.custom_data_method = lambda { {:some_key => "some_value" } }
26
+
27
+ # Add exception class names to the exception_level_filters hash to
28
+ # change the level that exception is reported at. Note that if an exception
29
+ # has already been reported and logged the level will need to be changed
30
+ # via the rollbar interface.
31
+ # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
32
+ # 'ignore' will cause the exception to not be reported at all.
33
+ # config.exception_level_filters.merge!('MyCriticalException' => 'critical')
34
+ #
35
+ # You can also specify a callable, which will be called with the exception instance.
36
+ # config.exception_level_filters.merge!('MyCriticalException' => lambda { |e| 'critical' })
37
+
38
+ # Enable asynchronous reporting (uses girl_friday or Threading if girl_friday
39
+ # is not installed)
40
+ # config.use_async = true
41
+ # Supply your own async handler:
42
+ # config.async_handler = Proc.new { |payload|
43
+ # Thread.new { Rollbar.process_from_async_handler(payload) }
44
+ # }
45
+
46
+ # Enable asynchronous reporting (using sucker_punch)
47
+ # config.use_sucker_punch
48
+
49
+ # Enable delayed reporting (using Sidekiq)
50
+ # config.use_sidekiq
51
+ # You can supply custom Sidekiq options:
52
+ # config.use_sidekiq 'queue' => 'default'
53
+
54
+ # If your application runs behind a proxy server, you can set proxy parameters here.
55
+ # If https_proxy is set in your environment, that will be used. Settings here have precedence.
56
+ # The :host key is mandatory and must include the URL scheme (e.g. 'http://'), all other fields
57
+ # are optional.
58
+ #
59
+ # config.proxy = {
60
+ # host: 'http://some.proxy.server',
61
+ # port: 80,
62
+ # user: 'username_if_auth_required',
63
+ # password: 'password_if_auth_required'
64
+ # }
65
+
66
+ # If you run your staging application instance in production environment then
67
+ # you'll want to override the environment reported by `Rails.env` with an
68
+ # environment variable like this: `ROLLBAR_ENV=staging`. This is a recommended
69
+ # setup for Heroku. See:
70
+ # https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment
71
+ config.environment = ENV['ROLLBAR_ENV'].presence || Rails.env
72
+ end
73
+ end
@@ -0,0 +1,17 @@
1
+ if ENV["SENTRY_DSN"]
2
+
3
+ Sentry.init do |config|
4
+ config.dsn = ENV["SENTRY_DSN"]
5
+ config.breadcrumbs_logger = [:active_support_logger, :http_logger]
6
+
7
+ # Set traces_sample_rate to 1.0 to capture 100%
8
+ # of transactions for performance monitoring.
9
+ # We recommend adjusting this value in production.
10
+ config.traces_sample_rate = 1.0
11
+ # or
12
+ config.traces_sampler = lambda do |context|
13
+ true
14
+ end
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerfile-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-01 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,8 @@ files:
52
52
  - lib/generators/templates/fly.toml.erb
53
53
  - lib/generators/templates/litefs.yml.erb
54
54
  - lib/generators/templates/node-version.erb
55
+ - lib/generators/templates/rollbar.rb.erb
56
+ - lib/generators/templates/sentry.rb.erb
55
57
  homepage: https://github.com/fly-apps/dockerfile-rails
56
58
  licenses:
57
59
  - MIT