dockerfile-rails 1.2.3 → 1.2.5

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: 98b182ee88ad6c1ba34edb41778c9d59dd329eefb6b199ede26697ded174aedb
4
- data.tar.gz: 94e946801bc23ae53ce8ba8a4c7f8129a58e04aad1db4b9cf05bc5d43b22cebb
3
+ metadata.gz: 6f8b3176721310f5c043a7c2642f12b59fa7bc2952fb73f6e6164d199d24bc5a
4
+ data.tar.gz: 995b15167890754208baef9bc6ff48613e8cef121083f8d70c1be77593b5beb4
5
5
  SHA512:
6
- metadata.gz: f20bb484ad3637c100cf2ff9a786404a686e961db71dbfdc1d48d0b33ea461c8031bb2ddacc05ebd3857aaa5d318fe2d49c2ecc21cd760b1fa08fac9e963a28f
7
- data.tar.gz: 80f23221cf71777312e57165a23b93a165feae6db3af97ac8c836e71295493ff952ca34f36e2a190f392508fb0e8a92b56a42c090262076063d75b386b96be56
6
+ metadata.gz: 7f05f65f85a29fcfc242682ab6464adb88f9e0725fffe1c65c192c342e12444c3dbaff9f855ff28ccb94ea13fa706918b71609af06a87673007407083e77dd2c
7
+ data.tar.gz: 5bcca34771c67bf29e28be9a0342fbd9dac8a13694f3416d0b27a2070cabf0e38017ed195ecf2b1a80a03150698cb62502e73d63ec603500bb927fa627cd73aa
data/README.md CHANGED
@@ -41,7 +41,9 @@ bin/rails generate dockerfile
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-link` - don't add [--link](https://docs.docker.com/engine/reference/builder/#copy---link) to COPY statements. Some tools (like at the moment, [buildah](https://www.redhat.com/en/topics/containers/what-is-buildah)) don't yet support this feature.
44
45
  * `--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).
