dockerfile-rails 1.6.17 → 1.6.19

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: e637270c44cb54868cd8947bc9347000e60ae76395d5f2033ca61f67f8266bac
4
- data.tar.gz: afe0959d1da483ca595e1b13bf5f7568bf470aa1b6abaf8e3e604b21cebcf793
3
+ metadata.gz: 770d93b1bee2aa9cec4832a7a03b6c3ed8ccbfb82ca6c19a28959ab38f5f4501
4
+ data.tar.gz: d19ba2048b0c6d2f5d92506ab29dd2c06bdf106d782b4ce3ca45d41c079306a0
5
5
  SHA512:
6
- metadata.gz: 11c0b726982acebf8d3943aaf2c498e9ecfb4960f943f3ef094881390601c9c6bdfb1d2cb69a45fbf4b0d481284d3cefc76986b3187f7b6d09a53434cd26f373
7
- data.tar.gz: 5c971c5b102ec993900e0bb75ccb52e17335499649ae05c23c2d6302f12e8514e200071cdd19015af5f0e28d65e2405f77799bcb7089fdd2ae7de0c38ade0f9d
6
+ metadata.gz: 9dab86fe342a82d18911f2a1fc2d7ec5de69f3b7b3326f1ea9c9fb2945049dbcdd39ac9c125ab524997c16af6f1422b0d73062dfd80ff13044a79b7f0e81996e
7
+ data.tar.gz: ef62d1ff9359b3e702c0e5a914e39edeeb594bf5c3cc9f5ff2ac8564b974e5ae2bd753f4949d69353a8caf5cdb2ed220daa27255589b0c8f991b60cefd4dbb47
data/lib/fly_replay.rb ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fly
4
+ class FlyReplay
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ # replay /prometheus/* to the prom proxy in bubblegum
11
+ if env["PATH_INFO"].starts_with?("/prometheus")
12
+ return [307, { "Fly-Replay" => "app=flyio-bubblegum-api" }, []]
13
+ end
14
+
15
+ # replay /debug to the debug app. unsure if this is actually used
16
+ if env["PATH_INFO"].starts_with?("/debug")
17
+ return [307, { "Fly-Replay" => "app=debug" }, []]
18
+ end
19
+
20
+ @status, @headers, @response = @app.call(env)
21
+
22
+ context = OpenTelemetry::Trace.current_span.context
23
+ @headers["fly-trace-id"] = context.trace_id.unpack1("H*")
24
+ @headers["fly-span-id"] = context.span_id.unpack1("H*")
25
+
26
+ [@status, @headers, @response]
27
+ end
28
+ end
29
+ end
@@ -331,6 +331,8 @@ class DockerfileGenerator < Rails::Generators::Base
331
331
 
332
332
  template "docker-compose.yml.erb", "docker-compose.yml" if options.compose
333
333
 
334
+ template "database.yml.erb", "config/database.yml" if fix_database_config
335
+
334
336
  if using_litefs?
335
337
  template "litefs.yml.erb", "config/litefs.yml"
336
338
 
@@ -517,12 +519,16 @@ private
517
519
  options.passenger? or options["max-idle"]
518
520
  end
519
521
 
522
+ def includes_jobs?
523
+ !(Dir["app/jobs/*.rb"] - ["app/jobs/application_job.rb"]).empty?
524
+ end
525
+
520
526
  def using_sidekiq?
521
- @gemfile.include?("sidekiq")
527
+ @gemfile.include?("sidekiq") and includes_jobs?
522
528
  end
523
529
 
524
530
  def using_solidq?
525
- @gemfile.include?("solid_queue")
531
+ @gemfile.include?("solid_queue") and includes_jobs?
526
532
  end
527
533
 
528
534
  def parallel?
@@ -1252,6 +1258,19 @@ private
1252
1258
  more
1253
1259
  end
1254
1260
 
1261
+ def compose_web_volumes
1262
+ volumes = %w[ log storage ]
1263
+
1264
+ if deploy_database == "sqlite3"
1265
+ database = YAML.load_file("config/database.yml", aliases: true).dig("production", "database")
1266
+ if database && database =~ /^\w/
1267
+ volumes << File.dirname(database)
1268
+ end
1269
+ end
1270
+
1271
+ volumes.uniq.sort
1272
+ end
1273
+
1255
1274
  def max_idle
