dockerfile-rails 1.2.1 → 1.2.2
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 +8 -2
- data/Rakefile +27 -0
- data/lib/generators/dockerfile_generator.rb +20 -2
- data/lib/generators/templates/Dockerfile.erb +7 -7
- 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: a56568105d5613dd366d84227a550dcdbc3f1f71460330772aa32c128ce5b922
|
4
|
+
data.tar.gz: 7b8539f3fb1ef2b26a29a9f33d7dccd825e433ddfdbc7034f6828118764f596f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae18c0c80988fd501ffa053f31752f73e2d6c8d94784b701bda85e5c1e7a01c5d0d12c48f9b8f1f6cf3c2f5a4bb718d1f5648a686bc5e819e09021c03c8c5de4
|
7
|
+
data.tar.gz: 3d4731ad7b9cc8b81c48fdb58a8324eee1c0b999a64cbe3fe27f2bde84afab6f7f7d83d09f5a40f6c829acfc8e235405e7126d6648e69282d4d68ec8e24436b3
|
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
@@ -77,9 +77,15 @@ Options are saved between runs into `config/dockerfile.yml`. To invert a boolea
|
|
77
77
|
|
78
78
|
## Testing
|
79
79
|
|
80
|
-
|
80
|
+
A single invocation of `rake test:all` will run all of the tests defined. dockerfile-rails has are three types of tests:
|
81
81
|
|
82
|
-
|
82
|
+
* `rake test:rubocop` runs [rubocop](https://github.com/rubocop/rubocop) using the same options as the Rails codebase.
|
83
|
+
* `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.
|
84
|
+
* `rake test` runs integration tests, as described below
|
85
|
+
|
86
|
+
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.
|
87
|
+
|
88
|
+
Running all integration tests, or even a single individual test can be done as follows:
|
83
89
|
|
84
90
|
```
|
85
91
|
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
|
@@ -214,7 +214,7 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
214
214
|
package = JSON.load_file("package.json")
|
215
215
|
unless package.dig("scripts", "build")
|
216
216
|
package["scripts"] ||= {}
|
217
|
-
package["scripts"]["build"]
|
217
|
+
package["scripts"]["build"] ||= "vite build --outDir public"
|
218
218
|
|
219
219
|
say_status :update, "package.json"
|
220
220
|
IO.write("package.json", JSON.pretty_generate(package))
|
@@ -293,6 +293,8 @@ private
|
|
293
293
|
end
|
294
294
|
|
295
295
|
def install_gems
|
296
|
+
ENV["BUNDLE_IGNORE_MESSAGES"] = "1"
|
297
|
+
|
296
298
|
if options.postgresql? || @postgresql
|
297
299
|
system "bundle add pg" unless @gemfile.include? "pg"
|
298
300
|
end
|
@@ -304,6 +306,22 @@ private
|
|
304
306
|
if options.redis? || using_redis?
|
305
307
|
system "bundle add redis" unless @gemfile.include? "redis"
|
306
308
|
end
|
309
|
+
|
310
|
+
# ensure linux platform is in the bundle lock
|
311
|
+
current_platforms = `bundle platform`
|
312
|
+
add_platforms = []
|
313
|
+
|
314
|
+
if !current_platforms.include?("x86_64-linux")
|
315
|
+
add_platforms += ["--add-platform=x86_64-linux"]
|
316
|
+
end
|
317
|
+
|
318
|
+
if !current_platforms.include?("aarch64-linux") && RUBY_PLATFORM.start_with?("arm64")
|
319
|
+
add_platforms += ["--add-platform=aarch64-linux"]
|
320
|
+
end
|
321
|
+
|
322
|
+
unless add_platforms.empty?
|
323
|
+
system "bundle lock #{add_platforms.join(" ")}"
|
324
|
+
end
|
307
325
|
end
|
308
326
|
|
309
327
|
def base_packages
|
@@ -447,7 +465,7 @@ private
|
|
447
465
|
def base_env
|
448
466
|
env = {
|
449
467
|
"RAILS_ENV" => "production",
|
450
|
-
"
|
468
|
+
"BUNDLE_DEPLOYMENT" => "1",
|
451
469
|
"BUNDLE_WITHOUT" => options.ci? ? "development" : "development:test"
|
452
470
|
}
|
453
471
|
|
@@ -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
35
|
<% if options.ci? -%>
|
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 --frozen-lockfile
|
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.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-02-
|
11
|
+
date: 2023-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|