46
+ * `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment
45
47
 
46
48
  ### Add a Database:
47
49
 
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ namespace :test do
36
36
  'Rails.application.routes.draw {get "/up", to: proc {[200, {}, ["ok"]]}}'
37
37
  sh "docker buildx build . --load -t system:test"
38
38
  key = IO.read("config/master.key")
39
- sh "docker run -p 3000:3000 -e RAILS_MASTER_KEY=#{key} system:test"
39
+ sh "docker run -p 3000:3000 -e RAILS_MASTER_KEY=#{key} --rm system:test"
40
40
  end
41
41
  ensure
42
42
  rm_rf "test/tmp/system_test"
@@ -6,7 +6,7 @@ require_relative "../dockerfile-rails/scanner.rb"
6
6
  class DockerfileGenerator < Rails::Generators::Base
7
7
  include DockerfileRails::Scanner
8
8
 
9
- OPTION_DEFAULTS = {
9
+ BASE_DEFAULTS = {
10
10
  "bin-cd" => false,
11
11
  "cache" => false,
12
12
  "ci" => false,
@@ -14,6 +14,7 @@ class DockerfileGenerator < Rails::Generators::Base
14
14
  "fullstaq" => false,
15
15
  "jemalloc" => false,
16
16
  "label" => {},
17
+ "link" => true,
17
18
  "lock" => true,
18
19
  "mysql" => false,
19
20
  "nginx" => false,
@@ -25,10 +26,13 @@ class DockerfileGenerator < Rails::Generators::Base
25
26
  "redis" => false,
26
27
  "root" => false,
27
28
  "sqlite3" => false,
29
+ "sudo" => false,
28
30
  "swap" => nil,
29
31
  "yjit" => false,
30
32
  }.then { |hash| Struct.new(*hash.keys.map(&:to_sym)).new(*hash.values) }
31
33
 
34
+ OPTION_DEFAULTS = BASE_DEFAULTS.dup
35
+
32
36
  @@labels = {}
33
37
  @@packages = { "base" => [], "build" => [], "deploy" => [] }
34
38
  @@vars = { "base" => {}, "build" => {}, "deploy" => {} }
@@ -68,6 +72,9 @@ class DockerfileGenerator < Rails::Generators::Base
68
72
  class_option :ci, type: :boolean, default: OPTION_DEFAULTS.ci,
69
73
  desc: "include test gems in bundle"
70
74
 
75
+ class_option :link, type: :boolean, default: OPTION_DEFAULTS.lock,
76
+ desc: "use COPY --link whenever possible"
77
+
71
78
  class_option :lock, type: :boolean, default: OPTION_DEFAULTS.lock,
72
79
  desc: "lock Gemfile/package.json"
73
80
 
@@ -125,6 +132,8 @@ class DockerfileGenerator < Rails::Generators::Base
125
132
  class_option :root, type: :boolean, default: OPTION_DEFAULTS.root,
126
133
  desc: "Run application as root user"
127
134
 
135
+ class_option :sudo, type: :boolean, default: OPTION_DEFAULTS.sudo,
136
+ desc: "Install and configure sudo to enable running as rails with full environment"
128
137
 
129
138
  class_option "add-base", type: :array, default: [],
130
139
  desc: "additional packages to install for both build and deploy"
@@ -212,18 +221,27 @@ class DockerfileGenerator < Rails::Generators::Base
212
221
 
213
222
  template "docker-compose.yml.erb", "docker-compose.yml" if options.compose
214
223
 
215
- template "dockerfile.yml.erb", "config/dockerfile.yml", force: true
216
-
217
224
  if @gemfile.include?("vite_ruby")
218
225
  package = JSON.load_file("package.json")
219
226
  unless package.dig("scripts", "build")
220
227
  package["scripts"] ||= {}
221
- package["scripts"]["build"] ||= "vite build --outDir public"
228
+ package["scripts"]["build"] = "vite build --outDir public"
222
229
 
223
230
  say_status :update, "package.json"
224
231
  IO.write("package.json", JSON.pretty_generate(package))
225
232
  end
226
233
  end
234
+
235
+ @dockerfile_config = (@dockerfile_config.to_a - BASE_DEFAULTS.to_h.stringify_keys.to_a).to_h
236
+ %w(packages envs args).each do |key|
237
+ @dockerfile_config.delete key if @dockerfile_config[key].empty?
238
+ end
239
+
240
+ if !@dockerfile_config.empty?
241
+ template "dockerfile.yml.erb", "config/dockerfile.yml", force: true
242
+ elsif File.exist? "config/dockerfile.yml"
243
+ remove_file "config/dockerfile.yml"
244
+ end
227
245
  end
228
246
 
229
247
  private
@@ -301,6 +319,10 @@ private
301
319
 
302
320
  gemfile = IO.read("Gemfile")
303
321
 
322
+ unless /^\s*source\s/.match?(gemfile)
323
+ gemfile = %{source "https://rubygems.org"\n} + gemfile
324
+ end
325
+
304
326
  if options.postgresql? || @postgresql
305
327
  system "bundle add pg --skip-install" unless @gemfile.include? "pg"
306
328
  end
@@ -343,6 +365,16 @@ private
343
365
  end
344
366
  end
345
367
 
368
+ def base_gems
369
+ gems = ["bundler"]
370
+
371
+ if options.ci? && options.lock? && @gemfile.include?("debug")
372
+ gems += %w(irb reline) - @gemfile
373
+ end
374
+
375
+ gems.sort
376
+ end
377
+
346
378
  def base_packages
347
379
  packages = []
348
380
  packages += @@packages["base"] if @@packages["base"]
@@ -454,6 +486,9 @@ private
454
486
  # nginx
455
487
  packages << "nginx" if options.nginx?
456
488
 
489
+ # sudo
490
+ packages << "sudo" if options.sudo?
491
+
457
492
  packages.sort
458
493
  end
459
494
 
@@ -32,10 +32,7 @@ ENV <%= base_env.join(" \\\n ") %>
32
32
 
33
33
  # Update gems and bundler
34
34
  RUN gem update --system --no-document && \
35
- <% if options.ci? and options.lock? -%>
36
- gem install -N irb reline && \
37
- <% end -%>
38
- gem install -N bundler
35
+ gem install -N <%= base_gems.join(" ") %>
39
36
 
40
37
  <% unless base_requirements.empty? -%>
41
38
  # Install packages needed to install <%= base_requirements %>
@@ -82,7 +79,7 @@ ENV <%= build_env.join(" \\\n ") %>
82
79
 
83
80
  <% end -%>
84
81
  # Install application gems
85
- COPY Gemfile Gemfile.lock .
82
+ COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock ./
86
83
  <% if options.cache? -%>
87
84
  RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
88
85
  bundle config set app_config .bundle && \
@@ -98,7 +95,8 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
98
95
 
99
96
  <% else -%>
100
97
  RUN bundle install<% if depend_on_bootsnap? -%> && \
101
- bundle exec bootsnap precompile --gemfile<% end %>
98
+ bundle exec bootsnap precompile --gemfile<% end %> && \
99
+ rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
102
100
 
103
101
  <% end -%>
104
102
  <% if parallel? -%>
@@ -110,7 +108,7 @@ COPY --from=node /rails/node_modules /rails/node_modules
110
108
 
111
109
  <% end -%>
112
110
  # Copy application code
113
- COPY . .
111
+ COPY<% if options.link? %> --link<% end %> . .
114
112
 
115
113
  <% if depend_on_bootsnap? -%>
116
114
  # Precompile bootsnap code for faster boot times
@@ -161,8 +159,10 @@ ARG UID=1000 \
161
159
  GID=1000
162
160
  RUN groupadd -f -g $GID rails && \
163
161
  useradd -u $UID -g $GID rails<% else -%>
164
- RUN useradd rails<% end -%><% if options.nginx? %> && \
165
- chown rails:rails /var/lib/nginx /var/log/nginx/*<% end %>
162
+ RUN useradd rails<% end -%> --home /rails --shell /bin/bash<% if options.nginx? %> && \
163
+ chown rails:rails /var/lib/nginx /var/log/nginx/*<% end %><% if deploy_packages.include?("sudo") && options.sudo? %> && \
164
+ sed -i 's/env_reset/env_keep="*"/' /etc/sudoers && \
165
+ chown rails:rails .<% end %>
166
166
  <% unless options.swap -%>
167
167
  USER rails:rails
168
168
  <% end -%>
@@ -9,5 +9,5 @@ ENV NODE_ENV=production
9
9
  <%= render partial: 'npm_install', locals: {sources: api_client_files} %>
10
10
 
11
11
  # build client application
12
- COPY <%= api_client_dir %> .
13
- RUN npm run build
12
+ COPY<% if options.link? %> --link<% end %> <%= api_client_dir %> .
13
+ RUN npm run build
@@ -1,5 +1,5 @@
1
1
  # Install node modules
2
- COPY <%=sources.join(' ') %> .
2
+ COPY<% if options.link? %> --link<% end %> <%= sources.join(' ') %> ./
3
3
  <% if sources.join.include? 'yarn' -%>
4
4
  RUN <% if options.cache? -%>--mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
5
5
  YARN_CACHE_FOLDER=/root/.yarn <% end -%>yarn install<% if options.lock? %> --frozen-lockfile<% end %>
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.3
4
+ version: 1.2.5
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-27 00:00:00.000000000 Z
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails