dockerfile-rails 1.2.0 → 1.2.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: e8dc8b1f01f52091af8e9cb3322db265d96698e80fc203bfc570135efd69cb06
4
- data.tar.gz: 6054ee7cb322ed79092c6205cce1969b7ab9ad1d868113024845d90bb52d4448
3
+ metadata.gz: a56568105d5613dd366d84227a550dcdbc3f1f71460330772aa32c128ce5b922
4
+ data.tar.gz: 7b8539f3fb1ef2b26a29a9f33d7dccd825e433ddfdbc7034f6828118764f596f
5
5
  SHA512:
6
- metadata.gz: 938d057a8f5faf7cca766898b5f6406a379bf90c1fc6116c05759e38a7d7439efdad941855a8cdf4029cc9aadd0131d7463a855e702fe8a69b7746250e1bfbd5
7
- data.tar.gz: 4be1203c6fa6176c867dae6ef78511aa5e0a3c9943958430a8b77ba04cbb5368371d4ea3e100d4a037946cfd0f94ee7ced7425a1464bfe75450a3c1cc8703dbc
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
- The current 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.
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
- Running all tests, or even a single individual test can be done as follows:
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"] = "vite build --outDir public"
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
- "BUNDLE_PATH" => "vendor/bundle",
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 preinstall the desired version of bundler
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 -v ${BUNDLER_VERSION}
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 _${BUNDLER_VERSION}_ install && \
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 _${BUNDLER_VERSION}_ install<% if depend_on_bootsnap? -%> && \
100
+ RUN bundle install<% if depend_on_bootsnap? -%> && \
102
101
  bundle exec bootsnap precompile --gemfile<% end %>
103
102
 
104
103
  <% end -%>
@@ -164,11 +163,14 @@ RUN groupadd -f -g $GID rails && \
164
163
  useradd -u $UID -g $GID rails<% else -%>
165
164
  RUN useradd rails<% end -%><% if options.nginx? %> && \
166
165
  chown rails:rails /var/lib/nginx /var/log/nginx/*<% end %>
166
+ <% unless options.swap -%>
167
167
  USER rails:rails
168
+ <% end -%>
168
169
 
169
170
  <% end -%>
170
171
  <% unless options.precompile == "defer" -%>
171
- # Copy built application from previous stage
172
+ # Copy built artifacts: gems, application
173
+ COPY --from=build /usr/local/bundle /usr/local/bundle
172
174
  COPY --from=build <% unless run_as_root? %>--chown=rails:rails <% end %>/rails /rails
173
175
  <% if api_client_dir -%>
174
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
- RUN npm i -g corepack && \
24
+ npm i -g corepack && \
27
25
  <% else -%>
28
- RUN corepack enable && \
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
- RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
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 \
@@ -1,13 +1,23 @@
1
1
  #!/bin/bash -e
2
2
 
3
3
  <% if options.swap -%>
4
- # allocate swap space
5
- fallocate -l <%= options.swap %> /swapfile
6
- chmod 0600 /swapfile
7
- mkswap /swapfile
8
- echo 10 > /proc/sys/vm/swappiness
9
- swapon /swapfile
10
- echo 1 > /proc/sys/vm/overcommit_memory
4
+ <% if run_as_root? -%>
5
+ <% @space = "" -%>
6
+ <% else -%>
7
+ <% @space = " " -%>
8
+ if [ $UID -eq 0 ]; then
9
+ <% end -%>
10
+ <%= @space %># allocate swap space
11
+ <%= @space %>fallocate -l <%= options.swap %> /swapfile
12
+ <%= @space %>chmod 0600 /swapfile
13
+ <%= @space %>mkswap /swapfile
14
+ <%= @space %>echo 10 > /proc/sys/vm/swappiness
15
+ <%= @space %>swapon /swapfile
16
+ <%= @space %>echo 1 > /proc/sys/vm/overcommit_memory
17
+ <% unless run_as_root? -%>
18
+ exec su rails $0 $@
19
+ fi
20
+ <% end -%>
11
21
 
12
22
  <% end -%>
13
23
  <% if options.prepare -%>
@@ -20,10 +20,12 @@
20
20
  <% if keeps? -%>
21
21
  !/log/.keep
22
22
  !/tmp/.keep
23
+ <% end -%>
23
24
 
24
25
  # Ignore pidfiles, but keep the directory.
25
26
  /tmp/pids/*
26
27
  !/tmp/pids/
28
+ <% if keeps? -%>
27
29
  !/tmp/pids/.keep
28
30
  <% end -%>
29
31
 
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.0
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-23 00:00:00.000000000 Z
11
+ date: 2023-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails