dockerfile-rails 0.4.1 → 0.4.2

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: 7267f137214c8c519555cc4b3775f844eb9f4028a01522b1fee0952301f488a5
4
- data.tar.gz: a27afadb1ccc74385cc12ddd4c6dea9445487035c48babd26eaab3c4712d539d
3
+ metadata.gz: 0d84e3358f7afd8b5729d49e6b427e03f92eb6fe5da6a258689e933c09d721a2
4
+ data.tar.gz: 897d2a5f53c344c7162953e757b751ff646192ecd880f61cfb1754da5dfbb76d
5
5
  SHA512:
6
- metadata.gz: 5ee1cf151c6521cdc3b29e13008716fa392e49649e6bc9614f095c911805c153e235c75704a3d0c09a6f1ffab9cb5bb3d9db92dac32fd441a7e350418bcee3f7
7
- data.tar.gz: 993df0bde29fffa8b637cbf142e28403a02143c697f2df5c95021721b0ef4ba85e8a251d6196d99a1156b07e2f9dd82511c009df9641884892d64ec0ec3052bf
6
+ metadata.gz: dd9b469a7c2c562c4cf137670c0d2fa177449c00ccb109e9aca65e0c48cb07d35b0a614c64daaaae699596eb2e191c7da4fcde1fc3da0566c3deed56e1b82494
7
+ data.tar.gz: 4ec4f71ecc02555da309027504872e137ccffa936b42ef42c935f2d0349b49cbccdfc39924f284653c952096bc3ea8014d9218eed92e7e71cfac15555e860705
data/README.md CHANGED
@@ -37,6 +37,7 @@ Optimizations:
37
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
38
  * `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
39
39
  * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler.
40
+ * `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes.
40
41
 
41
42
  Links:
42
43
 
@@ -44,3 +45,4 @@ Links:
44
45
  * [Preparations for Rails 7.1](https://community.fly.io/t/preparations-for-rails-7-1/9512)
45
46
  * [Rails Dockerfile futures](https://discuss.rubyonrails.org/t/rails-dockerfile-futures/82091/1)
46
47
  * [Fly Cookbooks](https://fly.io/docs/rails/cookbooks/)
48
+ * [app/templates/Dockerfile.tt](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt)
@@ -12,6 +12,9 @@ class DockerfileGenerator < Rails::Generators::Base
12
12
  class_option :parallel, type: :boolean, default: false,
13
13
  desc: 'use build stages to install gems and node modules in parallel'
14
14
 
15
+ class_option :swap, type: :string, default: nil,
16
+ desc: 'allocate swapspace'
17
+
15
18
  class_option :compose, type: :boolean, default: false,
16
19
  desc: 'generate a docker-compose.yml file'
17
20
 
@@ -75,7 +78,7 @@ private
75
78
  end).new(self, options[:locals] || {})
76
79
 
77
80
  template = IO.read(File.join(source_paths.last, "_#{options[:partial]}.erb"))
78
- ERB.new(template.strip, trim_mode: '-').result(scope.get_binding)
81
+ ERB.new(template, trim_mode: '-').result(scope.get_binding).strip
79
82
  end
80
83
 
81
84
  def using_node?
@@ -87,6 +90,10 @@ private
87
90
  options.redis? or @redis
88
91
  end
89
92
 
93
+ def using_execjs?
94
+ @gemfile.include? 'execjs'
95
+ end
96
+
90
97
  def parallel?
91
98
  using_node? && options.parallel
92
99
  end
@@ -114,9 +121,13 @@ private
114
121
  # ActiveStorage preview support
115
122
  packages << "libvips" if @gemfile.include? 'ruby-vips'
116
123
 
124
+ # Rmagick gem
125
+ packages += %w[pkg-config libmagickwand-dev] if @gemfile.include? 'rmagick'
126
+
117
127
  # node support, including support for building native modules
118
128
  if using_node?
119
- packages += %w(curl unzip node-gyp pkg-config)
129
+ packages += %w(node-gyp pkg-config)
130
+ packages += %w(curl unzip) unless using_execjs?
120
131
 
121
132
  # module build process depends on Python, and debian changed
122
133
  # how python is installed with the bullseye release. Below
@@ -155,6 +166,9 @@ private
155
166
  # ActiveStorage preview support
156
167
  packages << "libvips" if @gemfile.include? 'ruby-vips'
157
168
 
169
+ # Rmagick gem
170
+ packages << 'imagemagick' if @gemfile.include? 'rmagick'
171
+
158
172
  packages.sort
159
173
  end
160
174
 
@@ -21,23 +21,24 @@ ENV RAILS_ENV="production" \
21
21
  BUNDLE_PATH="vendor/bundle" \
22
22
  BUNDLE_WITHOUT="<%= options.ci? ? 'test' : 'development:test' %>"
23
23
 
24
+ # Update gems and preinstall the desired version of bundler
24
25
  ARG BUNDLER_VERSION=<%= Bundler::VERSION %>
25
26
  RUN gem update --system --no-document && \
26
27
  gem install -N bundler -v ${BUNDLER_VERSION}
27
28
 
29
+ <% if using_execjs? -%>
30
+ # Install packages needed to install nodejs
31
+ <%= render partial: 'apt_install', locals: {packages: %w(curl unzip), clean: true} %>
32
+
33
+ <%= render partial: 'install_node', locals: {yarn_version: nil} %>
34
+
35
+ <% end -%>
28
36
 
29
37
  # Throw-away build stage<%= parallel? ? 's' : '' %> to reduce size of final image
30
38
  FROM base as <%= parallel? ? 'pre' : '' %>build
31
39
 
32
- # Install packages need to build gems<%= using_node? ? " and node modules" : "" %>
33
- <% if options.cache? %>
34
- RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
35
- --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
36
- apt-get update -qq && \
37
- <% else -%>
38
- RUN apt-get update -qq && \
39
- <% end -%>
40
- apt-get install -y <%= build_packages.join(" ") %>
40
+ # Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
41
+ <%= render partial: 'apt_install', locals: {packages: build_packages, clean: false} %>
41
42
 
42
43
  <% if parallel? -%>
43
44
 
@@ -45,24 +46,11 @@ FROM prebuild as node
45
46
 
46
47
  <% end -%>
47
48
  <% if using_node? -%>
48
- # Install JavaScript dependencies
49
- ARG NODE_VERSION=<%= node_version %>
50
- ARG YARN_VERSION=<%= yarn_version %>
51
- RUN curl -fsSL https://fnm.vercel.app/install | bash && \
52
- /root/.local/share/fnm/fnm install $NODE_VERSION
53
- ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH
54
- RUN npm install -g yarn@$YARN_VERSION
49
+ <%= render partial: 'install_node', locals: {node_version: using_execjs? ? nil : node_version} %>
55
50
 
56
51
  <% end -%>
57
52
  <% if parallel? -%>
58
- # Install node modules
59
- COPY package.json yarn.lock ./
60
- <% if options.cache? -%>
61
- RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
62
- YARN_CACHE_FOLDER=/root/.yarn yarn install
63
- <% else -%>
64
- RUN yarn install
65
- <% end -%>
53
+ <%= render partial: 'npm_install', locals: {sources: %w(package.json yarn.lock)} %>
66
54
 
67
55
 
68
56
  FROM prebuild as build
@@ -91,14 +79,7 @@ RUN bundle _${BUNDLER_VERSION}_ install<% if depend_on_bootsnap? -%> && \
91
79
  <% if parallel? -%>
92
80
  asdf
93
81
  <% elsif using_node? -%>
94
- # Install node modules
95
- COPY package.json yarn.lock ./
96
- <% if options.cache? -%>
97
- RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
98
- YARN_CACHE_FOLDER=/root/.yarn yarn install
99
- <% else -%>
100
- RUN yarn install
101
- <% end -%>
82
+ <%= render partial: 'npm_install', locals: {sources: %w(package.json yarn.lock)} %>
102
83
 
103
84
  <% end -%>
104
85
  # Copy application code
@@ -124,17 +105,8 @@ RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_w
124
105
  FROM base
125
106
  <% unless deploy_packages.empty? -%>
126
107
 
127
- # Install packages need for deployment
128
- <% if options.cache? -%>
129
- RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
130
- --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
131
- apt-get update -qq && \
132
- apt-get install --no-install-recommends -y <%= deploy_packages.join(" ") %>
133
- <% else -%>
134
- RUN apt-get update -qq && \
135
- apt-get install --no-install-recommends -y <%= deploy_packages.join(" ") %> && \
136
- rm -rf /var/lib/apt/lists /var/cache/apt/archives
137
- <% end -%>
108
+ # Install packages needed for deployment
109
+ <%= render partial: 'apt_install', locals: {packages: deploy_packages, clean: true} %>
138
110
  <% end -%>
139
111
 
140
112
  # Copy built application from previous stage
@@ -0,0 +1,10 @@
1
+ <% if options.cache? -%>
2
+ RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
3
+ --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
4
+ apt-get update -qq && \
5
+ apt-get install --no-install-recommends -y <%= packages.join(" ") %>
6
+ <% else -%>
7
+ RUN apt-get update -qq && \
8
+ apt-get install --no-install-recommends -y <%= packages.join(" ") %><% if clean %> && \
9
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives<% end %>
10
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ <% if node_version and yarn_version -%>
2
+ # Install JavaScript dependencies
3
+ <% elsif node_version -%>
4
+ # Install Node.js
5
+ <% elsif yarn_version -%>
6
+ # Install yarn
7
+ <% end -%>
8
+ <% if node_version -%>
9
+ ARG NODE_VERSION=<%= node_version %>
10
+ <% end -%>
11
+ <% if yarn_version -%>
12
+ ARG YARN_VERSION=<%= yarn_version %>
13
+ <% end -%>
14
+ <% if node_version -%>
15
+ RUN curl -fsSL https://fnm.vercel.app/install | bash && \
16
+ /root/.local/share/fnm/fnm install $NODE_VERSION
17
+ ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH
18
+ <% end -%>
19
+ <% if yarn_version -%>
20
+ RUN npm install -g yarn@$YARN_VERSION
21
+ <% end -%>
@@ -6,23 +6,7 @@ WORKDIR /rails/<%= api_client_dir %>
6
6
 
7
7
  ENV NODE_ENV=production
8
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 -%>
9
+ <%= render partial: 'npm_install', locals: {sources: api_client_files} %>
26
10
 
27
11
  # build client application
28
12
  COPY <%= api_client_dir %> .
@@ -0,0 +1,17 @@
1
+ # Install node modules
2
+ COPY <%=sources.join(' ') %> .
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 -%>
10
+ <% else -%>
11
+ <% if options.cache? -%>
12
+ RUN --mount=type=cache,id=bld-npm-cache,target=/root/.npm \
13
+ npm install
14
+ <% else -%>
15
+ RUN npm install
16
+ <% end -%>
17
+ <% end -%>
@@ -1,5 +1,15 @@
1
1
  #!/bin/bash
2
2
 
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
11
+
12
+ <% end -%>
3
13
  # If running the rails server then create or migrate existing database
4
14
  if [ "${*}" == "./bin/rails server" ]; then
5
15
  ./bin/rails <%= dbprep_command %>
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: 0.4.1
4
+ version: 0.4.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-01-16 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,10 +36,12 @@ files:
36
36
  - Rakefile
37
37
  - lib/dockerfile-rails.rb
38
38
  - lib/dockerfile-rails/scanner.rb
39
- - lib/erbtest.rb
40
39
  - lib/generators/dockerfile_generator.rb
41
40
  - lib/generators/templates/Dockerfile.erb
41
+ - lib/generators/templates/_apt_install.erb
42
+ - lib/generators/templates/_install_node.erb
42
43
  - lib/generators/templates/_node_client.erb
44
+ - lib/generators/templates/_npm_install.erb
43
45
  - lib/generators/templates/docker-compose.yml.erb
44
46
  - lib/generators/templates/docker-entrypoint.erb
45
47
  - lib/generators/templates/dockerignore.erb
data/lib/erbtest.rb DELETED
@@ -1,56 +0,0 @@
1
- TEMPLATE = <<-EOF
2
- value is <%= five %>
3
- other is <%= three %>
4
- EOF
5
-
6
- require 'delegate'
7
- require 'forwardable'
8
- require 'ostruct'
9
- class Scope < SimpleDelegator
10
- end
11
-
12
- require 'erb'
13
- class ShoppingList
14
- def five
15
- 'FiVe'
16
- end
17
-
18
- def initialize
19
- renderer = ERB.new(TEMPLATE)
20
- puts '***'
21
-
22
- values = {one: 'One', three: 'tHrEe'}
23
-
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
41
-
42
- def three
43
- 3
44
- end
45
- end).new(self, values)
46
-
47
- puts renderer.result(scope.get_binding)
48
- end
49
-
50
- def get_binding
51
- binding
52
- end
53
- end
54
-
55
- puts '?'
56
- test = ShoppingList.new