dockerfile-rails 1.0.9 → 1.0.11

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: 7480e08de802e1158cee8c4328191fd924ccadc99ecb5183dfdd7d2a671cc059
4
- data.tar.gz: bd652cd97e31632508f25e9d9aebeddb11e6914353b506a2a8c782a7016e1939
3
+ metadata.gz: '0896ffd69a3ec18c6014f18fa25ac9e59a162d3a30ece017b14cfe39c658759b'
4
+ data.tar.gz: d45b430289a4a2162493f26d3ba35539e674efc20a6abb985787be2c6674b9b8
5
5
  SHA512:
6
- metadata.gz: 8e1d60aed5267759f46473d793addbcea1ed2c6a762b704c645b25a03d591be90c9da969946373b608141cd6f5d5f876abd0e659a6fa188d7dc8e805413f23fa
7
- data.tar.gz: 8fcf8f92f60d6f7ceb1a48fe0b19ddc9cffa6daf4a4cd7869dd1c0734476777eeb55ae112bd321b70394500ab9889d9e53bb3500bad3fa654603b527ea8825da
6
+ metadata.gz: 8b152efcc23fd9335210024b2a4b1c505009fa5f302b2756aa929989c77cd6d3f78270062ec18ad54a4ce5a21aba75d1d8641434c92d3a480ed43da887aae8bf
7
+ data.tar.gz: 2fe3c7b25bca49c0984b00d563a5f9c158f59017d43f333dcb5da82e18e70e0861c566ac3a0c8dfbb28961b00681c83fde800eaaabc025250f5b1b97e5b932dd
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
 
@@ -297,6 +301,9 @@ private
297
301
  # Puppeteer
298
302
  packages << 'google-chrome-stable' if using_puppeteer?
299
303
 
304
+ # nginx
305
+ packages << 'nginx' if options.nginx?
306
+
300
307
  packages.sort
301
308
  end
302
309
 
@@ -321,16 +328,18 @@ private
321
328
  def deploy_env
322
329
  env = []
323
330
 
331
+ env << 'PORT="3001"' if options.nginx?
332
+
324
333
  if Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_with?('7.0')
325
334
  env << 'RAILS_LOG_TO_STDOUT="1"'
326
- env << 'RAILS_SERVE_STATIC_FILES="true"'
335
+ env << 'RAILS_SERVE_STATIC_FILES="true"' unless options.nginx?
327
336
  end
328
337
 
329
- if options.yjit
338
+ if options.yjit?
330
339
  env << 'RUBY_YJIT_ENABLE="1"'
331
340
  end
332
341
 
333
- if options.jemalloc and not options.fullstaq
342
+ if options.jemalloc? and not options.fullstaq?
334
343
  if (options.platform || Gem::Platform::local.cpu).include? 'arm'
335
344
  env << 'LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libjemalloc.so.2"'
336
345
  else
@@ -473,4 +482,17 @@ private
473
482
  'db:migrate'
474
483
  end
475
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
476
498
  end
@@ -30,6 +30,9 @@ ENV RAILS_ENV="production" \
30
30
  # Update gems and preinstall the desired version of bundler
31
31
  ARG BUNDLER_VERSION=<%= Bundler::VERSION %>
32
32
  RUN gem update --system --no-document && \
33
+ <% if options.ci? -%>
34
+ gem install -N irb reline && \
35
+ <% end -%>
33
36
  gem install -N bundler -v ${BUNDLER_VERSION}
34
37
 
35
38
  <% unless base_requirements.empty? -%>
@@ -123,10 +126,14 @@ FROM base
123
126
  <%= render partial: 'apt_install', locals: {packages: deploy_packages, clean: true, repos: deploy_repos} %>
124
127
  <% end -%>
125
128
 
126
- # Copy built application from previous stage
127
- <% if options.ci? -%>
128
- COPY --from=build /usr/local/bundle /usr/local/bundle
129
+ <% if options.nginx? -%>
130
+ <%= render partial: 'nginx' %>
131
+
132
+ <% elsif procfile.size > 1 -%>
133
+ RUN gem install foreman
134
+
129
135
  <% end -%>
136
+ # Copy built application from previous stage
130
137
  COPY --from=build /rails /rails
131
138
  <% if api_client_dir -%>
132
139
 
@@ -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.9
4
+ version: 1.0.11
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-06 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.4.2
71
+ rubygems_version: 3.4.6
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Dockerfile generator for Rails