dockerfile-rails 0.4.0 → 0.4.1

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: 438d7f814f08f6180930a72f8b2e6437cb3b53b45ff495d99a0e5abf5c85e361
4
- data.tar.gz: 71d21d72fc2aea9062fa9ba15e491083d279caa050f264e36de424a42e70ef44
3
+ metadata.gz: 7267f137214c8c519555cc4b3775f844eb9f4028a01522b1fee0952301f488a5
4
+ data.tar.gz: a27afadb1ccc74385cc12ddd4c6dea9445487035c48babd26eaab3c4712d539d
5
5
  SHA512:
6
- metadata.gz: eb59c4587e1f9b0b9dbd93b7e71e49a2211659bb3e8c9c9a58919f39b3d30963a41b954ad182c418c19df2edabbf68578494bce069306bc1947c18af1fcf1c7a
7
- data.tar.gz: d3c30f95c8f17c44e1f4bc09639ed67a246e6d3b10646a758602bf97937e0da54507e1156b9728261a15ebba8de6618266002b5e6b5b02699bf0661f45da128b
6
+ metadata.gz: 5ee1cf151c6521cdc3b29e13008716fa392e49649e6bc9614f095c911805c153e235c75704a3d0c09a6f1ffab9cb5bb3d9db92dac32fd441a7e350418bcee3f7
7
+ data.tar.gz: 993df0bde29fffa8b637cbf142e28403a02143c697f2df5c95021721b0ef4ba85e8a251d6196d99a1156b07e2f9dd82511c009df9641884892d64ec0ec3052bf
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- ## Purpose
1
+ ## Overview
2
2
 
