dockerfile-rails 1.0.8 → 1.0.10

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: b2f3045de59d0f73629e9a4e8fde156434157a03efb44f2ea0e6ad635ea4de5a
4
- data.tar.gz: a39d31017f8c73bd9235336c06d3a3ee79e5ec4b48b5b284ea163d5d101475f0
3
+ metadata.gz: 53cc2b6e03a559610e57f74e509e60917c265b4b2b14838cfdf4649195a1eb74
4
+ data.tar.gz: c2f19f82cf95229926e2d8a409cc46df398d2a05988c6a691dfa51ea81b3a7cc
5
5
  SHA512:
6
- metadata.gz: 86d23b99ea73ec3189ca25668769a6f390b8a11d6efbfcd9812f24cd0170f9e01323d440d7ebdd2a42233c76707fd5c781e7697b939f3d0ba22272220c91e844
7
- data.tar.gz: 97ac9c940d08683a6ce1c086112d76ace43c275c32604a64bf6974b353220ebaa783ab5665c1b2ceb3091b2ba56dc0ad5d2b70addf106be3fffdd2587abe2c75
6
+ metadata.gz: 781b58388ee23ceee2b2b0419379659548fb777bc3476b03c1c985e01a1813fddc8bd9aad1876d2d15546e48a36a53a1721bce20ba7a3b85f2dc7c6706bac07d
7
+ data.tar.gz: 1ded24e677e58592b3e94f5e60afed20021de791949c82288365b9dabd11be57b8fd6e601a77a4368ef6273f027d6330b7d42826d906402c8514c34197a7c96c
data/README.md CHANGED
@@ -14,17 +14,27 @@ bundle add dockerfile-rails --optimistic --group development
14
14
  bin/rails generate dockerfile
