dockerfile-rails 1.5.0 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4478af556f6059702ab4b1fce65ab4735a024299796bdebce3014730f3d86220
4
- data.tar.gz: 941e1e7a2fd88238d3ee9dd7fe16ffb2e290e10568fd1ca2ed3e0001d5aceed8
3
+ metadata.gz: d8ce323b4347b43694278ab3b78c36c300deef6c88acff15e3a5c6e66ef5a0ad
4
+ data.tar.gz: 507e7a76e5f38761f3d729b665d93f231185ffc07edd3665ca88a034244a1dc3
5
5
  SHA512:
6
- metadata.gz: ed8adae939c867d565049530df18915c49f0cbd775cc9b909733960ea8b3075b9185132eaf1454e501f7ea211a3f903dca44ce394f20fe356168154d8c2165dd
7
- data.tar.gz: a289a97a457eedd708e9449172b5191685d5f120de3b04df18d6e35950131f681972bf009953967120e32d949b4aede461ac0fb675e14fff8858ccf38de7d522
6
+ metadata.gz: d9d99879f76d1e9d1e4f601db989b5d6a80e3b4113456827e2b0ab17a495163fb14925c6a6ea34ed760f2921fe482ccfc377e89382e40c10681d3423da6c3f16
7
+ data.tar.gz: 40a0a469845941a12367aa5f1a7e54f7834a8b07ac081b9bdcf922d30c57d02d75dc994c7b6d1c77e301fac2142e7dcac29551b443286a9c51342582ac043aaa
data/README.md CHANGED
@@ -44,6 +44,7 @@ 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
47
48
  * `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment
48
49
 
49
50
  ### Add a Database:
@@ -44,7 +44,7 @@ module DockerfileRails
44
44
  @sqlite3 = true
45
45
  elsif database == "postgresql"
46
46
  @postgresql = true
47
- elsif (database == "mysql") || (database == "mysql2")
47
+ elsif (database == "mysql") || (database == "mysql2") || (database == "trilogy")
48
48
  @mysql = true
49
49
  elsif database == "sqlserver"
50
50
  @sqlserver = true
@@ -52,7 +52,7 @@ module DockerfileRails
52
52
 
53
53
  @sqlite3 = true if @gemfile.include? "sqlite3"
54
54
  @postgresql = true if @gemfile.include? "pg"
55
- @mysql = true if @gemfile.include? "mysql2"
55
+ @mysql = true if @gemfile.include?("mysql2") || using_trilogy?
56
56
 
57
57
  ### node modules ###
58
58
 
@@ -81,5 +81,9 @@ module DockerfileRails
81
81
 
82
82
  @redis = @redis_cable || @redis_cache
83
83
  end
84
+
85
+ def using_trilogy?
86
+ @gemfile.include?("trilogy") || @gemfile.include?("activerecord-trilogy-adapter")
87
+ end
84
88
  end
85
89
  end
@@ -33,12 +33,13 @@ class DockerfileGenerator < Rails::Generators::Base
33
33
  "registry" => "",
34
34
  "root" => false,
35
35
  "sqlite3" => false,
36
+ "sentry" => false,
36
37
  "sudo" => false,
37
38
  "swap" => nil,
38
39
  "variant" => "slim",
39
40
  "windows" => false,
40
41
  "yjit" => false,
41
- }.then { |hash| Struct.new(*hash.keys.map(&:to_sym)).new(*hash.values) }
42
+ }.yield_self { |hash| Struct.new(*hash.keys.map(&:to_sym)).new(*hash.values) }
42
43
 
43
44
  OPTION_DEFAULTS = BASE_DEFAULTS.dup
44
45
 
@@ -169,6 +170,9 @@ class DockerfileGenerator < Rails::Generators::Base
169
170
  class_option :sudo, type: :boolean, default: OPTION_DEFAULTS.sudo,
170
171
  desc: "Install and configure sudo to enable running as rails with full environment"
171
172
 
173
+ class_option :sentry, type: :boolean, default: OPTION_DEFAULTS.sentry,
174
+ desc: "Install gems and a starter initializer for sentry"
175
+
172
176
  class_option "migrate", type: :string, default: OPTION_DEFAULTS.migrate,
173
177
  desc: "custom migration/db:prepare script"
174
178
 
@@ -282,17 +286,19 @@ class DockerfileGenerator < Rails::Generators::Base
282
286
  fly_attach_consul
283
287
  end
284
288
 
285
- if fly_processes # therefore File.exist?('fly.toml')
289
+ if File.exist?("fly.toml") && (fly_processes || !options.prepare || options.swap)
286
290
  if File.stat("fly.toml").size > 0
287
291
  template "fly.toml.erb", "fly.toml"
288
292
  else
289
- toml = fly_make_processes(fly_processes)
290
- if toml != IO.read("fly.toml")
291
- File.write "fly.toml", toml
292
- end
293
+ toml = fly_make_toml
294
+ File.write "fly.toml", toml if toml != ""
293
295
  end
294
296
  end
295
297
 
298
+ if options.sentry? && (not File.exist?("config/initializers/sentry.rb"))
299
+ template "sentry.rb.erb", "config/initializers/sentry.rb"
300
+ end
301
+
296
302
  if @gemfile.include?("vite_ruby")
297
303
  package = JSON.load_file("package.json")
298
304
  unless package.dig("scripts", "build")
@@ -321,7 +327,7 @@ private
321
327
  scope = (Class.new do
322
328
  def initialize(obj, locals)
323
329
  @_obj = obj
324
- @_locals = locals.then do |hash|
330
+ @_locals = locals.yield_self do |hash|
325
331
  return nil if hash.empty?
326
332
  Struct.new(*hash.keys.map(&:to_sym)).new(*hash.values)
327
333
  end
@@ -400,6 +406,14 @@ private
400
406
  using_node? && options.parallel
401
407
  end
402
408
 
409
+ def has_mysql_gem?
410
+ @gemfile.include? "mysql2" or using_trilogy?
411
+ end
412
+
413
+ def using_trilogy?
414
+ @gemfile.include?("trilogy") || @gemfile.include?("activerecord-trilogy-adapter")
415
+ end
416
+
403
417
  def keeps?
404
418
  return @keeps if @keeps != nil
405
419
  @keeps = !!Dir["**/.keep"]
@@ -419,13 +433,18 @@ private
419
433
  end
420
434
 
421
435
  if options.mysql? || @mysql
422
- system "bundle add mysql2 --skip-install" unless @gemfile.include? "mysql2"
436
+ system "bundle add mysql2 --skip-install" unless has_mysql_gem?
423
437
  end
424
438
 
425
439
  if options.redis? || using_redis?
426
440
  system "bundle add redis --skip-install" unless @gemfile.include? "redis"
427
441
  end
428
442
 
443
+ if options.sentry?
444
+ system "bundle add sentry-ruby --skip-install" unless @gemfile.include? "sentry-ruby"
445
+ system "bundle add sentry-rails --skip-install" unless @gemfile.include? "sentry-rails"
446
+ end
447
+
429
448
  # https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp/70500221#70500221
430
449
  if @gemfile.include? "mail"
431
450
  %w(net-smtp net-imap net-pop).each do |gem|
@@ -511,7 +530,10 @@ private
511
530
  # add databases: sqlite3, postgres, mysql
512
531
  packages << "pkg-config" if options.sqlite3? || @sqlite3
513
532
  packages << "libpq-dev" if options.postgresql? || @postgresql
514
- packages << "default-libmysqlclient-dev" if options.mysql? || @mysql
533
+
534
+ if (options.mysql? || @mysql) && !using_trilogy?
535
+ packages << "default-libmysqlclient-dev"
536
+ end
515
537
 
516
538
  # add git if needed to install gems
517
539
  packages << "git" if @git
@@ -635,7 +657,7 @@ private
635
657
  repos += [
636
658
  "curl https://dl-ssl.google.com/linux/linux_signing_key.pub |",
637
659
  " gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg &&",
638
- 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
660
+ 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
639
661
  ]
640
662
  end
641
663
 
@@ -714,12 +736,7 @@ private
714
736
  end
715
737
 
716
738
  if options.jemalloc? && !options.fullstaq?
717
- if (options.platform || Gem::Platform.local.cpu).include? "arm"
718
- env["LD_PRELOAD"] = "/usr/lib/aarch64-linux-gnu/libjemalloc.so.2"
719
- else
720
- env["LD_PRELOAD"] = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
721
- end
722
-
739
+ env["LD_PRELOAD"] = "libjemalloc.so.2"
723
740
  env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
724
741
  end
725
742
 
@@ -857,7 +874,7 @@ private
857
874
  # use presence of "pg" or "mysql2" in the bundle as evidence of intent.
858
875
  if options.postgresql? || @postgresql || @gemfile.include?("pg")
859
876
  "postgresql"
860
- elsif options.mysql? || @mysql || @gemfile.include?("mysql2")
877
+ elsif options.mysql? || @mysql || has_mysql_gem?
861
878
  "mysql"
862
879
  else
863
880
  "sqlite3"
@@ -1042,19 +1059,54 @@ private
1042
1059
  system "#{flyctl} consul attach"
1043
1060
  end
1044
1061
 
1045
- def fly_make_processes(list)
1062
+ def fly_make_toml
1046
1063
  toml = File.read("fly.toml")
1047
1064
 
1048
- if toml.include? "[processes]"
1049
- toml.sub!(/\[processes\].*?(\n\n|\n?\z)/m, "[processes]\n" +
1050
- list.map { |name, cmd| " #{name} = #{cmd.inspect}" }.join("\n") + '\1')
1051
- else
1052
- toml += "\n[processes]\n" +
1053
- list.map { |name, cmd| " #{name} = #{cmd.inspect}\n" }.join
1065
+ list = fly_processes
1066
+ if list
1067
+ if toml.include? "[processes]"
1068
+ toml.sub!(/\[processes\].*?(\n\n|\n?\z)/m, "[processes]\n" +
1069
+ list.map { |name, cmd| " #{name} = #{cmd.inspect}" }.join("\n") + '\1')
1070
+ else
1071
+ toml += "\n[processes]\n" +
1072
+ list.map { |name, cmd| " #{name} = #{cmd.inspect}\n" }.join
1073
+
1074
+ app = list.has_key?("app") ? "app" : list.keys.first
1075
+
1076
+ toml.sub! "[http_service]\n", "\\0 processes = [#{app.inspect}]\n"
1077
+ end
1078
+ end
1079
+
1080
+ if options.prepare == false
1081
+ deploy = "[deploy]\n release_command = #{dbprep_command.inspect}\n\n"
1082
+ if toml.include? "[deploy]"
1083
+ toml.sub!(/\[deploy\].*?(\n\n|\n?\z)/m, deploy)
1084
+ else
1085
+ toml += deploy
1086
+ end
1087
+ end
1054
1088
 
1055
- app = list.has_key?("app") ? "app" : list.keys.first
1089
+ if options.swap
1090
+ suffixes = {
1091
+ "kib" => 1024,
1092
+ "k" => 1024,
1093
+ "kb" => 1000,
1094
+ "mib" => 1048576,
1095
+ "m" => 1048576,
1096
+ "mb" => 100000,
1097
+ "gib" => 1073741824,
1098
+ "g" => 1073741824,
1099
+ "gb" => 100000000,
1100
+ }
1056
1101
 
1057
- toml.sub! "[http_service]\n", "\\0 processes = [#{app.inspect}]\n"
1102
+ pattern = Regexp.new("^(\\d+)(#{suffixes.keys.join('|')})?$", "i")
1103
+
1104
+ match = pattern.match(options.swap.downcase)
1105
+
1106
+ if match
1107
+ size = ((match[1].to_i * (suffixes[match[2]] || 1)) / 1048576.0).round
1108
+ toml += "swap_size_mb = #{size}"
1109
+ end
1058
1110
  end
1059
1111
 
1060
1112
  toml
@@ -20,7 +20,7 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz
20
20
  <% if yarn_version < '2' -%>
21
21
  <% if node_version -%> <% else %>RUN<% end %> npm install -g yarn@$YARN_VERSION<% if node_version -%> && \<% end %>
22
22
  <% else -%>
23
- <% if (node_version.split('.').map(&:to_i) <=> [16,10,0]) < 0 -%>
23
+ <% if node_version && (node_version.split('.').map(&:to_i) <=> [16,10,0]) < 0 -%>
24
24
  npm i -g corepack && \
25
25
  <% else -%>
26
26
  corepack enable && \
@@ -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 stdout;/' /etc/nginx/nginx.conf && \
7
+ sed -i 's/error_log\s.*;/error_log 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 stdout;
14
14
 
15
15
  root /rails/public;
16
16
 
@@ -20,10 +20,10 @@ EOF
20
20
  <% end -%>
21
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
@@ -21,8 +21,12 @@ services:
21
21
  <% if deploy_database == 'postgresql' -%>
22
22
  - DATABASE_URL=postgres://root:password@postgres-db/
23
23
  <% elsif deploy_database == 'mysql' -%>
24
+ <% if using_trilogy? -%>
25
+ - DATABASE_URL=trilogy://root:password@mysql-db/
26
+ <% else -%>
24
27
  - DATABASE_URL=mysql2://root:password@mysql-db/
25
28
  <% end -%>
29
+ <% end -%>
26
30
  <% if deploy_database == 'sqlite3' -%>
27
31
  volumes:
28
32
  - ./db:/rails/db
@@ -89,7 +93,11 @@ services:
89
93
  <% if deploy_database == 'postgresql' -%>
90
94
  - DATABASE_URL=postgres://root:password@postgres-db/
91
95
  <% elsif deploy_database == 'mysql' -%>
96
+ <% if using_trilogy? -%>
97
+ - DATABASE_URL=trilogy://root:password@mysql-db/
98
+ <% else -%>
92
99
  - DATABASE_URL=mysql2://root:password@mysql-db/
100
+ <% end -%>
93
101
  <% end -%>
94
102
  depends_on:
95
103
  redis-db:
@@ -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 -%>
@@ -1 +1 @@
1
- <%= fly_make_processes(fly_processes) -%>
1
+ <%= fly_make_toml -%>
@@ -0,0 +1,13 @@
1
+ Sentry.init do |config|
2
+ config.dsn = ENV["SENTRY_DSN"]
3
+ config.breadcrumbs_logger = [:active_support_logger, :http_logger]
4
+
5
+ # Set traces_sample_rate to 1.0 to capture 100%
6
+ # of transactions for performance monitoring.
7
+ # We recommend adjusting this value in production.
8
+ config.traces_sample_rate = 1.0
9
+ # or
10
+ config.traces_sampler = lambda do |context|
11
+ true
12
+ end
13
+ 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.0
4
+ version: 1.5.2
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-06-22 00:00:00.000000000 Z
11
+ date: 2023-07-24 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/sentry.rb.erb
55
56
  homepage: https://github.com/fly-apps/dockerfile-rails
56
57
  licenses:
57
58
  - MIT
@@ -65,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
66
  requirements:
66
67
  - - ">="
67
68
  - !ruby/object:Gem::Version
68
- version: '0'
69
+ version: 2.6.0
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  requirements:
71
72
  - - ">="