3
- Provide Rails generators to produce Dockerfiles and related files.
3
+ Provides Rails generators to produce Dockerfiles and related files. This is being proposed as the generator to be included in Rails 7.1, and a substantial number of pull requests along those lines have already been merged. This repository contains fixes and features beyond those pull requests. Highlights:
4
+
5
+ * Supports all [Rails supported releases](https://guides.rubyonrails.org/maintenance_policy.html), not just Rails 7.1, and likely works with a number of previous releases.
6
+ * Can be customized using flags on the `generate dockerfile` command, and rerun to produce a custom tailored dockerfile based on detecting the actual features used by your application.
7
+ * Can produce a `docker-compose.yml` file for locally testing your configuration before deploying.
4
8
 
5
9
  ## Usage
6
10
 
@@ -28,6 +32,12 @@ additional support may be needed:
28
32
  * `--redis` - add redis libraries
29
33
  * `--sqlite3` - add sqlite3 libraries
30
34
 
35
+ Optimizations:
36
+
37
+ * `--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)
38
+ * `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
39
+ * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler.
40
+
31
41
  Links:
32
42
 
33
43
  * [Demos](./DEMO.md)
data/lib/erbtest.rb CHANGED
@@ -5,6 +5,7 @@ EOF
5
5
 
6
6
  require 'delegate'
7
7
  require 'forwardable'
8
+ require 'ostruct'
8
9
  class Scope < SimpleDelegator
9
10
  end
10
11
 
@@ -20,14 +21,28 @@ class ShoppingList
20
21
 
21
22
  values = {one: 'One', three: 'tHrEe'}
22
23
 
23
- scope = (Class.new(SimpleDelegator) do
24
- extend Forwardable
25
- def_delegators values, :one, :three
24
+ scope = (Class.new do
25
+ def initialize(obj, locals)
26
+ @_obj = obj
27
+ @_locals = OpenStruct.new(locals)
28
+ end
29
+
30
+ def method_missing(method, *args, &block)
31
+ if @_locals.respond_to? method
32
+ @_locals.send method, *args, &block
33
+ else
34
+ @_obj.send method, *args, &block
35
+ end
36
+ end
37
+
38
+ def get_binding
39
+ binding
40
+ end
26
41
 
27
42
  def three
28
43
  3
29
44
  end
30
- end).new(self)
45
+ end).new(self, values)
31
46
 
32
47
  puts renderer.result(scope.get_binding)
33
48
  end
@@ -1,3 +1,5 @@
1
+ require 'erb'
2
+
1
3
  class DockerfileGenerator < Rails::Generators::Base
2
4
  include DockerfileRails::Scanner
3
5
 
@@ -13,7 +15,7 @@ class DockerfileGenerator < Rails::Generators::Base
13
15
  class_option :compose, type: :boolean, default: false,
14
16
  desc: 'generate a docker-compose.yml file'
15
17
 
16
- class_option :redit, type: :boolean, default: false,
18
+ class_option :redis, type: :boolean, default: false,
17
19
  desc: 'include redis libraries'
18
20
 
19
21
  class_option :sqlite3, aliases: '--sqlite', type: :boolean, default: false,
@@ -52,6 +54,30 @@ class DockerfileGenerator < Rails::Generators::Base
52
54
 
53
55
  private
54
56
 
57
+ def render(options)
58
+ scope = (Class.new do
59
+ def initialize(obj, locals)
60
+ @_obj = obj
61
+ @_locals = OpenStruct.new(locals)
62
+ end
63
+
64
+ def method_missing(method, *args, &block)
65
+ if @_locals.respond_to? method
66
+ @_locals.send method, *args, &block
67
+ else
68
+ @_obj.send method, *args, &block
69
+ end
70
+ end
71
+
72
+ def get_binding
73
+ binding
74
+ end
75
+ end).new(self, options[:locals] || {})
76
+
77
+ template = IO.read(File.join(source_paths.last, "_#{options[:partial]}.erb"))
78
+ ERB.new(template.strip, trim_mode: '-').result(scope.get_binding)
79
+ end
80
+
55
81
  def using_node?
56
82
  return @using_node if @using_node != nil
57
83
  @using_node = File.exist? 'package.json'
@@ -184,7 +210,7 @@ private
184
210
  end
185
211
 
186
212
  def depend_on_bootsnap?
187
- @gemfile.include? 'bootstrap'
213
+ @gemfile.include? 'bootsnap'
188
214
  end
189
215
 
190
216
  def api_only?
@@ -3,35 +3,7 @@
3
3
  # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4
4
  ARG RUBY_VERSION=<%= RUBY_VERSION %>
5
5
  <% if api_client_dir -%>
6
- ARG NODE_VERSION=<%= node_version %>
7
-
8
- FROM node:$NODE_VERSION-slim as client
9
-
10
- WORKDIR /rails/<%= api_client_dir %>
11
-
12
- ENV NODE_ENV=production
13
-
14
- # Install node modules
15
- COPY <%= api_client_files.join(' ') %> .
16
- <% if api_client_files.join.include? 'yarn' -%>
17
- <% if options.cache? -%>
18
- RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
19
- YARN_CACHE_FOLDER=/root/.yarn yarn install
20
- <% else -%>
21
- RUN yarn install
22
- <% end -%>
23
- <% else -%>
24
- <% if options.cache? -%>
25
- RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.npm \
26
- npm install
27
- <% else -%>
28
- RUN npm install
29
- <% end -%>
30
- <% end -%>
31
-
32
- # build client application
33
- COPY <%= api_client_dir %> .
34
- RUN npm run build
6
+ <%= render partial: 'node_client' %>
35
7
 
36
8
 
37
9
  <% end -%>
@@ -103,12 +75,17 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
103
75
  bundle config set app_config .bundle && \
104
76
  bundle config set path /srv/vendor && \
105
77
  bundle _${BUNDLER_VERSION}_ install && \
78
+ <% if depend_on_bootsnap? -%> && \
79
+ bundle exec bootsnap precompile --gemfile && \
80
+ <% end -%>
106
81
  bundle clean && \
107
82
  mkdir -p vendor && \
108
83
  bundle config set path vendor && \
109
84
  cp -ar /srv/vendor .
110
85
  <% else -%>
111
- RUN bundle _${BUNDLER_VERSION}_ install
86
+ RUN bundle _${BUNDLER_VERSION}_ install<% if depend_on_bootsnap? -%> && \
87
+ bundle exec bootsnap precompile --gemfile
88
+ <% end -%>
112
89
  <% end -%>
113
90
 
114
91
  <% if parallel? -%>
@@ -129,7 +106,7 @@ COPY . .
129
106
 
130
107
  <% if depend_on_bootsnap? -%>
131
108
  # Precompile bootsnap code for faster boot times
132
- RUN bundle exec bootsnap precompile --gemfile app/ lib/
109
+ RUN bundle exec bootsnap precompile app/ lib/
133
110
 
134
111
  <% end -%>
135
112
  <% unless binfile_fixups.empty? -%>
@@ -0,0 +1,29 @@
1
+ ARG NODE_VERSION=<%= node_version %>
2
+
3
+ FROM node:$NODE_VERSION-slim as client
4
+
5
+ WORKDIR /rails/<%= api_client_dir %>
6
+
7
+ ENV NODE_ENV=production
8
+
9
+ # Install node modules
10
+ COPY <%= api_client_files.join(' ') %> .
11
+ <% if api_client_files.join.include? 'yarn' -%>
12
+ <% if options.cache? -%>
13
+ RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
14
+ YARN_CACHE_FOLDER=/root/.yarn yarn install
15
+ <% else -%>
16
+ RUN yarn install
17
+ <% end -%>
18
+ <% else -%>
19
+ <% if options.cache? -%>
20
+ RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.npm \
21
+ npm install
22
+ <% else -%>
23
+ RUN npm install
24
+ <% end -%>
25
+ <% end -%>
26
+
27
+ # build client application
28
+ COPY <%= api_client_dir %> .
29
+ RUN npm run build
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerfile-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -39,6 +39,7 @@ files:
39
39
  - lib/erbtest.rb
40
40
  - lib/generators/dockerfile_generator.rb
41
41
  - lib/generators/templates/Dockerfile.erb
42
+ - lib/generators/templates/_node_client.erb
42
43
  - lib/generators/templates/docker-compose.yml.erb
43
44
  - lib/generators/templates/docker-entrypoint.erb
44
45
  - lib/generators/templates/dockerignore.erb