dockerfile-rails 1.6.24 → 1.7.0
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 +4 -4
- data/DEMO.md +1 -1
- data/README.md +1 -0
- data/lib/generators/dockerfile_generator.rb +134 -46
- data/lib/generators/templates/Dockerfile.erb +25 -13
- data/lib/generators/templates/docker-compose.yml.erb +1 -1
- data/lib/generators/templates/docker-entrypoint.erb +10 -6
- data/lib/generators/templates/dockerignore.erb +16 -2
- data/lib/generators/templates/litestream.rake.erb +55 -0
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8309aa1e1fe7194297188df68c64c458d2fc7e892c0d4b0c0dadc9fe9b1d3a6e
|
4
|
+
data.tar.gz: c0d684a6bde26b27aa40c12e8cdd24bbdbd15d220258f48468ac6d4780fd15d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0444b3658976d0b1f3e363848616a0774886e24a4c156daf0102f40c983ecb902f927af387be92c0f91447fad2c521a8ea1e378ca799d0a967400f8ffadc8ada
|
7
|
+
data.tar.gz: b174840c7d365257c77f706d82ac979a231d2cb91c633fcc79e2806f9deaa4ccdf1818e389bd2c6d9d115e978bb823f97ff091f9344f75121cd5ef0025441ace
|
data/DEMO.md
CHANGED
@@ -7,7 +7,7 @@ Rails provides a _smoke test_ for new applications that makes sure that you have
|
|
7
7
|
```bash
|
8
8
|
rails new demo --minimal
|
9
9
|
cd demo
|
10
|
-
echo 'Rails.application.routes.draw { root "rails/welcome#index" }'
|
10
|
+
echo 'Rails.application.routes.draw { root "rails/welcome#index" }' >> config/routes.rb
|
11
11
|
bundle add dockerfile-rails --optimistic --group development
|
12
12
|
bin/rails generate dockerfile
|
13
13
|
docker buildx build . -t rails-demo
|
data/README.md
CHANGED
@@ -67,6 +67,7 @@ are actually using. But should you be using DATABASE_URL, for example, at runti
|
|
67
67
|
additional support may be needed:
|
68
68
|
|
69
69
|
* `--litefs` - use [LiteFS](https://fly.io/docs/litefs/)
|
70
|
+
* `--litestream` - use [LiteFS](https://litestream.io/)
|
70
71
|
* `--mysql` - add mysql libraries
|
71
72
|
* `--postgresql` - add postgresql libraries
|
72
73
|
* `--redis` - add redis libraries
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "erb"
|
4
4
|
require "json"
|
5
|
+
require "shellwords"
|
5
6
|
require_relative "../dockerfile-rails/scanner.rb"
|
6
7
|
|
7
8
|
class DockerfileGenerator < Rails::Generators::Base
|
@@ -15,10 +16,11 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
15
16
|
"compose" => false,
|
16
17
|
"fullstaq" => false,
|
17
18
|
"gemfile-updates" => true,
|
18
|
-
"jemalloc" =>
|
19
|
+
"jemalloc" => true,
|
19
20
|
"label" => {},
|
20
21
|
"link" => false,
|
21
22
|
"litefs" => false,
|
23
|
+
"litestream" => false,
|
22
24
|
"lock" => true,
|
23
25
|
"max-idle" => nil,
|
24
26
|
"migrate" => "",
|
@@ -74,7 +76,8 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
74
76
|
"node-gyp" => "gyp",
|
75
77
|
"pkg-config" => "pkgconfig",
|
76
78
|
"python" => "python3",
|
77
|
-
"python-is-python3" => "python3"
|
79
|
+
"python-is-python3" => "python3",
|
80
|
+
"sqlite3" => "sqlite",
|
78
81
|
}
|
79
82
|
|
80
83
|
# load defaults from config file
|
@@ -162,6 +165,9 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
162
165
|
class_option :litefs, type: :boolean, default: OPTION_DEFAULTS.litefs,
|
163
166
|
desc: "replicate sqlite3 databases using litefs"
|
164
167
|
|
168
|
+
class_option :litestream, type: :boolean, default: OPTION_DEFAULTS.litestream,
|
169
|
+
desc: "replicate sqlite3 databases using litesream"
|
170
|
+
|
165
171
|
class_option :tigris, type: :boolean, default: OPTION_DEFAULTS.tigris,
|
166
172
|
desc: "configure active storage to use tigris"
|
167
173
|
|
@@ -333,7 +339,7 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
333
339
|
|
334
340
|
if fix_database_config
|
335
341
|
template "database.yml.erb", "config/database.yml",
|
336
|
-
force: File.exist?("fly.toml")
|
342
|
+
force: options.force? || File.exist?("fly.toml")
|
337
343
|
end
|
338
344
|
|
339
345
|
if solidq_launcher == :puma && !File.read("config/puma.rb").include?(":solid_queue")
|
@@ -346,6 +352,10 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
346
352
|
fly_attach_consul
|
347
353
|
end
|
348
354
|
|
355
|
+
if using_litestream?
|
356
|
+
template "litestream.rake.erb", "lib/tasks/litestream.rake"
|
357
|
+
end
|
358
|
+
|
349
359
|
if File.exist?("fly.toml") && (fly_processes || !options.prepare || options.swap || deploy_database == "sqlite3")
|
350
360
|
if File.stat("fly.toml").size > 0
|
351
361
|
template "fly.toml.erb", "fly.toml"
|
@@ -421,24 +431,12 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
421
431
|
end
|
422
432
|
|
423
433
|
if File.exist?("fly.toml")
|
424
|
-
env =
|
425
|
-
|
426
|
-
if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL")
|
427
|
-
env["DATABASE_URL"] = "sqlite3:///data/production.sqlite3"
|
428
|
-
end
|
429
|
-
|
430
|
-
if using_thruster? && !dockerfile.include?("HTTP_PORT")
|
431
|
-
env["HTTP_PORT"] = "8080"
|
432
|
-
end
|
433
|
-
|
434
|
-
if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
|
435
|
-
env["SOLID_QUEUE_IN_PUMA"] = "true"
|
436
|
-
end
|
434
|
+
env = fly_toml_env
|
437
435
|
|
438
436
|
unless env.empty?
|
439
437
|
toml = IO.read("fly.toml")
|
440
|
-
if !toml.include?("[
|
441
|
-
toml += "\n[
|
438
|
+
if !toml.include?("[env]")
|
439
|
+
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
|
442
440
|
File.write "fly.toml", toml
|
443
441
|
end
|
444
442
|
end
|
@@ -500,6 +498,10 @@ private
|
|
500
498
|
@gemfile.include?("litestack")
|
501
499
|
end
|
502
500
|
|
501
|
+
def using_litestream?
|
502
|
+
options.litestream?
|
503
|
+
end
|
504
|
+
|
503
505
|
def using_node?
|
504
506
|
return @using_node if @using_node != nil
|
505
507
|
return if using_bun?
|
@@ -606,6 +608,10 @@ private
|
|
606
608
|
system "bundle add mysql2 --skip-install" unless has_mysql_gem?
|
607
609
|
end
|
608
610
|
|
611
|
+
if options.litestream?
|
612
|
+
system "bundle add litestream --skip-install" unless @gemfile.include? "litestream"
|
613
|
+
end
|
614
|
+
|
609
615
|
if options.redis? || using_redis?
|
610
616
|
system "bundle add redis --skip-install" unless @gemfile.include? "redis"
|
611
617
|
end
|
@@ -674,19 +680,30 @@ private
|
|
674
680
|
end
|
675
681
|
|
676
682
|
def base_packages
|
677
|
-
packages =
|
683
|
+
packages = %w(curl) # work with the default healthcheck strategy in Kamal
|
678
684
|
packages += @@packages["base"] if @@packages["base"]
|
679
685
|
|
686
|
+
packages << "libjemalloc2" if options.jemalloc? && !options.fullstaq?
|
687
|
+
|
688
|
+
# start with databases: sqlite3, postgres, mysql
|
689
|
+
packages << "postgresql-client" if options.postgresql? || @postgresql
|
690
|
+
packages << "default-mysql-client" if options.mysql? || @mysql
|
691
|
+
packages << "freetds-bin" if options.sqlserver? || @sqlserver
|
692
|
+
if options.sqlite3? || @sqlite3
|
693
|
+
packages << "sqlite3" unless packages.include? "sqlite3"
|
694
|
+
end
|
695
|
+
|
696
|
+
# ActiveStorage preview support
|
697
|
+
packages << "libvips" if @gemfile.include? "ruby-vips"
|
698
|
+
|
680
699
|
if using_execjs?
|
681
700
|
if node_version == "lts"
|
682
701
|
packages += %w(nodejs npm)
|
683
|
-
else
|
684
|
-
packages += %w(curl)
|
685
702
|
end
|
686
703
|
end
|
687
704
|
|
688
705
|
if using_puppeteer?
|
689
|
-
packages += %w(
|
706
|
+
packages += %w(gnupg)
|
690
707
|
end
|
691
708
|
|
692
709
|
# charlock_holmes. Placed here as the library itself is
|
@@ -737,9 +754,6 @@ private
|
|
737
754
|
# add git if needed to install gems
|
738
755
|
packages << "git" if @git
|
739
756
|
|
740
|
-
# ActiveStorage preview support
|
741
|
-
packages << "libvips" if @gemfile.include? "ruby-vips"
|
742
|
-
|
743
757
|
# Rmagick gem
|
744
758
|
packages += %w[pkg-config libmagickwand-dev] if @gemfile.include? "rmagick"
|
745
759
|
|
@@ -748,7 +762,7 @@ private
|
|
748
762
|
packages += %w(node-gyp pkg-config)
|
749
763
|
|
750
764
|
unless using_execjs? || using_puppeteer?
|
751
|
-
packages << "curl"
|
765
|
+
# packages << "curl"
|
752
766
|
end
|
753
767
|
|
754
768
|
# module build process depends on Python, and debian changed
|
@@ -774,7 +788,7 @@ private
|
|
774
788
|
end
|
775
789
|
|
776
790
|
if using_bun?
|
777
|
-
packages += %w(
|
791
|
+
packages += %w(unzip)
|
778
792
|
end
|
779
793
|
|
780
794
|
if options.alpine?
|
@@ -785,18 +799,9 @@ private
|
|
785
799
|
end
|
786
800
|
|
787
801
|
def deploy_packages
|
788
|
-
packages =
|
802
|
+
packages = []
|
789
803
|
packages += @@packages["deploy"] if @@packages["deploy"]
|
790
804
|
|
791
|
-
# start with databases: sqlite3, postgres, mysql
|
792
|
-
packages << "postgresql-client" if options.postgresql? || @postgresql
|
793
|
-
packages << "default-mysql-client" if options.mysql? || @mysql
|
794
|
-
packages << "freetds-bin" if options.sqlserver? || @sqlserver
|
795
|
-
packages << "libjemalloc2" if options.jemalloc? && !options.fullstaq?
|
796
|
-
if options.sqlite3? || @sqlite3
|
797
|
-
packages << "libsqlite3-0" unless packages.include? "sqlite3"
|
798
|
-
end
|
799
|
-
|
800
805
|
# litefs
|
801
806
|
packages += ["ca-certificates", "fuse3", "sudo"] if options.litefs?
|
802
807
|
|
@@ -877,7 +882,7 @@ private
|
|
877
882
|
packages = []
|
878
883
|
|
879
884
|
if using_passenger?
|
880
|
-
packages += %w(gnupg
|
885
|
+
packages += %w(curl gnupg)
|
881
886
|
repos += [
|
882
887
|
"curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt |",
|
883
888
|
" gpg --dearmor > /etc/apt/trusted.gpg.d/phusion.gpg &&",
|
@@ -903,7 +908,7 @@ private
|
|
903
908
|
packages = []
|
904
909
|
|
905
910
|
if using_puppeteer? && deploy_packages.include?("google-chrome-stable")
|
906
|
-
packages += %w(gnupg
|
911
|
+
packages += %w(gnupg)
|
907
912
|
repos += [
|
908
913
|
"curl https://dl-ssl.google.com/linux/linux_signing_key.pub |",
|
909
914
|
" gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg &&",
|
@@ -991,8 +996,8 @@ private
|
|
991
996
|
end
|
992
997
|
|
993
998
|
if options.jemalloc? && !options.fullstaq?
|
994
|
-
env["LD_PRELOAD"] = "libjemalloc.so.2"
|
995
|
-
env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
|
999
|
+
# env["LD_PRELOAD"] = "libjemalloc.so.2"
|
1000
|
+
# env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
|
996
1001
|
end
|
997
1002
|
|
998
1003
|
if using_puppeteer?
|
@@ -1145,6 +1150,30 @@ private
|
|
1145
1150
|
end
|
1146
1151
|
end
|
1147
1152
|
|
1153
|
+
def start_command
|
1154
|
+
if !options.procfile.blank?
|
1155
|
+
["foreman", "start", "--procfile=#{options.procfile}"]
|
1156
|
+
elsif procfile.size > 1
|
1157
|
+
["foreman", "start", "--procfile=Procfile.prod"]
|
1158
|
+
else
|
1159
|
+
command = Shellwords.split(procfile.values.first)
|
1160
|
+
|
1161
|
+
if command.first == "./bin/thrust"
|
1162
|
+
command[1..]
|
1163
|
+
else
|
1164
|
+
command
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
def shellescape(string)
|
1170
|
+
if %r{\A[-\w._/= ]+\z}.match?(string)
|
1171
|
+
string.inspect
|
1172
|
+
else
|
1173
|
+
Shellwords.escape(string)
|
1174
|
+
end
|
1175
|
+
end
|
1176
|
+
|
1148
1177
|
def node_version
|
1149
1178
|
return unless using_node? || using_execjs?
|
1150
1179
|
|
@@ -1249,15 +1278,25 @@ private
|
|
1249
1278
|
rails: "./bin/rails server -p 3001"
|
1250
1279
|
}
|
1251
1280
|
elsif using_thruster?
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1281
|
+
if File.exist? "bin/thrust"
|
1282
|
+
base = {
|
1283
|
+
rails: "./bin/thrust ./bin/rails server"
|
1284
|
+
}
|
1285
|
+
else
|
1286
|
+
base = {
|
1287
|
+
rails: "bundle exec thrust ./bin/rails server"
|
1288
|
+
}
|
1289
|
+
end
|
1255
1290
|
else
|
1256
1291
|
base = {
|
1257
1292
|
rails: "./bin/rails server"
|
1258
1293
|
}
|
1259
1294
|
end
|
1260
1295
|
|
1296
|
+
if using_litestream? && base[:rails]
|
1297
|
+
base[:rails] = "./bin/rake litestream:run " + base[:rails]
|
1298
|
+
end
|
1299
|
+
|
1261
1300
|
if solidq_launcher == :procfile
|
1262
1301
|
base["solidq"] = "bundle exec rake solid_queue:start"
|
1263
1302
|
end
|
@@ -1269,9 +1308,13 @@ private
|
|
1269
1308
|
options.thruster? || @gemfile.include?("thruster")
|
1270
1309
|
end
|
1271
1310
|
|
1311
|
+
def using_kamal?
|
1312
|
+
@gemfile.include?("kamal")
|
1313
|
+
end
|
1314
|
+
|
1272
1315
|
def fly_processes
|
1273
1316
|
return unless File.exist? "fly.toml"
|
1274
|
-
return unless using_sidekiq? || using_solidq?
|
1317
|
+
return unless using_sidekiq? || using_solidq? || using_thruster?
|
1275
1318
|
|
1276
1319
|
if procfile.size > 1
|
1277
1320
|
list = { "app" => "foreman start --procfile=Procfile.prod" }
|
@@ -1435,11 +1478,49 @@ private
|
|
1435
1478
|
end
|
1436
1479
|
end
|
1437
1480
|
|
1481
|
+
def fly_toml_env
|
1482
|
+
env = {}
|
1483
|
+
dockerfile = File.read("Dockerfile") rescue ""
|
1484
|
+
|
1485
|
+
if using_thruster?
|
1486
|
+
env["PORT"] = "8080"
|
1487
|
+
end
|
1488
|
+
|
1489
|
+
if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL")
|
1490
|
+
env["DATABASE_URL"] = "sqlite3:///data/production.sqlite3"
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
if using_thruster? # && !dockerfile.include?("HTTP_PORT")
|
1494
|
+
# env["HTTP_PORT"] = "8080"
|
1495
|
+
env["PORT"] = "8080"
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
|
1499
|
+
env["SOLID_QUEUE_IN_PUMA"] = "true"
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
env
|
1503
|
+
end
|
1504
|
+
|
1438
1505
|
def fly_make_toml
|
1439
1506
|
toml = File.read("fly.toml")
|
1507
|
+
env = fly_toml_env
|
1508
|
+
|
1509
|
+
unless env.empty? || toml.include?("[env]")
|
1510
|
+
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
|
1511
|
+
end
|
1440
1512
|
|
1441
1513
|
list = fly_processes
|
1442
1514
|
if list
|
1515
|
+
if using_thruster?
|
1516
|
+
primary = list.keys.first
|
1517
|
+
list[primary] = list[primary].sub(/^.*thrust /, "")
|
1518
|
+
end
|
1519
|
+
|
1520
|
+
if using_litestream? && list["app"]
|
1521
|
+
list["app"] = "./bin/rake litestream:run #{list["app"]}"
|
1522
|
+
end
|
1523
|
+
|
1443
1524
|
if toml.include? "[processes]"
|
1444
1525
|
toml.sub!(/\[processes\].*?(\n\n|\n?\z)/m, "[processes]\n" +
|
1445
1526
|
list.map { |name, cmd| " #{name} = #{cmd.inspect}" }.join("\n") + '\1')
|
@@ -1464,7 +1545,14 @@ private
|
|
1464
1545
|
|
1465
1546
|
if deploy_database == "sqlite3"
|
1466
1547
|
if not toml.include? "[mounts]"
|
1467
|
-
toml += "
|
1548
|
+
toml += <<~EOF + "\n"
|
1549
|
+
[mounts]
|
1550
|
+
source = "data"
|
1551
|
+
destination = "/data"
|
1552
|
+
auto_extend_size_threshold = 80
|
1553
|
+
auto_extend_size_increment = "1GB"
|
1554
|
+
auto_extend_size_limit = "10GB"
|
1555
|
+
EOF
|
1468
1556
|
end
|
1469
1557
|
end
|
1470
1558
|
|
@@ -1,6 +1,15 @@
|
|
1
|
-
# syntax
|
1
|
+
# syntax=docker/dockerfile:1
|
2
|
+
# check=error=true
|
3
|
+
<% if using_kamal? -%>
|
2
4
|
|
3
|
-
#
|
5
|
+
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
|
6
|
+
# docker build -t demo .
|
7
|
+
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name demo demo
|
8
|
+
|
9
|
+
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
4
13
|
ARG RUBY_VERSION=<%= RUBY_VERSION %>
|
5
14
|
<% if api_client_dir -%>
|
6
15
|
<%= render partial: 'node_client' %>
|
@@ -27,18 +36,18 @@ WORKDIR /rails
|
|
27
36
|
ARG <%= base_args.map {|key, value| "#{key}=#{value.inspect}"}.join(" \\\n ") %>
|
28
37
|
|
29
38
|
<% end -%>
|
30
|
-
# Set production environment
|
31
|
-
ENV <%= base_env.join(" \\\n ") %>
|
32
|
-
|
33
39
|
# Update gems and bundler
|
34
40
|
RUN gem update --system <% if RUBY_VERSION.start_with? '2' %>3.4.22 <% end %>--no-document && \
|
35
41
|
gem install -N <%= base_gems.join(" ") %>
|
36
42
|
|
37
43
|
<% unless base_packages.empty? -%>
|
38
|
-
# Install packages<% unless base_requirements.empty? -%> needed to install <%= base_requirements %><% end %>
|
44
|
+
# Install base packages<% unless base_requirements.empty? -%> needed to install <%= base_requirements %><% end %>
|
39
45
|
<%= render partial: 'apt_install', locals: {packages: base_packages, clean: true, repos: base_repos} %>
|
40
46
|
|
41
47
|
<% end -%>
|
48
|
+
# Set production environment
|
49
|
+
ENV <%= base_env.join(" \\\n ") %>
|
50
|
+
|
42
51
|
<% if using_execjs? and node_version != 'lts' -%>
|
43
52
|
<%= render partial: 'install_node', locals: {yarn_version: nil} %>
|
44
53
|
|
@@ -54,7 +63,7 @@ FROM base AS <%= parallel? ? 'pre' : '' %>build
|
|
54
63
|
|
55
64
|
<% end -%>
|
56
65
|
# Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
|
57
|
-
<%= render partial: 'apt_install', locals: {packages: build_packages, clean:
|
66
|
+
<%= render partial: 'apt_install', locals: {packages: build_packages, clean: true, repos: ''} %>
|
58
67
|
|
59
68
|
<% if parallel? -%>
|
60
69
|
|
@@ -113,13 +122,12 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
|
|
113
122
|
RUN --mount=type=secret,id=gemserver_credentials,target=/kaniko/gemserver_credentials \
|
114
123
|
<%= private_gemserver_env_variable_name %>="$(cat /kaniko/gemserver_credentials)" && \
|
115
124
|
export <%= private_gemserver_env_variable_name %> && \
|
116
|
-
bundle install
|
117
|
-
bundle exec bootsnap precompile --gemfile<% end %> && \
|
125
|
+
bundle install && \
|
118
126
|
<% else -%>
|
119
|
-
RUN <% if options["precompiled-gems"] != true %>bundle config set force_ruby_platform true && \<%= "\n " %><% end %>bundle install
|
120
|
-
bundle exec bootsnap precompile --gemfile<% end %> && \
|
127
|
+
RUN <% if options["precompiled-gems"] != true %>bundle config set force_ruby_platform true && \<%= "\n " %><% end %>bundle install && \
|
121
128
|
<% end -%>
|
122
|
-
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
|
129
|
+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git<% if depend_on_bootsnap? && options.precompile != "defer" -%> && \
|
130
|
+
bundle exec bootsnap precompile --gemfile<% end %>
|
123
131
|
|
124
132
|
<% end -%>
|
125
133
|
<% if using_passenger? -%>
|
@@ -298,12 +306,16 @@ COPY <<-"EOF" /rails/Procfile.prod
|
|
298
306
|
EOF
|
299
307
|
|
300
308
|
<% end -%>
|
309
|
+
<% if using_thruster? -%>
|
310
|
+
# Start server via Thruster by default, this can be overwritten at runtime
|
311
|
+
<% else -%>
|
301
312
|
# Start the server by default, this can be overwritten at runtime
|
313
|
+
<% end -%>
|
302
314
|
EXPOSE <%= using_thruster? ? '80' : '3000' %>
|
303
315
|
<% if deploy_database == 'sqlite3' -%>
|
304
316
|
VOLUME /data
|
305
317
|
<% end -%>
|
306
|
-
<% unless fly_processes -%>
|
318
|
+
<% unless fly_processes && !using_thruster? -%>
|
307
319
|
<% if !options.procfile.blank? -%>
|
308
320
|
CMD ["foreman", "start", "--procfile=<%= options.procfile %>"]
|
309
321
|
<% elsif procfile.size > 1 -%>
|
@@ -91,7 +91,7 @@ services:
|
|
91
91
|
redis-db:
|
92
92
|
image: redis
|
93
93
|
<% end -%>
|
94
|
-
<% if (using_sidekiq?
|
94
|
+
<% if (using_sidekiq? and deploy_database != 'sqlite3') or solidq_launcher == :process -%>
|
95
95
|
|
96
96
|
<%= using_sidekiq? ? "sidekiq" : "solidq" %>:
|
97
97
|
build: .
|
@@ -4,6 +4,14 @@
|
|
4
4
|
#!/bin/bash -e
|
5
5
|
<% end -%>
|
6
6
|
|
7
|
+
<% if options.jemalloc? -%>
|
8
|
+
# Enable jemalloc for reduced memory usage and latency.
|
9
|
+
if [ -z "${LD_PRELOAD+x}" ]; then
|
10
|
+
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
|
11
|
+
export LD_PRELOAD
|
12
|
+
fi
|
13
|
+
|
14
|
+
<% end -%>
|
7
15
|
<% if options.swap && !File.exist?("fly.toml")-%>
|
8
16
|
<% if run_as_root? or using_passenger? -%>
|
9
17
|
<% @space = "" -%>
|
@@ -36,17 +44,13 @@ fi
|
|
36
44
|
<% end -%>
|
37
45
|
<% if options.prepare -%>
|
38
46
|
<% if !options.procfile.blank? -%>
|
39
|
-
|
47
|
+
# If running the specified procfile then create or migrate existing database
|
40
48
|
<% elsif procfile.size > 1 -%>
|
41
49
|
# If running the production procfile then create or migrate existing database
|
42
|
-
if [ "${*}" == "foreman start --procfile=Procfile.prod" ]; then
|
43
|
-
<% elsif procfile.values.first.start_with? "./bin/rails server" -%>
|
44
|
-
# If running the rails server then create or migrate existing database
|
45
|
-
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]<% if using_litefs? %> && [ "$FLY_REGION" == "$PRIMARY_REGION" ]<%end%>; then
|
46
50
|
<% else -%>
|
47
51
|
# If running the rails server then create or migrate existing database
|
48
|
-
if [ "${*}" == <%= procfile.values.first.inspect %> <% if using_litefs? %>-a "$FLY_REGION" == "$PRIMARY_REGION" <%end%>]; then
|
49
52
|
<% end -%>
|
53
|
+
if <%= start_command.map.with_index {|word, index| "[ \"${@: #{index - start_command.length}:1}\" == #{shellescape(word)} ]"}.join(" && ") %><% if using_litefs? %> && [ "$FLY_REGION" == "$PRIMARY_REGION" ]<%end%>; then
|
50
54
|
<% if options.precompile == "defer" -%>
|
51
55
|
./bin/rails assets:precompile
|
52
56
|
<% end -%>
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# Ignore git directory.
|
4
4
|
/.git/
|
5
|
+
/.gitignore
|
5
6
|
|
6
7
|
# Ignore bundler config.
|
7
8
|
/.bundle
|
8
9
|
|
9
|
-
# Ignore all environment files
|
10
|
+
# Ignore all environment files.
|
10
11
|
/.env*
|
11
|
-
!/.env*.erb
|
12
12
|
|
13
13
|
# Ignore all default key files.
|
14
14
|
/config/master.key
|
@@ -50,4 +50,18 @@ GEMSERVER_CREDENTIALS.secret.txt
|
|
50
50
|
<% end -%>
|
51
51
|
/public/assets
|
52
52
|
<% end -%>
|
53
|
+
|
54
|
+
# Ignore CI service files.
|
55
|
+
/.github
|
56
|
+
|
57
|
+
# Ignore Kamal files.
|
58
|
+
/config/deploy*.yml
|
59
|
+
/.kamal
|
60
|
+
|
61
|
+
# Ignore development files
|
62
|
+
/.devcontainer
|
63
|
+
|
64
|
+
# Ignore Docker-related files
|
65
|
+
/.dockerignore
|
66
|
+
/Dockerfile*
|
53
67
|
<%= more_docker_ignores -%>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
LITESTREAM_CONFIG = ENV["LITESTREAM_CONFIG"] || Rails.root.join("tmp/litestream.yml").to_s
|
2
|
+
|
3
|
+
LITESTREAM_TEMPLATE = <<-EOF
|
4
|
+
# This is the configuration file for litestream.
|
5
|
+
#
|
6
|
+
# For more details, see: https://litestream.io/reference/config/
|
7
|
+
#
|
8
|
+
dbs:
|
9
|
+
<%% for db in @dbs -%>
|
10
|
+
- path: <%%= db %>
|
11
|
+
replicas:
|
12
|
+
- type: s3
|
13
|
+
endpoint: $AWS_ENDPOINT_URL_S3
|
14
|
+
bucket: $BUCKET_NAME
|
15
|
+
path: storage/<%%= File.basename(db) %>
|
16
|
+
access-key-id: $AWS_ACCESS_KEY_ID
|
17
|
+
secret-access-key: $AWS_SECRET_ACCESS_KEY
|
18
|
+
<%% end -%>
|
19
|
+
EOF
|
20
|
+
|
21
|
+
namespace :litestream do
|
22
|
+
task prepare: "db:load_config" do
|
23
|
+
require "erubi"
|
24
|
+
|
25
|
+
@dbs =
|
26
|
+
ActiveRecord::Base
|
27
|
+
.configurations
|
28
|
+
.configs_for(env_name: "production", include_hidden: true)
|
29
|
+
.select { |config| [ "sqlite3", "litedb" ].include? config.adapter }
|
30
|
+
.map(&:database)
|
31
|
+
|
32
|
+
result = eval(Erubi::Engine.new(LITESTREAM_TEMPLATE).src)
|
33
|
+
|
34
|
+
unless File.exist?(LITESTREAM_CONFIG) && File.read(LITESTREAM_CONFIG) == result
|
35
|
+
File.write(LITESTREAM_CONFIG, result)
|
36
|
+
end
|
37
|
+
|
38
|
+
@dbs.each do |db|
|
39
|
+
next if File.exist?(db) or !ENV["BUCKET_NAME"]
|
40
|
+
system "litestream restore -config #{LITESTREAM_CONFIG} -if-replica-exists #{db}"
|
41
|
+
exit $?.exitstatus unless $?.exitstatus == 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :run do
|
46
|
+
require "shellwords"
|
47
|
+
|
48
|
+
exec(*%w[bundle exec litestream replicate -config],
|
49
|
+
LITESTREAM_CONFIG, "-exec", Shellwords.join(ARGV[1..-1]))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :db do
|
54
|
+
task prepare: "litestream:prepare"
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerfile-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
@@ -24,7 +23,6 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: 3.0.0
|
27
|
-
description:
|
28
26
|
email: rubys@intertwingly.net
|
29
27
|
executables: []
|
30
28
|
extensions: []
|
@@ -52,6 +50,7 @@ files:
|
|
52
50
|
- lib/generators/templates/dockerignore.erb
|
53
51
|
- lib/generators/templates/fly.toml.erb
|
54
52
|
- lib/generators/templates/litefs.yml.erb
|
53
|
+
- lib/generators/templates/litestream.rake.erb
|
55
54
|
- lib/generators/templates/node-version.erb
|
56
55
|
- lib/generators/templates/rollbar.rb.erb
|
57
56
|
- lib/generators/templates/sentry.rb.erb
|
@@ -60,7 +59,6 @@ licenses:
|
|
60
59
|
- MIT
|
61
60
|
metadata:
|
62
61
|
homepage_uri: https://github.com/fly-apps/dockerfile-rails
|
63
|
-
post_install_message:
|
64
62
|
rdoc_options: []
|
65
63
|
require_paths:
|
66
64
|
- lib
|
@@ -75,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
73
|
- !ruby/object:Gem::Version
|
76
74
|
version: '0'
|
77
75
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
76
|
+
rubygems_version: 3.6.2
|
80
77
|
specification_version: 4
|
81
78
|
summary: Dockerfile generator for Rails
|
82
79
|
test_files: []
|