1256
1275
  option = options["max-idle"]
1257
1276
 
@@ -1433,4 +1452,31 @@ private
1433
1452
 
1434
1453
  toml
1435
1454
  end
1455
+
1456
+ # if there are multiple production databases defined, allow them all to be
1457
+ # configured via DATABASE_URL.
1458
+ def fix_database_config
1459
+ yaml = IO.read("config/database.yml")
1460
+
1461
+ production = YAML.load(yaml, aliases: true)["production"]
1462
+ return unless production.is_a?(Hash) && production.values.all?(Hash)
1463
+ return if production.keys == [ "primary" ]
1464
+
1465
+ section = yaml[/^(production:.*?)(^\S|\z)/m, 1]
1466
+
1467
+ replacement = section.gsub(/( ).*?\n((\1\s+).*?\n)*/) do |subsection|
1468
+ spaces = $3
1469
+ name = subsection[/\w+/]
1470
+
1471
+ if /^ +url:/.match?(subsection)
1472
+ subsection
1473
+ elsif name == "primary"
1474
+ subsection + spaces + %(url: <%= ENV["DATABASE_URL"] %>\n)
1475
+ else
1476
+ subsection + spaces + %(url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_#{name}" } if ENV["DATABASE_URL"] %>\n)
1477
+ end
1478
+ end
1479
+
1480
+ yaml.sub(section, replacement)
1481
+ end
1436
1482
  end
@@ -8,9 +8,9 @@ ARG RUBY_VERSION=<%= RUBY_VERSION %>
8
8
 
9
9
  <% end -%>
10
10
  <% if options.fullstaq -%>
11
- FROM <%= platform %>quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= options.jemalloc ? 'jemalloc-' : 'malloctrim-' %><%= variant %><% unless options.precompile == "defer" %> as base<% end %>
11
+ FROM <%= platform %>quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= options.jemalloc ? 'jemalloc-' : 'malloctrim-' %><%= variant %><% unless options.precompile == "defer" %> AS base<% end %>
12
12
  <% else -%>
13
- FROM <%= platform %><%= options.registry %>ruby:$RUBY_VERSION-<%= variant %><% unless options.precompile == "defer" %> as base<% end %>
13
+ FROM <%= platform %><%= options.registry %>ruby:$RUBY_VERSION-<%= variant %><% unless options.precompile == "defer" %> AS base<% end %>
14
14
  <% end -%>
15
15
 
16
16
  <% unless options.label.empty? -%>
@@ -50,7 +50,7 @@ RUN gem update --system <% if RUBY_VERSION.start_with? '2' %>3.4.22 <% end %>--n
50
50
  <% unless options.precompile == "defer" -%>
51
51
 
52
52
  # Throw-away build stage<%= parallel? ? 's' : '' %> to reduce size of final image
53
- FROM base as <%= parallel? ? 'pre' : '' %>build
53
+ FROM base AS <%= parallel? ? 'pre' : '' %>build
54
54
 
55
55
  <% end -%>
56
56
  # Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
@@ -58,7 +58,7 @@ FROM base as <%= parallel? ? 'pre' : '' %>build
58
58
 
59
59
  <% if parallel? -%>
60
60
 
61
- FROM prebuild as <% if using_bun? %>bun<% else %>node<% end %>
61
+ FROM prebuild AS <% if using_bun? %>bun<% else %>node<% end %>
62
62
 
63
63
  <% end -%>
64
64
  <% if using_bun? and (!using_execjs? || File.exist?('bun.lockb')) -%>
@@ -72,7 +72,7 @@ FROM prebuild as <% if using_bun? %>bun<% else %>node<% end %>
72
72
  <%= render partial: 'npm_install', locals: {sources: Dir[*%w(package.json yarn.lock bun.lockb)]} %>
73
73
 
74
74
 
75
- FROM prebuild as build
75
+ FROM prebuild AS build
76
76
 
77
77
  <% end -%>
78
78
  <% unless build_args.empty? -%>
@@ -1,6 +1,6 @@
1
1
  ARG NODE_VERSION=<%= node_version %>
2
2
 
3
- FROM <%= platform %>node:$NODE_VERSION-slim as client
3
+ FROM <%= platform %>node:$NODE_VERSION-slim AS client
4
4
 
5
5
  WORKDIR /rails/<%= api_client_dir %>
6
6
 
@@ -0,0 +1 @@
1
+ <%= fix_database_config %>
@@ -1,4 +1,5 @@
1
1
  version: "3.8"
2
+
2
3
  services:
3
4
  web:
4
5
  <% if all_args.empty? -%>
@@ -18,11 +19,14 @@ services:
18
19
  secrets:
19
20
  - gemserver_credentials
20
21
  <% end -%>
22
+ <% end -%>
23
+ volumes:
24
+ <% compose_web_volumes.each do |path| -%>
25
+ - ./<%= path %>:/rails/<%= path %>
21
26
  <% end -%>
22
27
  ports:
23
28
  - "3000:3000"
24
29
  environment:
25
- - RAILS_MASTER_KEY=$RAILS_MASTER_KEY
26
30
  <% if using_redis? -%>
27
31
  - REDIS_URL=redis://redis-db:6379
28
32
  <% end -%>
@@ -35,10 +39,9 @@ services:
35
39
  - DATABASE_URL=mysql2://root:password@mysql-db/
36
40
  <% end -%>
37
41
  <% end -%>
38
- <% if deploy_database == 'sqlite3' -%>
39
- volumes:
40
- - ./db:/rails/db
41
- <% end -%>
42
+ secrets:
43
+ - source: master_key
44
+ target: /rails/config/master.key
42
45
  <% if using_redis? or deploy_database != 'sqlite3' -%>
43
46
  depends_on:
44
47
  <% if using_redis? -%>
@@ -60,9 +63,7 @@ services:
60
63
  POSTGRES_USER: root
61
64
  POSTGRES_PASSWORD: password
62
65
  volumes:
63
- - ./tmp/db:/var/lib/postgresql/data
64
- ports:
65
- - "5432:5432"
66
+ - ./tmp/postgres-db:/var/lib/postgresql/data
66
67
  healthcheck:
67
68
  test: pg_isready
68
69
  interval: 2s
@@ -77,7 +78,7 @@ services:
77
78
  environment:
78
79
  MYSQL_ROOT_PASSWORD: password
79
80
  volumes:
80
- - ./tmp/db:/var/lib/mysql
81
+ - ./tmp/mysql-db:/var/lib/mysql
81
82
  healthcheck:
82
83
  test: mysqladmin ping -h 127.0.0.1 -u root --password=password
83
84
  interval: 2s
@@ -132,3 +133,7 @@ secrets:
132
133
  gemserver_credentials:
133
134
  file: ./GEMSERVER_CREDENTIALS.secret.txt
134
135
  <% end -%>
136
+
137
+ secrets:
138
+ master_key:
139
+ file: ./config/master.key
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.6.17
4
+ version: 1.6.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,6 +37,7 @@ files:
37
37
  - Rakefile
38
38
  - lib/dockerfile-rails.rb
39
39
  - lib/dockerfile-rails/scanner.rb
40
+ - lib/fly_replay.rb
40
41
  - lib/generators/dockerfile_generator.rb
41
42
  - lib/generators/templates/Dockerfile.erb
42
43
  - lib/generators/templates/_apt_install.erb
@@ -45,6 +46,7 @@ files:
45
46
  - lib/generators/templates/_node_client.erb
46
47
  - lib/generators/templates/_npm_install.erb
47
48
  - lib/generators/templates/_passenger.erb
49
+ - lib/generators/templates/database.yml.erb
48
50
  - lib/generators/templates/docker-compose.yml.erb
49
51
  - lib/generators/templates/docker-entrypoint.erb
50
52
  - lib/generators/templates/dockerfile.yml.erb
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
76
  - !ruby/object:Gem::Version
75
77
  version: '0'
76
78
  requirements: []
77
- rubygems_version: 3.5.10
79
+ rubygems_version: 3.5.14
78
80
  signing_key:
79
81
  specification_version: 4
80
82
  summary: Dockerfile generator for Rails