15
15
  ```
16
16
 
17
- General options:
17
+ General option:
18
18
 
19
19
  * `--force` - overwrite existing files
20
+
21
+ Runtime Optimizations:
22
+
23
+ * `--fullstaq` - use [fullstaq](https://fullstaqruby.org/) [images](https://github.com/evilmartians/fullstaq-ruby-docker) on [quay.io](https://quay.io/repository/evl.ms/fullstaq-ruby?tab=tags&tag=latest)
24
+ * `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
25
+ * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
26
+ * `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes
27
+
28
+ Features:
29
+
20
30
  * `--ci` - include test gems in deployed image
21
- * `--bin-cd` - adjust binstubs to set current working directory
22
- * `--no-prepare` - omit `db:prepare`. Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases
23
- * `--platform=s` - specify target platform. See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details
31
+ * `--compose` - generate a `docker-compose.yml` file
32
+ * `--nginx` - serve static files via [nginx](https://www.nginx.com/)
33
+
34
+ Build:
35
+
24
36
  * `--cache` - use build caching to speed up builds
25
37
  * `--parallel` - use multi-stage builds to install gems and node modules in parallel
26
- * `--compose` - generate a `docker-compose.yml` file
27
- * `--label=name:value` - specify docker label. Can be used multiple times. See [LABEL](https://docs.docker.com/engine/reference/builder/#label) for details
28
38
 
29
39
  Dependencies:
30
40
 
@@ -37,12 +47,12 @@ additional support may be needed:
37
47
  * `--redis` - add redis libraries
38
48
  * `--sqlite3` - add sqlite3 libraries
39
49
 
40
- Runtime Optimizations:
50
+ Configuration:
41
51
 
42
- * `--fullstaq` - use [fullstaq](https://fullstaqruby.org/) [images](https://github.com/evilmartians/fullstaq-ruby-docker) on [quay.io](https://quay.io/repository/evl.ms/fullstaq-ruby?tab=tags&tag=latest)
43
- * `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
44
- * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
45
- * `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes
52
+ * `--bin-cd` - adjust binstubs to set current working directory
53
+ * `--no-prepare` - omit `db:prepare`. Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases
54
+ * `--platform=s` - specify target platform. See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details
55
+ * `--label=name:value` - specify docker label. Can be used multiple times. See [LABEL](https://docs.docker.com/engine/reference/builder/#label) for detail
46
56
 
47
57
  Options are saved between runs into `config/dockerfile.yml`. To invert a boolean options, add or remove a `no-` prefix from the option name.
48
58
 
@@ -20,6 +20,7 @@ class DockerfileGenerator < Rails::Generators::Base
20
20
  'swap' => nil,
21
21
  'yjit' => false,
22
22
  'label' => {},
23
+ 'nginx' => false,
23
24
  )
24
25
 
25
26
  @@labels = {}
@@ -85,6 +86,9 @@ class DockerfileGenerator < Rails::Generators::Base
85
86
  class_option :label, type: :hash, default: {},
86
87
  desc: 'Add Docker label(s)'
87
88
 
89
+ class_option :nginx, type: :boolean, default: OPTION_DEFAULTS.nginx,
90
+ desc: 'Serve static files with nginx'
91
+
88
92
  def generate_app
89
93
  source_paths.push File.expand_path('./templates', __dir__)
90
94
 
@@ -209,6 +213,12 @@ private
209
213
  # libicu63 in buster, libicu67 in bullseye, libiclu72 in bookworm...
210
214
  packages << "libicu-dev" if @gemfile.include? 'charlock_holmes'
211
215
 
216
+
217
+ if @gemfile.include? 'webp-ffi'
218
+ # https://github.com/le0pard/webp-ffi#requirements
219
+ packages += %w(libjpeg-dev libpng-dev libtiff-dev libwebp-dev)
220
+ end
221
+
212
222
  packages.sort.uniq
213
223
  end
214
224
 
@@ -291,6 +301,9 @@ private
291
301
  # Puppeteer
292
302
  packages << 'google-chrome-stable' if using_puppeteer?
293
303
 
304
+ # nginx
305
+ packages << 'nginx' if options.nginx?
306
+
294
307
  packages.sort
295
308
  end
296
309
 
@@ -315,16 +328,18 @@ private
315
328
  def deploy_env
316
329
  env = []
317
330
 
331
+ env << 'PORT="3001"' if options.nginx?
332
+
318
333
  if Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_with?('7.0')
319
334
  env << 'RAILS_LOG_TO_STDOUT="1"'
320
- env << 'RAILS_SERVE_STATIC_FILES="true"'
335
+ env << 'RAILS_SERVE_STATIC_FILES="true"' unless options.nginx?
321
336
  end
322
337
 
323
- if options.yjit
338
+ if options.yjit?
324
339
  env << 'RUBY_YJIT_ENABLE="1"'
325
340
  end
326
341
 
327
- if options.jemalloc and not options.fullstaq
342
+ if options.jemalloc? and not options.fullstaq?
328
343
  if (options.platform || Gem::Platform::local.cpu).include? 'arm'
329
344
  env << 'LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libjemalloc.so.2"'
330
345
  else
@@ -467,4 +482,17 @@ private
467
482
  'db:migrate'
468
483
  end
469
484
  end
485
+
486
+ def procfile
487
+ if options.nginx?
488
+ {
489
+ nginx: 'nginx -g "daemon off;"',
490
+ rails: './bin/rails server -p 3001'
491
+ }
492
+ else
493
+ {
494
+ rails: './bin/rails server'
495
+ }
496
+ end
497
+ end
470
498
  end
@@ -123,6 +123,13 @@ FROM base
123
123
  <%= render partial: 'apt_install', locals: {packages: deploy_packages, clean: true, repos: deploy_repos} %>
124
124
  <% end -%>
125
125
 
126
+ <% if options.nginx? -%>
127
+ <%= render partial: 'nginx' %>
128
+
129
+ <% elsif procfile.size > 1 -%>
130
+ RUN gem install foreman
131
+
132
+ <% end -%>
126
133
  # Copy built application from previous stage
127
134
  <% if options.ci? -%>
128
135
  COPY --from=build /usr/local/bundle /usr/local/bundle
@@ -146,6 +153,19 @@ ENV <%= deploy_env.join(" \\\n ") %>
146
153
  <% end -%>
147
154
  ENTRYPOINT ["/rails/bin/docker-entrypoint"]
148
155
 
156
+ <% if procfile.size > 1 -%>
157
+ # Build a Procfile for production use
158
+ COPY <<-"EOF" /rails/Procfile.prod
159
+ <% procfile.each do |name, command| -%>
160
+ <%= name %>: <%= command %>
161
+ <% end -%>
162
+ EOF
163
+
164
+ # Start the server by default, this can be overwritten at runtime
165
+ EXPOSE 3000
166
+ CMD ["foreman", "start", "--procfile=Procfile.prod"]
167
+ <% else -%>
149
168
  # Start the server by default, this can be overwritten at runtime
150
169
  EXPOSE 3000
151
170
  CMD ["./bin/rails", "server"]
171
+ <% end -%>
@@ -1,7 +1,7 @@
1
1
  # configure nginx
2
- RUN sed -i 's/access_log\s.*;/access_log \/dev\/stdout main;/' /etc/nginx/nginx.conf && \
3
- sed -i 's/error_log\s.*;/error_log \/dev\/stderr info;/' /etc/nginx/nginx.conf && \
4
- sed -i "/access_log/i\ \n\tlog_format main '\$http_fly_client_ip - \$remote_user [\$time_local] "\$request" '\n\t'\$status \$body_bytes_sent \"\$http_referer\" \"\$http_user_agent\"';" /etc/nginx/nginx.conf
2
+ RUN gem install foreman && \
3
+ sed -i 's/access_log\s.*;/access_log \/dev\/stdout;/' /etc/nginx/nginx.conf && \
4
+ sed -i 's/error_log\s.*;/error_log \/dev\/stderr info;/' /etc/nginx/nginx.conf
5
5
 
6
6
  COPY <<-"EOF" /etc/nginx/sites-available/default
7
7
  server {
@@ -11,8 +11,13 @@ echo 1 > /proc/sys/vm/overcommit_memory
11
11
 
12
12
  <% end -%>
13
13
  <% if options.prepare -%>
14
+ <% if procfile.size > 1 -%>
15
+ # If running the production procfile then create or migrate existing database
16
+ if [ "${*}" == "foreman start --procfile=Procfile.prod" ]; then
17
+ <% else -%>
14
18
  # If running the rails server then create or migrate existing database
15
19
  if [ "${*}" == "./bin/rails server" ]; then
20
+ <% end -%>
16
21
  ./bin/rails <%= dbprep_command %>
17
22
  fi
18
23
 
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.0.8
4
+ version: 1.0.10
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-05 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails