dockerfile-rails 0.4.9 → 0.5.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 906eaaf2f4166356a6cece9b347dd58a29324a0e7a3d0f557cfea85054c34816
|
4
|
+
data.tar.gz: 0c071eb1fd4da339676916705498c18fb2d5e08e0115b8f47745def8229390e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66b27141d048276513a4384b6dd88fae87f929d2128a9e6a19187cac6a1d75f751d5e261ccd4f94424ae7ae53ca0713141db34163d04cb997a719731a6e39dde
|
7
|
+
data.tar.gz: 7e927389954e205c3cc89e6de75506d85265ac394a749f0b394d9b5263b4de719a5dc935d8ff493f1c1cfdc30854b70f7f5b77f6c48599095a7132f0f050a0cd
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## Overview
|
2
2
|
|
3
|
-
Provides Rails
|
3
|
+
Provides a Rails generator 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
4
|
|
5
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
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.
|
@@ -18,6 +18,7 @@ General options:
|
|
18
18
|
* `--force` - overwrite existing files
|
19
19
|
* `--ci` - include test gems in deployed image
|
20
20
|
* `--bin-cd` - adjust binstubs to set current working directory
|
21
|
+
* `--no-prepare` - omit `db:prepare`. Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases.
|
21
22
|
* `--platform=s` - specify target platform. See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details.
|
22
23
|
* `--cache` - use build caching to speed up builds
|
23
24
|
* `--parallel` - use multi-stage builds to install gems and node modules in parallel
|
@@ -34,13 +35,15 @@ additional support may be needed:
|
|
34
35
|
* `--redis` - add redis libraries
|
35
36
|
* `--sqlite3` - add sqlite3 libraries
|
36
37
|
|
37
|
-
Optimizations:
|
38
|
+
Runtime Optimizations:
|
38
39
|
|
39
40
|
* `--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)
|
40
41
|
* `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
|
41
42
|
* `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
|
42
43
|
* `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes
|
43
44
|
|
45
|
+
Options are saved between runs into `config/dockerfile.yml`. To invert a boolean options, add or remove a `no-` prefix from the option name.
|
46
|
+
|
44
47
|
## Testing
|
45
48
|
|
46
49
|
The current testing strategy is to run `rails new` and `generate dockerfile` with various configurations and compare the generated artifacts with expected results. `ARG` values in `Dockerfiles` are masked before comparison.
|
@@ -4,51 +4,86 @@ require_relative '../dockerfile-rails/scanner.rb'
|
|
4
4
|
class DockerfileGenerator < Rails::Generators::Base
|
5
5
|
include DockerfileRails::Scanner
|
6
6
|
|
7
|
-
|
7
|
+
OPTION_DEFAULTS = OpenStruct.new(
|
8
|
+
'bin-cd' => false,
|
9
|
+
'cache' => false,
|
10
|
+
'ci' => false,
|
11
|
+
'compose' => false,
|
12
|
+
'fullstaq' => false,
|
13
|
+
'jemalloc' => false,
|
14
|
+
'mysql' => false,
|
15
|
+
'parallel' => false,
|
16
|
+
'platform' => nil,
|
17
|
+
'prepare' => true,
|
18
|
+
'redis' => false,
|
19
|
+
'swap' => nil,
|
20
|
+
'yjit' => false,
|
21
|
+
)
|
22
|
+
|
23
|
+
# load defaults from config file
|
24
|
+
if File.exist? 'config/dockerfile.yml'
|
25
|
+
options = YAML.safe_load_file('config/dockerfile.yml', symbolize_names: true)[:options]
|
26
|
+
if options
|
27
|
+
OPTION_DEFAULTS.to_h.each do |option, value|
|
28
|
+
OPTION_DEFAULTS[option] = options[option] if options.include? option
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class_option :ci, type: :boolean, default: OPTION_DEFAULTS.ci,
|
8
34
|
desc: 'include test gems in bundle'
|
9
35
|
|
10
|
-
class_option 'bin-cd', type: :boolean, default:
|
36
|
+
class_option 'bin-cd', type: :boolean, default: OPTION_DEFAULTS['bin-cd'],
|
11
37
|
desc: 'modify binstubs to set working directory'
|
12
38
|
|
13
|
-
class_option :cache, type: :boolean, default:
|
39
|
+
class_option :cache, type: :boolean, default: OPTION_DEFAULTS.cache,
|
14
40
|
desc: 'use build cache to speed up installs'
|
15
41
|
|
16
|
-
class_option :
|
42
|
+
class_option :prepare, type: :boolean, default: OPTION_DEFAULTS.prepare,
|
43
|
+
desc: 'include db:prepare step'
|
44
|
+
|
45
|
+
class_option :parallel, type: :boolean, default: OPTION_DEFAULTS.parallel,
|
17
46
|
desc: 'use build stages to install gems and node modules in parallel'
|
18
47
|
|
19
|
-
class_option :swap, type: :string, default:
|
48
|
+
class_option :swap, type: :string, default: OPTION_DEFAULTS.swap,
|
20
49
|
desc: 'allocate swapspace'
|
21
50
|
|
22
|
-
class_option :compose, type: :boolean, default:
|
51
|
+
class_option :compose, type: :boolean, default: OPTION_DEFAULTS.compose,
|
23
52
|
desc: 'generate a docker-compose.yml file'
|
24
53
|
|
25
|
-
class_option :redis, type: :boolean, default:
|
54
|
+
class_option :redis, type: :boolean, default: OPTION_DEFAULTS.redis,
|
26
55
|
desc: 'include redis libraries'
|
27
56
|
|
28
|
-
class_option :sqlite3, aliases: '--sqlite', type: :boolean, default:
|
57
|
+
class_option :sqlite3, aliases: '--sqlite', type: :boolean, default: OPTION_DEFAULTS.sqlite3,
|
29
58
|
desc: 'include sqlite3 libraries'
|
30
59
|
|
31
|
-
class_option :postgresql, aliases: '--postgres', type: :boolean, default:
|
60
|
+
class_option :postgresql, aliases: '--postgres', type: :boolean, default: OPTION_DEFAULTS.postgresql,
|
32
61
|
desc: 'include postgresql libraries'
|
33
62
|
|
34
|
-
class_option :mysql, type: :boolean, default:
|
63
|
+
class_option :mysql, type: :boolean, default: OPTION_DEFAULTS.mysql,
|
35
64
|
desc: 'include mysql libraries'
|
36
65
|
|
37
|
-
class_option :platform, type: :string, default:
|
66
|
+
class_option :platform, type: :string, default: OPTION_DEFAULTS.platform,
|
38
67
|
desc: 'image platform (example: linux/arm64)'
|
39
68
|
|
40
|
-
class_option :jemalloc, type: :boolean, default:
|
69
|
+
class_option :jemalloc, type: :boolean, default: OPTION_DEFAULTS.jemalloc,
|
41
70
|
desc: 'use jemalloc alternative malloc implementation'
|
42
71
|
|
43
|
-
class_option :fullstaq, type: :boolean, default:
|
72
|
+
class_option :fullstaq, type: :boolean, default: OPTION_DEFAULTS.fullstaq,
|
44
73
|
descr: 'use Fullstaq Ruby image from Quay.io'
|
45
74
|
|
46
|
-
class_option :yjit, type: :boolean, default:
|
75
|
+
class_option :yjit, type: :boolean, default: OPTION_DEFAULTS.yjit,
|
47
76
|
desc: 'enable YJIT optimizing compiler'
|
48
77
|
|
49
78
|
def generate_app
|
50
79
|
source_paths.push File.expand_path('./templates', __dir__)
|
51
80
|
|
81
|
+
# gather up options for config file
|
82
|
+
@dockerfile_config = OPTION_DEFAULTS.dup.to_h.stringify_keys
|
83
|
+
options.to_h.each do |option, value|
|
84
|
+
@dockerfile_config[option] = value if @dockerfile_config.include? option
|
85
|
+
end
|
86
|
+
|
52
87
|
scan_rails_app
|
53
88
|
|
54
89
|
template 'Dockerfile.erb', 'Dockerfile'
|
@@ -60,6 +95,8 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
60
95
|
chmod "bin/docker-entrypoint", 0755 & ~File.umask, verbose: false
|
61
96
|
|
62
97
|
template 'docker-compose.yml.erb', 'docker-compose.yml' if options.compose
|
98
|
+
|
99
|
+
template 'dockerfile.yml.erb', 'config/dockerfile.yml'
|
63
100
|
end
|
64
101
|
|
65
102
|
private
|
@@ -137,7 +137,11 @@ ENV RAILS_LOG_TO_STDOUT="1" \
|
|
137
137
|
<% end -%>
|
138
138
|
MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true"<% end %>
|
139
139
|
|
140
|
+
<% if options.prepare -%>
|
140
141
|
# Entrypoint prepares the database.
|
142
|
+
<% else -%>
|
143
|
+
# Entrypoint sets up the container.
|
144
|
+
<% end -%>
|
141
145
|
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
142
146
|
|
143
147
|
# Start the server by default, this can be overwritten at runtime
|
@@ -10,9 +10,14 @@ swapon /swapfile
|
|
10
10
|
echo 1 > /proc/sys/vm/overcommit_memory
|
11
11
|
|
12
12
|
<% end -%>
|
13
|
+
<% if options.prepare -%>
|
13
14
|
# If running the rails server then create or migrate existing database
|
14
15
|
if [ "${*}" == "./bin/rails server" ]; then
|
15
16
|
./bin/rails <%= dbprep_command %>
|
16
17
|
fi
|
17
18
|
|
19
|
+
<% elsif !options.swap -%>
|
20
|
+
# Add any container initialization steps here
|
21
|
+
|
22
|
+
<% end -%>
|
18
23
|
exec "${@}"
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/generators/templates/_npm_install.erb
|
45
45
|
- lib/generators/templates/docker-compose.yml.erb
|
46
46
|
- lib/generators/templates/docker-entrypoint.erb
|
47
|
+
- lib/generators/templates/dockerfile.yml.erb
|
47
48
|
- lib/generators/templates/dockerignore.erb
|
48
49
|
- lib/generators/templates/node-version.erb
|
49
50
|
homepage: https://github.com/rubys/dockerfile-rails
|