dockerfile-rails 1.0.17 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DEMO.md +61 -27
- data/MOTIVATION.md +58 -0
- data/README.md +26 -9
- data/Rakefile +5 -3
- data/lib/dockerfile-rails/scanner.rb +29 -28
- data/lib/dockerfile-rails.rb +5 -3
- data/lib/generators/dockerfile_generator.rb +327 -153
- data/lib/generators/templates/Dockerfile.erb +36 -5
- data/lib/generators/templates/docker-compose.yml.erb +9 -0
- data/lib/generators/templates/docker-entrypoint.erb +1 -1
- metadata +3 -2
@@ -22,10 +22,13 @@ LABEL <%= key =~ /^\w[.\w]*$/ ? key : key.inspect %>=<%= value.inspect %>
|
|
22
22
|
# Rails app lives here
|
23
23
|
WORKDIR /rails
|
24
24
|
|
25
|
+
<% unless base_args.empty? -%>
|
26
|
+
# Base build arguments
|
27
|
+
ARG <%= base_args.map {|key, value| "#{key}=#{value.inspect}"}.join(" \\\n ") %>
|
28
|
+
|
29
|
+
<% end -%>
|
25
30
|
# Set production environment
|
26
|
-
ENV
|
27
|
-
BUNDLE_PATH="vendor/bundle" \
|
28
|
-
BUNDLE_WITHOUT="<%= options.ci? ? 'development' : 'development:test' %>"
|
31
|
+
ENV <%= base_env.join(" \\\n ") %>
|
29
32
|
|
30
33
|
# Update gems and preinstall the desired version of bundler
|
31
34
|
ARG BUNDLER_VERSION=<%= Bundler::VERSION %>
|
@@ -68,6 +71,16 @@ FROM prebuild as node
|
|
68
71
|
|
69
72
|
FROM prebuild as build
|
70
73
|
|
74
|
+
<% end -%>
|
75
|
+
<% unless build_args.empty? -%>
|
76
|
+
# Build arguments
|
77
|
+
ARG <%= build_args.map {|key, value| "#{key}=#{value.inspect}"}.join(" \\\n ") %>
|
78
|
+
|
79
|
+
<% end -%>
|
80
|
+
<% unless build_env.empty? -%>
|
81
|
+
# Deployment options
|
82
|
+
ENV <%= build_env.join(" \\\n ") %>
|
83
|
+
|
71
84
|
<% end -%>
|
72
85
|
# Install application gems
|
73
86
|
COPY Gemfile Gemfile.lock ./
|
@@ -124,6 +137,11 @@ RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_w
|
|
124
137
|
# Final stage for app image
|
125
138
|
FROM base
|
126
139
|
|
140
|
+
<% end -%>
|
141
|
+
<% unless deploy_args.empty? -%>
|
142
|
+
# Deployment build arguments
|
143
|
+
ARG <%= deploy_args.map {|key, value| "#{key}=#{value.inspect}"}.join(" \\\n ") %>
|
144
|
+
|
127
145
|
<% end -%>
|
128
146
|
<% unless deploy_packages.empty? -%>
|
129
147
|
# Install packages needed for deployment
|
@@ -136,14 +154,27 @@ FROM base
|
|
136
154
|
<% elsif procfile.size > 1 -%>
|
137
155
|
RUN gem install foreman
|
138
156
|
|
157
|
+
<% end -%>
|
158
|
+
<% unless run_as_root? -%>
|
159
|
+
# # Run and own the application files as a non-root user for security
|
160
|
+
<% if options.compose? -%>
|
161
|
+
ARG UID=1000 \
|
162
|
+
GID=1000
|
163
|
+
RUN groupadd -f -g $GID rails && \
|
164
|
+
useradd -u $UID -g $GID rails
|
165
|
+
<% else -%>
|
166
|
+
RUN useradd rails
|
167
|
+
<% end -%>
|
168
|
+
USER rails
|
169
|
+
|
139
170
|
<% end -%>
|
140
171
|
<% unless options.precompile == "defer" -%>
|
141
172
|
# Copy built application from previous stage
|
142
|
-
COPY --from=build
|
173
|
+
COPY --from=build <% unless run_as_root? %>--chown=rails:rails <% end %>/rails /rails
|
143
174
|
<% if api_client_dir -%>
|
144
175
|
|
145
176
|
# Copy built client
|
146
|
-
COPY --from=client
|
177
|
+
COPY --from=client <% unless run_as_root? %>--chown=rails:rails <% end %>/rails/<%= api_client_dir %>/build /rails/public
|
147
178
|
<% end -%>
|
148
179
|
|
149
180
|
<% end -%>
|
@@ -1,7 +1,16 @@
|
|
1
1
|
version: "3.8"
|
2
2
|
services:
|
3
3
|
web:
|
4
|
+
<% if all_args.empty? -%>
|
4
5
|
build: .
|
6
|
+
<% else -%>
|
7
|
+
build:
|
8
|
+
context: .
|
9
|
+
args:
|
10
|
+
<% all_args.each do |name, value| -%>
|
11
|
+
<%= name %>: <%= value.html_safe? ? value : "\"#{Shellwords.escape(value)}\"" %>
|
12
|
+
<% end -%>
|
13
|
+
<% end -%>
|
5
14
|
ports:
|
6
15
|
- "3000:3000"
|
7
16
|
environment:
|
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.1.0
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -32,6 +32,7 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- DEMO.md
|
34
34
|
- MIT-LICENSE
|
35
|
+
- MOTIVATION.md
|
35
36
|
- README.md
|
36
37
|
- Rakefile
|
37
38
|
- lib/dockerfile-rails.rb
|