dockerfile-rails 1.2.1 → 1.2.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 +4 -4
- data/DEMO.md +5 -5
- data/README.md +10 -3
- data/Rakefile +27 -0
- data/lib/generators/dockerfile_generator.rb +46 -12
- data/lib/generators/templates/Dockerfile.erb +9 -9
- data/lib/generators/templates/_install_node.erb +7 -6
- data/lib/generators/templates/_npm_install.erb +2 -6
- data/lib/generators/templates/dockerignore.erb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b182ee88ad6c1ba34edb41778c9d59dd329eefb6b199ede26697ded174aedb
|
4
|
+
data.tar.gz: 94e946801bc23ae53ce8ba8a4c7f8129a58e04aad1db4b9cf05bc5d43b22cebb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f20bb484ad3637c100cf2ff9a786404a686e961db71dbfdc1d48d0b33ea461c8031bb2ddacc05ebd3857aaa5d318fe2d49c2ecc21cd760b1fa08fac9e963a28f
|
7
|
+
data.tar.gz: 80f23221cf71777312e57165a23b93a165feae6db3af97ac8c836e71295493ff952ca34f36e2a190f392508fb0e8a92b56a42c090262076063d75b386b96be56
|
data/DEMO.md
CHANGED
@@ -11,7 +11,7 @@ echo 'Rails.application.routes.draw { root "rails/welcome#index" }' > config/rou
|
|
11
11
|
bundle add dockerfile-rails --optimistic --group development
|
12
12
|
bin/rails generate dockerfile
|
13
13
|
docker buildx build . -t rails-demo
|
14
|
-
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-demo
|
14
|
+
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails-demo
|
15
15
|
```
|
16
16
|
|
17
17
|
# Demo 2 - Neofetch
|
@@ -45,7 +45,7 @@ EOF
|
|
45
45
|
bundle add dockerfile-rails --optimistic --group development
|
46
46
|
bin/rails generate dockerfile --add neofetch colorized-logs
|
47
47
|
docker buildx build . -t rails-demo
|
48
|
-
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-demo
|
48
|
+
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails-demo
|
49
49
|
```
|
50
50
|
|
51
51
|
Add `--load` to the `buildx` command if you want to save the image to local Docker.
|
@@ -187,7 +187,7 @@ bundle add dockerfile-rails --optimistic --group development
|
|
187
187
|
bin/rails generate dockerfile
|
188
188
|
|
189
189
|
docker buildx build . -t rails-demo
|
190
|
-
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-demo
|
190
|
+
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails-demo
|
191
191
|
```
|
192
192
|
|
193
193
|
# Demo 5 - Bunding Javascript (esbuild)
|
@@ -307,7 +307,7 @@ bundle add dockerfile-rails --optimistic --group development
|
|
307
307
|
bin/rails generate dockerfile
|
308
308
|
|
309
309
|
docker buildx build . -t rails-demo
|
310
|
-
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-demo
|
310
|
+
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails-demo
|
311
311
|
```
|
312
312
|
|
313
313
|
# Demo 6 - Grover / puppeteer / Chromium
|
@@ -337,5 +337,5 @@ EOF
|
|
337
337
|
bundle add dockerfile-rails --optimistic --group development
|
338
338
|
bin/rails generate dockerfile
|
339
339
|
docker buildx build . -t rails-demo
|
340
|
-
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-demo
|
340
|
+
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails-demo
|
341
341
|
```
|
data/README.md
CHANGED
@@ -36,11 +36,12 @@ bin/rails generate dockerfile
|
|
36
36
|
* `--cache` - use build caching to speed up builds
|
37
37
|
* `--parallel` - use multi-stage builds to install gems and node modules in parallel
|
38
38
|
|
39
|
-
### Add a Feature:
|
39
|
+
### Add/remove a Feature:
|
40
40
|
|
41
41
|
* `--ci` - include test gems in deployed image
|
42
42
|
* `--compose` - generate a `docker-compose.yml` file
|
43
43
|
* `--nginx` - serve static files via [nginx](https://www.nginx.com/). May require `--root` on some targets to access `/dev/stdout`
|
44
|
+
* `--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).
|
44
45
|
|
45
46
|
### Add a Database:
|
46
47
|
|
@@ -77,9 +78,15 @@ Options are saved between runs into `config/dockerfile.yml`. To invert a boolea
|
|
77
78
|
|
78
79
|
## Testing
|
79
80
|
|
80
|
-
|
81
|
+
A single invocation of `rake test:all` will run all of the tests defined. dockerfile-rails has are three types of tests:
|
81
82
|
|
82
|
-
|
83
|
+
* `rake test:rubocop` runs [rubocop](https://github.com/rubocop/rubocop) using the same options as the Rails codebase.
|
84
|
+
* `rake test:system` creates a new esbuild application, generates a dockerfile, builds and runs it. As this is time consuming, only one application is tested this way at this time, and a `--javascript` example was selected as it exercises a large portion of the features.
|
85
|
+
* `rake test` runs integration tests, as described below
|
86
|
+
|
87
|
+
The current integration testing strategy is to run `rails new` and `generate dockerfile` with various configurations and compare the generated artifacts with expected results. `ARG` values in `Dockerfiles` are masked before comparison.
|
88
|
+
|
89
|
+
Running all integration tests, or even a single individual test can be done as follows:
|
83
90
|
|
84
91
|
```
|
85
92
|
rake test
|
data/Rakefile
CHANGED
@@ -16,4 +16,31 @@ namespace :test do
|
|
16
16
|
ENV["TEST_CAPTURE"] = "true"
|
17
17
|
Rake::Task[:test].invoke
|
18
18
|
end
|
19
|
+
|
20
|
+
task :rubocop do
|
21
|
+
sh "rubocop"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :system do
|
25
|
+
rm_rf "test/tmp/system_test"
|
26
|
+
Dir.chdir "test/tmp" do
|
27
|
+
sh "rails new system_test --javascript esbuild"
|
28
|
+
Dir.chdir "system_test"
|
29
|
+
sh "bundle config disable_local_branch_check true"
|
30
|
+
sh "bundle config set --local local.dockerfile-rails #{__dir__}"
|
31
|
+
sh "bundle add dockerfile-rails --group development " +
|
32
|
+
"--git https://github.com/rubys/dockerfile-rails.git"
|
33
|
+
sh "bin/rails generate dockerfile"
|
34
|
+
cp "#{__dir__}/test/docker-entrypoint", "bin"
|
35
|
+
IO.write "config/routes.rb",
|
36
|
+
'Rails.application.routes.draw {get "/up", to: proc {[200, {}, ["ok"]]}}'
|
37
|
+
sh "docker buildx build . --load -t system:test"
|
38
|
+
key = IO.read("config/master.key")
|
39
|
+
sh "docker run -p 3000:3000 -e RAILS_MASTER_KEY=#{key} system:test"
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
rm_rf "test/tmp/system_test"
|
43
|
+
end
|
44
|
+
|
45
|
+
task all: %w(test:rubocop test test:system)
|
19
46
|
end
|
@@ -14,6 +14,7 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
14
14
|
"fullstaq" => false,
|
15
15
|
"jemalloc" => false,
|
16
16
|
"label" => {},
|
17
|
+
"lock" => true,
|
17
18
|
"mysql" => false,
|
18
19
|
"nginx" => false,
|
19
20
|
"parallel" => false,
|
@@ -67,6 +68,9 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
67
68
|
class_option :ci, type: :boolean, default: OPTION_DEFAULTS.ci,
|
68
69
|
desc: "include test gems in bundle"
|
69
70
|
|
71
|
+
class_option :lock, type: :boolean, default: OPTION_DEFAULTS.lock,
|
72
|
+
desc: "lock Gemfile/package.json"
|
73
|
+
|
70
74
|
class_option :precompile, type: :string, default: OPTION_DEFAULTS.precompile,
|
71
75
|
desc: 'if set to "defer", assets:precompile will be done at deploy time'
|
72
76
|
|
@@ -214,7 +218,7 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
214
218
|
package = JSON.load_file("package.json")
|
215
219
|
unless package.dig("scripts", "build")
|
216
220
|
package["scripts"] ||= {}
|
217
|
-
package["scripts"]["build"]
|
221
|
+
package["scripts"]["build"] ||= "vite build --outDir public"
|
218
222
|
|
219
223
|
say_status :update, "package.json"
|
220
224
|
IO.write("package.json", JSON.pretty_generate(package))
|
@@ -252,7 +256,7 @@ private
|
|
252
256
|
|
253
257
|
def platform
|
254
258
|
if options.platform
|
255
|
-
"--platform
|
259
|
+
"--platform=#{options.platform} "
|
256
260
|
else
|
257
261
|
""
|
258
262
|
end
|
@@ -293,16 +297,49 @@ private
|
|
293
297
|
end
|
294
298
|
|
295
299
|
def install_gems
|
300
|
+
ENV["BUNDLE_IGNORE_MESSAGES"] = "1"
|
301
|
+
|
302
|
+
gemfile = IO.read("Gemfile")
|
303
|
+
|
296
304
|
if options.postgresql? || @postgresql
|
297
|
-
system "bundle add pg" unless @gemfile.include? "pg"
|
305
|
+
system "bundle add pg --skip-install" unless @gemfile.include? "pg"
|
298
306
|
end
|
299
307
|
|
300
308
|
if options.mysql? || @mysql
|
301
|
-
system "bundle add mysql2" unless @gemfile.include? "mysql2"
|
309
|
+
system "bundle add mysql2 --skip-install" unless @gemfile.include? "mysql2"
|
302
310
|
end
|
303
311
|
|
304
312
|
if options.redis? || using_redis?
|
305
|
-
system "bundle add redis" unless @gemfile.include? "redis"
|
313
|
+
system "bundle add redis --skip-install" unless @gemfile.include? "redis"
|
314
|
+
end
|
315
|
+
|
316
|
+
# https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp/70500221#70500221
|
317
|
+
if @gemfile.include? "mail"
|
318
|
+
%w(net-smtp net-imap net-pop).each do |gem|
|
319
|
+
system "bundle add #{gem} --skip-install --require false" unless @gemfile.include? gem
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
unless gemfile == IO.read("Gemfile")
|
324
|
+
system "bundle install --quiet"
|
325
|
+
end
|
326
|
+
|
327
|
+
if options.lock?
|
328
|
+
# ensure linux platform is in the bundle lock
|
329
|
+
current_platforms = `bundle platform`
|
330
|
+
add_platforms = []
|
331
|
+
|
332
|
+
if !current_platforms.include?("x86_64-linux")
|
333
|
+
add_platforms += ["--add-platform=x86_64-linux"]
|
334
|
+
end
|
335
|
+
|
336
|
+
if !current_platforms.include?("aarch64-linux") && RUBY_PLATFORM.start_with?("arm64")
|
337
|
+
add_platforms += ["--add-platform=aarch64-linux"]
|
338
|
+
end
|
339
|
+
|
340
|
+
unless add_platforms.empty?
|
341
|
+
system "bundle lock #{add_platforms.join(" ")}"
|
342
|
+
end
|
306
343
|
end
|
307
344
|
end
|
308
345
|
|
@@ -352,9 +389,6 @@ private
|
|
352
389
|
# add git if needed to install gems
|
353
390
|
packages << "git" if @git
|
354
391
|
|
355
|
-
# add redis if Action Cable, caching, or sidekiq are used
|
356
|
-
packages << "redis" if options.redis? || using_redis?
|
357
|
-
|
358
392
|
# ActiveStorage preview support
|
359
393
|
packages << "libvips" if @gemfile.include? "ruby-vips"
|
360
394
|
|
@@ -400,9 +434,6 @@ private
|
|
400
434
|
packages << "postgresql-client" if options.postgresql? || @postgresql
|
401
435
|
packages << "default-mysql-client" if options.mysql || @mysql
|
402
436
|
|
403
|
-
# add redis in case Action Cable, caching, or sidekiq are added later
|
404
|
-
packages << "redis" if using_redis?
|
405
|
-
|
406
437
|
# ActiveStorage preview support
|
407
438
|
packages << "libvips" if @gemfile.include? "ruby-vips"
|
408
439
|
|
@@ -447,10 +478,13 @@ private
|
|
447
478
|
def base_env
|
448
479
|
env = {
|
449
480
|
"RAILS_ENV" => "production",
|
450
|
-
"BUNDLE_PATH" => "vendor/bundle",
|
451
481
|
"BUNDLE_WITHOUT" => options.ci? ? "development" : "development:test"
|
452
482
|
}
|
453
483
|
|
484
|
+
if options.lock?
|
485
|
+
env["BUNDLE_DEPLOYMENT"] = "1"
|
486
|
+
end
|
487
|
+
|
454
488
|
if @@args["base"]
|
455
489
|
env.merge! @@args["base"].to_h { |key, value| [key, "$#{key}"] }
|
456
490
|
end
|
@@ -8,7 +8,7 @@ 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}-<%=
|
11
|
+
FROM <%= platform %>quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= options.jemalloc ? 'jemalloc-' : '' %>slim<% unless options.precompile == "defer" %> as base<% end %>
|
12
12
|
<% else -%>
|
13
13
|
FROM <%= platform %>ruby:$RUBY_VERSION-slim<% unless options.precompile == "defer" %> as base<% end %>
|
14
14
|
<% end -%>
|
@@ -30,13 +30,12 @@ ARG <%= base_args.map {|key, value| "#{key}=#{value.inspect}"}.join(" \\\n ")
|
|
30
30
|
# Set production environment
|
31
31
|
ENV <%= base_env.join(" \\\n ") %>
|
32
32
|
|
33
|
-
# Update gems and
|
34
|
-
ARG BUNDLER_VERSION=<%= Bundler::VERSION %>
|
33
|
+
# Update gems and bundler
|
35
34
|
RUN gem update --system --no-document && \
|
36
|
-
<% if options.ci? -%>
|
35
|
+
<% if options.ci? and options.lock? -%>
|
37
36
|
gem install -N irb reline && \
|
38
37
|
<% end -%>
|
39
|
-
gem install -N bundler
|
38
|
+
gem install -N bundler
|
40
39
|
|
41
40
|
<% unless base_requirements.empty? -%>
|
42
41
|
# Install packages needed to install <%= base_requirements %>
|
@@ -83,12 +82,12 @@ ENV <%= build_env.join(" \\\n ") %>
|
|
83
82
|
|
84
83
|
<% end -%>
|
85
84
|
# Install application gems
|
86
|
-
COPY Gemfile Gemfile.lock
|
85
|
+
COPY Gemfile Gemfile.lock .
|
87
86
|
<% if options.cache? -%>
|
88
87
|
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
|
89
88
|
bundle config set app_config .bundle && \
|
90
89
|
bundle config set path /srv/vendor && \
|
91
|
-
bundle
|
90
|
+
bundle install && \
|
92
91
|
<% if depend_on_bootsnap? -%>
|
93
92
|
bundle exec bootsnap precompile --gemfile && \
|
94
93
|
<% end -%>
|
@@ -98,7 +97,7 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
|
|
98
97
|
cp -ar /srv/vendor .
|
99
98
|
|
100
99
|
<% else -%>
|
101
|
-
RUN bundle
|
100
|
+
RUN bundle install<% if depend_on_bootsnap? -%> && \
|
102
101
|
bundle exec bootsnap precompile --gemfile<% end %>
|
103
102
|
|
104
103
|
<% end -%>
|
@@ -170,7 +169,8 @@ USER rails:rails
|
|
170
169
|
|
171
170
|
<% end -%>
|
172
171
|
<% unless options.precompile == "defer" -%>
|
173
|
-
# Copy built
|
172
|
+
# Copy built artifacts: gems, application
|
173
|
+
COPY --from=build /usr/local/bundle /usr/local/bundle
|
174
174
|
COPY --from=build <% unless run_as_root? %>--chown=rails:rails <% end %>/rails /rails
|
175
175
|
<% if api_client_dir -%>
|
176
176
|
|
@@ -15,18 +15,19 @@ ARG YARN_VERSION=<%= yarn_version %>
|
|
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 && \
|
18
|
-
npm install -g yarn@$YARN_VERSION && \
|
19
|
-
rm -rf /tmp/node-build-master
|
20
18
|
<% end -%>
|
21
19
|
<% if yarn_version -%>
|
22
20
|
<% if yarn_version < '2' -%>
|
23
|
-
RUN npm install -g yarn@$YARN_VERSION
|
21
|
+
<% if node_version -%> <% else %>RUN<% end %> npm install -g yarn@$YARN_VERSION<% if node_version -%> && \<% end %>
|
24
22
|
<% else -%>
|
25
23
|
<% if (node_version.split('.').map(&:to_i) <=> [16,10,0]) < 0 -%>
|
26
|
-
|
24
|
+
npm i -g corepack && \
|
27
25
|
<% else -%>
|
28
|
-
|
26
|
+
corepack enable && \
|
27
|
+
<% end -%>
|
28
|
+
corepack prepare yarn@$YARN_VERSION --activate<% if node_version -%> && \<% end %>
|
29
29
|
<% end -%>
|
30
|
-
corepack prepare yarn@$YARN_VERSION --activate
|
31
30
|
<% end -%>
|
31
|
+
<% if node_version -%>
|
32
|
+
rm -rf /tmp/node-build-master
|
32
33
|
<% end -%>
|
@@ -1,12 +1,8 @@
|
|
1
1
|
# Install node modules
|
2
2
|
COPY <%=sources.join(' ') %> .
|
3
3
|
<% if sources.join.include? 'yarn' -%>
|
4
|
-
<% if options.cache?
|
5
|
-
|
6
|
-
YARN_CACHE_FOLDER=/root/.yarn yarn install
|
7
|
-
<% else -%>
|
8
|
-
RUN yarn install
|
9
|
-
<% end -%>
|
4
|
+
RUN <% if options.cache? -%>--mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
|
5
|
+
YARN_CACHE_FOLDER=/root/.yarn <% end -%>yarn install<% if options.lock? %> --frozen-lockfile<% end %>
|
10
6
|
<% else -%>
|
11
7
|
<% if options.cache? -%>
|
12
8
|
RUN --mount=type=cache,id=bld-npm-cache,target=/root/.npm \
|
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.2.
|
4
|
+
version: 1.2.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-02-
|
11
|
+
date: 2023-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|