dockerfile-rails 1.0.17 → 1.0.18
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: 9cc1cc395215fe473533ab4418d6e9949a5f58d2a366c2e8d49d29ee2f8e65d8
|
4
|
+
data.tar.gz: 9e5a602abb603a024c08ce9e7cd0a4ebb393cfcb92b15fcbc2efd2302ea5d2d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30fceacbbc93b16c8f9f3e6e850dfe372d76675407239f4fec6e26fedc4d956a614a2b6d3c88cacd5cf0085ce06c20709b7c2885954796fe0b7f3e1f63c97cf9
|
7
|
+
data.tar.gz: dbd788b1bbf86b86950d95cfa4f6222e43a1359e3453bbe26c275b0ac451d5a00e1b8a038498d3cc8a554b567c35f27a1c5c143ff5deaed6d197fa7309f0f1ce
|
data/README.md
CHANGED
@@ -54,6 +54,7 @@ Configuration:
|
|
54
54
|
* `--no-prepare` - omit `db:prepare`. Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases
|
55
55
|
* `--platform=s` - specify target platform. See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details
|
56
56
|
* `--precompile=defer` - may be needed when your configuration requires access to secrets that are not available at build time. Results in larger images and slower deployments.
|
57
|
+
* `--root` - run application as root
|
57
58
|
|
58
59
|
Options are saved between runs into `config/dockerfile.yml`. To invert a boolean options, add or remove a `no-` prefix from the option name.
|
59
60
|
|
@@ -11,20 +11,22 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
11
11
|
'compose' => false,
|
12
12
|
'fullstaq' => false,
|
13
13
|
'jemalloc' => false,
|
14
|
+
'label' => {},
|
14
15
|
'mysql' => false,
|
16
|
+
'nginx' => false,
|
15
17
|
'parallel' => false,
|
16
18
|
'platform' => nil,
|
17
19
|
'postgresql' => false,
|
18
20
|
'precompile' => nil,
|
19
21
|
'prepare' => true,
|
20
22
|
'redis' => false,
|
23
|
+
'root' => false,
|
21
24
|
'swap' => nil,
|
22
25
|
'yjit' => false,
|
23
|
-
'label' => {},
|
24
|
-
'nginx' => false,
|
25
26
|
)
|
26
27
|
|
27
28
|
@@labels = {}
|
29
|
+
@@packages = {"base" => [], "build" => [], "deploy" => []}
|
28
30
|
|
29
31
|
# load defaults from config file
|
30
32
|
if File.exist? 'config/dockerfile.yml'
|
@@ -35,6 +37,12 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
35
37
|
OPTION_DEFAULTS[option] = options[option] if options.include? option
|
36
38
|
end
|
37
39
|
|
40
|
+
if options[:packages]
|
41
|
+
options[:packages].each do |stage, list|
|
42
|
+
@@packages[stage.to_s] = list
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
@@labels = options[:label].stringify_keys if options.include? :label
|
39
47
|
end
|
40
48
|
end
|
@@ -93,6 +101,27 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
93
101
|
class_option :nginx, type: :boolean, default: OPTION_DEFAULTS.nginx,
|
94
102
|
desc: 'Serve static files with nginx'
|
95
103
|
|
104
|
+
class_option :root, type: :boolean, default: OPTION_DEFAULTS.root,
|
105
|
+
desc: 'Run application as root user'
|
106
|
+
|
107
|
+
class_option 'add-base', type: :array, default: [],
|
108
|
+
desc: 'additional packages to install for both build and deploy'
|
109
|
+
|
110
|
+
class_option 'add-build', type: :array, default: [],
|
111
|
+
desc: 'additional packages to install for use during build'
|
112
|
+
|
113
|
+
class_option 'add-deploy', aliases: '--add', type: :array, default: [],
|
114
|
+
desc: 'additional packages to install for deployment'
|
115
|
+
|
116
|
+
class_option 'remove-base', type: :array, default: [],
|
117
|
+
desc: 'remove from list of base packages'
|
118
|
+
|
119
|
+
class_option 'remove-build', type: :array, default: [],
|
120
|
+
desc: 'remove from list of build packages'
|
121
|
+
|
122
|
+
class_option 'remove-deploy', aliases: '--remove', type: :array, default: [],
|
123
|
+
desc: 'remove from list of deploy packages'
|
124
|
+
|
96
125
|
def generate_app
|
97
126
|
source_paths.push File.expand_path('./templates', __dir__)
|
98
127
|
|
@@ -105,6 +134,16 @@ class DockerfileGenerator < Rails::Generators::Base
|
|
105
134
|
@dockerfile_config[option] = value if @dockerfile_config.include? option
|
106
135
|
end
|
107
136
|
|
137
|
+
# apply requested package changes
|
138
|
+
%w(base build deploy).each do |phase|
|
139
|
+
@@packages[phase] += options["add-#{phase}"]
|
140
|
+
@@packages[phase] -= options["remove-#{phase}"]
|
141
|
+
@@packages[phase].uniq!
|
142
|
+
@@packages.delete phase if @@packages[phase].empty?
|
143
|
+
end
|
144
|
+
|
145
|
+
@dockerfile_config['packages'] = @@packages
|
146
|
+
|
108
147
|
scan_rails_app
|
109
148
|
|
110
149
|
Bundler.with_original_env { install_gems }
|
@@ -169,6 +208,10 @@ private
|
|
169
208
|
end
|
170
209
|
end
|
171
210
|
|
211
|
+
def run_as_root?
|
212
|
+
true # options.root? || options.nginx?
|
213
|
+
end
|
214
|
+
|
172
215
|
def using_node?
|
173
216
|
return @using_node if @using_node != nil
|
174
217
|
@using_node = File.exist? 'package.json'
|
@@ -215,6 +258,7 @@ private
|
|
215
258
|
|
216
259
|
def base_packages
|
217
260
|
packages = []
|
261
|
+
packages += @@packages['base'] if @@packages['base']
|
218
262
|
|
219
263
|
if using_execjs?
|
220
264
|
packages += %w(curl unzip)
|
@@ -248,6 +292,7 @@ private
|
|
248
292
|
def build_packages
|
249
293
|
# start with the essentials
|
250
294
|
packages = %w(build-essential)
|
295
|
+
packages += @@packages['build'] if @@packages['build']
|
251
296
|
|
252
297
|
# add databases: sqlite3, postgres, mysql
|
253
298
|
packages << 'pkg-config' if options.sqlite3? or @sqlite3
|
@@ -298,6 +343,7 @@ private
|
|
298
343
|
|
299
344
|
def deploy_packages
|
300
345
|
packages = []
|
346
|
+
packages += @@packages['deploy'] if @@packages['deploy']
|
301
347
|
|
302
348
|
# start with databases: sqlite3, postgres, mysql
|
303
349
|
packages << 'libsqlite3-0' if options.sqlite3? or @sqlite3
|
@@ -124,6 +124,11 @@ RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_w
|
|
124
124
|
# Final stage for app image
|
125
125
|
FROM base
|
126
126
|
|
127
|
+
<% end -%>
|
128
|
+
<% unless run_as_root? -%>
|
129
|
+
# add a non-root user
|
130
|
+
RUN useradd rails
|
131
|
+
|
127
132
|
<% end -%>
|
128
133
|
<% unless deploy_packages.empty? -%>
|
129
134
|
# Install packages needed for deployment
|
@@ -139,11 +144,11 @@ RUN gem install foreman
|
|
139
144
|
<% end -%>
|
140
145
|
<% unless options.precompile == "defer" -%>
|
141
146
|
# Copy built application from previous stage
|
142
|
-
COPY --from=build
|
147
|
+
COPY --from=build <% unless run_as_root? %>--chown=rails:rails <% end %>/rails /rails
|
143
148
|
<% if api_client_dir -%>
|
144
149
|
|
145
150
|
# Copy built client
|
146
|
-
COPY --from=client
|
151
|
+
COPY --from=client <% unless run_as_root? %>--chown=rails:rails <% end %>/rails/<%= api_client_dir %>/build /rails/public
|
147
152
|
<% end -%>
|
148
153
|
|
149
154
|
<% end -%>
|
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.
|
4
|
+
version: 1.0.18
|
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-
|
11
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|