dockerfile-rails 1.5.2 → 1.5.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
  SHA256:
3
- metadata.gz: d8ce323b4347b43694278ab3b78c36c300deef6c88acff15e3a5c6e66ef5a0ad
4
- data.tar.gz: 507e7a76e5f38761f3d729b665d93f231185ffc07edd3665ca88a034244a1dc3
3
+ metadata.gz: fb14492c49c1cf3daf989207c2188413c0311a317a95727330fcec570f79632c
4
+ data.tar.gz: c18d7c536626010b3befe71e23ef8c99b53095680e7050dfbcfecd59960cba91
5
5
  SHA512:
6
- metadata.gz: d9d99879f76d1e9d1e4f601db989b5d6a80e3b4113456827e2b0ab17a495163fb14925c6a6ea34ed760f2921fe482ccfc377e89382e40c10681d3423da6c3f16
7
- data.tar.gz: 40a0a469845941a12367aa5f1a7e54f7834a8b07ac081b9bdcf922d30c57d02d75dc994c7b6d1c77e301fac2142e7dcac29551b443286a9c51342582ac043aaa
6
+ metadata.gz: 50725e7ac313645b93fddb4742a2e711b08e01ba1c593bd0126a70135d04f7467b9d2caa476eb2642903392fc805e2a38ff811aede86c4a2c23843aa30be0189
7
+ data.tar.gz: 85c0608fc27c115b95d42ddeef4b86b2e5c6be63f652338d01d4b24886686036e2572bab94356f41b3f6e18123d07370b2982f4b224eba34997ef0707381f557
data/README.md CHANGED
@@ -44,9 +44,12 @@ bin/rails generate dockerfile
44
44
  * `--nginx` - serve static files via [nginx](https://www.nginx.com/). May require `--root` on some targets to access `/dev/stdout`
45
45
  * `--no-link` - don't add [--link](https://docs.docker.com/engine/reference/builder/#copy---link) to COPY statements. Some tools (like at the moment, [buildah](https://www.redhat.com/en/topics/containers/what-is-buildah)) don't yet support this feature.
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
- * `--sentry` -- install gems and a starter initializer for sentry
48
47
  * `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment
49
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
+
50
53
  ### Add a Database:
51
54
 
52
55
  Generally the dockerfile generator will be able to determine what dependencies you
@@ -82,6 +85,7 @@ Not all of your needs can be determined by scanning your application. For examp
82
85
  * `--precompile=defer` - may be needed when your configuration requires access to secrets that are not available at build time. Results in larger images and slower deployments.
83
86
  * `--root` - run application as root
84
87
  * `--windows` - make Dockerfile work for Windows users that may have set `git config --global core.autocrlf true`
88
+ * `--private-gemserver-domain=gems.example.com` - set the domain name of your private gemserver. This is used to tell bundler for what domain to use the credentials of a private gemserver provided via a docker secret
85
89
 
86
90
  ### Advanced Customization:
87
91
 
@@ -116,7 +120,7 @@ rake test
116
120
  ruby test/test_minimal.rb
117
121
  ```
118
122
 
119
- To assis with this process, outputs of tests can be captured automatically. This is useful when adding new tests and when making a change that affects many tests. Be sure to inspect the output (e.g., by using `git diff`) before committing.
123
+ To assist with this process, outputs of tests can be captured automatically. This is useful when adding new tests and when making a change that affects many tests. Be sure to inspect the output (e.g., by using `git diff`) before committing.
120
124
 
121
125
  ```
122
126
  rake test:capture
@@ -28,9 +28,11 @@ class DockerfileGenerator < Rails::Generators::Base
28
28
  "postgresql" => false,
29
29
  "precompile" => nil,
30
30
  "prepare" => true,
31
+ "private-gemserver-domain" => nil,
31
32
  "procfile" => "",
32
33
  "redis" => false,
33
34
  "registry" => "",
35
+ "rollbar" => false,
34
36
  "root" => false,
35
37
  "sqlite3" => false,
36
38
  "sentry" => false,
@@ -171,7 +173,10 @@ class DockerfileGenerator < Rails::Generators::Base
171
173
  desc: "Install and configure sudo to enable running as rails with full environment"
172
174
 
173
175
  class_option :sentry, type: :boolean, default: OPTION_DEFAULTS.sentry,
174
- desc: "Install gems and a starter initializer for sentry"
176
+ desc: "Install gems and a default initializer for Sentry"
177
+
178
+ class_option :rollbar, type: :boolean, default: OPTION_DEFAULTS.rollbar,
179
+ desc: "Install gem and a default initializer for Rollbar"
175
180
 
176
181
  class_option "migrate", type: :string, default: OPTION_DEFAULTS.migrate,
177
182
  desc: "custom migration/db:prepare script"
@@ -179,6 +184,9 @@ class DockerfileGenerator < Rails::Generators::Base
179
184
  class_option "procfile", type: :string, default: OPTION_DEFAULTS.procfile,
180
185
  desc: "custom procfile to start services"
181
186
 
187
+ class_option "private-gemserver-domain", type: :string, default: OPTION_DEFAULTS["private-gemserver-domain"],
188
+ desc: "domain name of a private gemserver used when installing application gems"
189
+
182
190
 
183
191
  class_option "add-base", type: :array, default: [],
184
192
  desc: "additional packages to install for both build and deploy"
@@ -299,6 +307,10 @@ class DockerfileGenerator < Rails::Generators::Base
299
307
  template "sentry.rb.erb", "config/initializers/sentry.rb"
300
308
  end
301
309
 
310
+ if options.rollbar? && (not File.exist?("config/initializers/rollbar.rb"))
311
+ template "rollbar.rb.erb", "config/initializers/rollbar.rb"
312
+ end
313
+
302
314
  if @gemfile.include?("vite_ruby")
303
315
  package = JSON.load_file("package.json")
304
316
  unless package.dig("scripts", "build")
@@ -445,6 +457,10 @@ private
445
457
  system "bundle add sentry-rails --skip-install" unless @gemfile.include? "sentry-rails"
446
458
  end
447
459
 
460
+ if options.rollbar?
461
+ system "bundle add rollbar --skip-install" unless @gemfile.include? "rollbar"
462
+ end
463
+
448
464
  # https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp/70500221#70500221
449
465
  if @gemfile.include? "mail"
450
466
  %w(net-smtp net-imap net-pop).each do |gem|
@@ -526,6 +542,7 @@ private
526
542
  # start with the essentials
527
543
  packages = %w(build-essential)
528
544
  packages += @@packages["build"] if @@packages["build"]
545
+ packages += %w(nodejs npm) if node_version == "lts"
529
546
 
530
547
  # add databases: sqlite3, postgres, mysql
531
548
  packages << "pkg-config" if options.sqlite3? || @sqlite3
@@ -837,7 +854,9 @@ private
837
854
 
838
855
  def binfile_fixups
839
856
  # binfiles may have OS specific paths to ruby. Normalize them.
840
- shebangs = Dir["bin/*"].map { |file| IO.read(file).lines.first }.join
857
+ shebangs = Dir["bin/*"].map do |file|
858
+ IO.read(file).lines.first.encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "")
859
+ end.join
841
860
  rubies = shebangs.scan(%r{#!/usr/bin/env (ruby.*)}).flatten.uniq
842
861
 
843
862
  binfixups = (rubies - %w(ruby)).map do |ruby|
@@ -1027,6 +1046,19 @@ private
1027
1046
  nil
1028
1047
  end
1029
1048
 
1049
+ # Takes the domain of the private gemserver and returns the name of the
1050
+ # environment variable, as expected by bundler.
1051
+ #
1052
+ # For example, if the domain is "gems.example.com", the environment variable
1053
+ # name will be "BUNDLE_GEMS__EXAMPLE__COM".
1054
+ def private_gemserver_env_variable_name
1055
+ option = options["private-gemserver-domain"]
1056
+
1057
+ return nil if option.blank?
1058
+
1059
+ "BUNDLE_#{option.upcase.gsub(".", "__")}"
1060
+ end
1061
+
1030
1062
  # if running on fly v2, make a best effort to attach consul
1031
1063
  def fly_attach_consul
1032
1064
  # certainly not fly unless there is a fly.toml
@@ -86,10 +86,15 @@ ENV <%= build_env.join(" \\\n ") %>
86
86
  COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock ./
87
87
  <% if options.cache? -%>
88
88
  RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
89
+ <% if private_gemserver_env_variable_name -%>
90
+ --mount=type=secret,id=gemserver_credentials,dst=/kaniko/gemserver_credentials \
91
+ <%= private_gemserver_env_variable_name %>="$(cat /kaniko/gemserver_credentials)" && \
92
+ export <%= private_gemserver_env_variable_name %> && \
93
+ <% end -%>
89
94
  bundle config set app_config .bundle && \
90
95
  bundle config set path /srv/vendor && \
91
96
  bundle install && \
92
- <% if depend_on_bootsnap? -%>
97
+ <% if depend_on_bootsnap? && options.precompile != "defer" -%>
93
98
  bundle exec bootsnap precompile --gemfile && \
94
99
  <% end -%>
95
100
  bundle clean && \
@@ -98,8 +103,16 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
98
103
  cp -ar /srv/vendor .
99
104
 
100
105
  <% else -%>
101
- RUN bundle install<% if depend_on_bootsnap? -%> && \
106
+ <% if private_gemserver_env_variable_name -%>
107
+ RUN --mount=type=secret,id=gemserver_credentials,dst=/kaniko/gemserver_credentials \
108
+ <%= private_gemserver_env_variable_name %>="$(cat /kaniko/gemserver_credentials)" && \
109
+ export <%= private_gemserver_env_variable_name %> && \
110
+ bundle install<% if depend_on_bootsnap? && options.precompile != "defer" -%> && \
102
111
  bundle exec bootsnap precompile --gemfile<% end %> && \
112
+ <% else -%>
113
+ RUN bundle install<% if depend_on_bootsnap? && options.precompile != "defer" -%> && \
114
+ bundle exec bootsnap precompile --gemfile<% end %> && \
115
+ <% end -%>
103
116
  rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
104
117
 
105
118
  <% end -%>
@@ -115,7 +128,7 @@ COPY --from=node /usr/local/node /usr/local/node
115
128
  ENV PATH=/usr/local/node/bin:$PATH
116
129
 
117
130
  <% elsif using_node? -%>
118
- <%= render partial: 'npm_install', locals: {sources: Dir[*%w(package.json package-lock.json yarn.lock)]} %>
131
+ <%= render partial: 'npm_install', locals: {sources: Dir[*%w(.npmrc .yarnrc package.json package-lock.json yarn.lock)]} %>
119
132
 
120
133
  <% end -%>
121
134
  # Copy application code
@@ -5,13 +5,13 @@
5
5
  <% elsif yarn_version -%>
6
6
  # Install yarn
7
7
  <% end -%>
8
- <% if node_version -%>
8
+ <% if node_version && node_version != 'lts' -%>
9
9
  ARG NODE_VERSION=<%= node_version %>
10
10
  <% end -%>
11
11
  <% if yarn_version -%>
12
12
  ARG YARN_VERSION=<%= yarn_version %>
13
13
  <% end -%>
14
- <% if node_version -%>
14
+ <% if node_version && node_version != 'lts' -%>
15
15
  ENV PATH=/usr/local/node/bin:$PATH
16
16
  RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
17
17
  /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
@@ -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 stdout;/' /etc/nginx/nginx.conf && \
7
- sed -i 's/error_log\s.*;/error_log 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 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
@@ -1,5 +1,8 @@
1
1
  # Install node modules
2
2
  COPY<% if options.link? %> --link<% end %> <%= sources.join(' ') %> ./
3
+ <% if sources.join.include?('.yarnrc') && !Dir['.yarn/releases/*'].empty? -%>
4
+ COPY<% if options.link? %> --link<% end %> .yarn/releases/* .yarn/releases/
5
+ <% end -%>
3
6
  <% if sources.join.include? 'yarn' -%>
4
7
  RUN <% if options.cache? -%>--mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
5
8
  YARN_CACHE_FOLDER=/root/.yarn <% end -%>yarn install<% if options.lock? %> --frozen-lockfile<% end %>
@@ -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,7 +19,6 @@ 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
23
  sed -i 's/access_log\s.*;/access_log stdout;/' /etc/nginx/nginx.conf && \
24
24
  sed -i 's/error_log\s.*;/error_log stderr info;/' /etc/nginx/nginx.conf && \
@@ -3,6 +3,10 @@ services:
3
3
  web:
4
4
  <% if all_args.empty? -%>
5
5
  build: .
6
+ <% if private_gemserver_env_variable_name -%>
7
+ secrets:
8
+ - gemserver_credentials
9
+ <% end -%>
6
10
  <% else -%>
7
11
  build:
8
12
  context: .
@@ -10,6 +14,10 @@ services:
10
14
  <% all_args.each do |name, value| -%>
11
15
  <%= name %>: <%= value.html_safe? ? value : "\"#{Shellwords.escape(value)}\"" %>
12
16
  <% end -%>
17
+ <% if private_gemserver_env_variable_name -%>
18
+ secrets:
19
+ - gemserver_credentials
20
+ <% end -%>
13
21
  <% end -%>
14
22
  ports:
15
23
  - "3000:3000"
@@ -110,3 +118,9 @@ services:
110
118
  condition: service_healthy
111
119
  <% end -%>
112
120
  <% end -%>
121
+ <% if private_gemserver_env_variable_name -%>
122
+
123
+ secrets:
124
+ gemserver_credentials:
125
+ file: ./GEMSERVER_CREDENTIALS.secret.txt
126
+ <% end -%>
@@ -39,6 +39,11 @@
39
39
  <% end -%>
40
40
  <% unless options.api? -%>
41
41
 
42
+ <% if private_gemserver_env_variable_name -%>
43
+ # Ignore gemserver credentials.
44
+ GEMSERVER_CREDENTIALS.secret.txt
45
+
46
+ <% end -%>
42
47
  # Ignore assets.
43
48
  /node_modules/
44
49
  /app/assets/builds/*
@@ -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
@@ -1,3 +1,5 @@
1
+ if ENV["SENTRY_DSN"]
2
+
1
3
  Sentry.init do |config|
2
4
  config.dsn = ENV["SENTRY_DSN"]
3
5
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]
@@ -10,4 +12,6 @@ Sentry.init do |config|
10
12
  config.traces_sampler = lambda do |context|
11
13
  true
12
14
  end
13
- 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.2
4
+ version: 1.5.4
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-24 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,7 @@ 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
55
56
  - lib/generators/templates/sentry.rb.erb
56
57
  homepage: https://github.com/fly-apps/dockerfile-rails
57
58
  licenses: