dockerfile-rails 0.3.2 → 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 +4 -4
- data/README.md +12 -2
- data/lib/erbtest.rb +19 -4
- data/lib/generators/dockerfile_generator.rb +37 -2
- data/lib/generators/templates/Dockerfile.erb +15 -31
- data/lib/generators/templates/_node_client.erb +29 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7267f137214c8c519555cc4b3775f844eb9f4028a01522b1fee0952301f488a5
|
4
|
+
data.tar.gz: a27afadb1ccc74385cc12ddd4c6dea9445487035c48babd26eaab3c4712d539d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ee1cf151c6521cdc3b29e13008716fa392e49649e6bc9614f095c911805c153e235c75704a3d0c09a6f1ffab9cb5bb3d9db92dac32fd441a7e350418bcee3f7
|
7
|
+
data.tar.gz: 993df0bde29fffa8b637cbf142e28403a02143c697f2df5c95021721b0ef4ba85e8a251d6196d99a1156b07e2f9dd82511c009df9641884892d64ec0ec3052bf
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
##
|
1
|
+
## Overview
|
2
2
|
|
3
|
-
|
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
|
24
|
-
|
25
|
-
|
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 :
|
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,
|
@@ -25,6 +27,15 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
25
27
|
class_option :mysql, type: :boolean, default: false,
|
26
28
|
desc: 'include mysql libraries'
|
27
29
|
|
30
|
+
class_option :jemalloc, type: :boolean, default: false,
|
31
|
+
desc: 'use jemalloc alternative malloc implementation'
|
32
|
+
|
33
|
+
class_option :fullstaq, type: :boolean, default: false,
|
34
|
+
descr: 'use Fullstaq Ruby image from Quay.io'
|
35
|
+
|
36
|
+
class_option :yjit, type: :boolean, default: false,
|
37
|
+
desc: 'enable YJIT optimizing compiler'
|
38
|
+
|
28
39
|
def generate_app
|
29
40
|
source_paths.push File.expand_path('./templates', __dir__)
|
30
41
|
|
@@ -43,6 +54,30 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
43
54
|
|
44
55
|
private
|
45
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
|
+
|
46
81
|
def using_node?
|
47
82
|
return @using_node if @using_node != nil
|
48
83
|
@using_node = File.exist? 'package.json'
|
@@ -175,7 +210,7 @@ private
|
|
175
210
|
end
|
176
211
|
|
177
212
|
def depend_on_bootsnap?
|
178
|
-
@gemfile.include? '
|
213
|
+
@gemfile.include? 'bootsnap'
|
179
214
|
end
|
180
215
|
|
181
216
|
def api_only?
|
@@ -3,39 +3,15 @@
|
|
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
|
-
|
7
|
-
|
8
|
-
FROM node:$NODE_VERSION-slim as client
|
9
|
-
|
10
|
-
WORKDIR /rails/<%= api_client_dir %>
|
6
|
+
<%= render partial: 'node_client' %>
|
11
7
|
|
12
|
-
ENV NODE_ENV=production
|
13
8
|
|
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
9
|
<% end -%>
|
10
|
+
<% if options.fullstaq -%>
|
11
|
+
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= @options.jemalloc ? 'jemalloc-' : '' %>slim as base
|
23
12
|
<% 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
|
35
|
-
|
36
|
-
|
37
|
-
<% end -%>
|
38
13
|
FROM ruby:$RUBY_VERSION-slim as base
|
14
|
+
<% end -%>
|
39
15
|
|
40
16
|
# Rails app lives here
|
41
17
|
WORKDIR /rails
|
@@ -99,12 +75,17 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
|
|
99
75
|
bundle config set app_config .bundle && \
|
100
76
|
bundle config set path /srv/vendor && \
|
101
77
|
bundle _${BUNDLER_VERSION}_ install && \
|
78
|
+
<% if depend_on_bootsnap? -%> && \
|
79
|
+
bundle exec bootsnap precompile --gemfile && \
|
80
|
+
<% end -%>
|
102
81
|
bundle clean && \
|
103
82
|
mkdir -p vendor && \
|
104
83
|
bundle config set path vendor && \
|
105
84
|
cp -ar /srv/vendor .
|
106
85
|
<% else -%>
|
107
|
-
RUN bundle _${BUNDLER_VERSION}_ install
|
86
|
+
RUN bundle _${BUNDLER_VERSION}_ install<% if depend_on_bootsnap? -%> && \
|
87
|
+
bundle exec bootsnap precompile --gemfile
|
88
|
+
<% end -%>
|
108
89
|
<% end -%>
|
109
90
|
|
110
91
|
<% if parallel? -%>
|
@@ -125,7 +106,7 @@ COPY . .
|
|
125
106
|
|
126
107
|
<% if depend_on_bootsnap? -%>
|
127
108
|
# Precompile bootsnap code for faster boot times
|
128
|
-
RUN bundle exec bootsnap precompile
|
109
|
+
RUN bundle exec bootsnap precompile app/ lib/
|
129
110
|
|
130
111
|
<% end -%>
|
131
112
|
<% unless binfile_fixups.empty? -%>
|
@@ -169,7 +150,10 @@ COPY --from=client /rails/<%= api_client_dir %>/build /rails/public
|
|
169
150
|
|
170
151
|
# Deployment options
|
171
152
|
ENV RAILS_LOG_TO_STDOUT="1" \
|
172
|
-
RAILS_SERVE_STATIC_FILES="true"
|
153
|
+
RAILS_SERVE_STATIC_FILES="true"<% if options.yjit %> \
|
154
|
+
RUBY_YJIT_ENABLE="1"<% end %><% if options.jemalloc and not options.fullstaq %> \
|
155
|
+
LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" \
|
156
|
+
MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true"<% end %>
|
173
157
|
|
174
158
|
# Entrypoint prepares the database.
|
175
159
|
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
@@ -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
|
+
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
|