dockerfile-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 536685e13e342227e5d6af85e3d778539668bbdab81b5430902ae08286a57c62
4
- data.tar.gz: a3155769a131089493ae0682e195f6108dd4c81d03c79c6774ce21af0eda04be
3
+ metadata.gz: b317d73db1dda4043a0cf7ad8bc237cc909cf6fe08550960e57190651fe15f5a
4
+ data.tar.gz: 15454b9d5fee80e253dff57fe4f708f9e2c0bc729a1c1b506e2e96a7f1c13666
5
5
  SHA512:
6
- metadata.gz: 0547a5c9224213fdab9b99a2ca03e5aa411f086abb723b121561226079968e6da769f9acdf76ee123b1fbd57a64aa7d622c5dc44a48ab05717d9a523322955a1
7
- data.tar.gz: 37923bd9eaa647b9ca44433ce374d30e0250799e7078669b180f2ac5734241dc7af757a58b12227de999d78e3d4171ae7e3e9ebbbf828e90f2d71184999fb8c7
6
+ metadata.gz: ff075f1ab57a0a7bf5a6f084bc8c552f5a9a4b2e16a9452fec6d07b5f245dd7e8cc56e74d447af3083906926747fb868e0a76a99da8f0cba20c61273fd7f7010
7
+ data.tar.gz: c6306db9e351812343158cad19c59da387889f1fb449006e73806329d8b375d3ff8534e9f4c358c9b34368f1ea9e98d3e0b23d5833067477ccf6a68fe744bf9b
data/README.md CHANGED
@@ -5,7 +5,7 @@ Provide Rails generators to produce Dockerfiles and related files.
5
5
  ## Usage
6
6
 
7
7
  ```
8
- bundle add dockerfile-rails
8
+ bundle add dockerfile-rails --group development
9
9
  bin/rails generate dockerfile
10
10
  ```
11
11
 
@@ -26,4 +26,10 @@ additional support may be needed:
26
26
  * `--mysql` - add mysql libraries
27
27
  * `--posgresql` - add posgresql libraries
28
28
  * `--redis` - add redis libraries
29
- * `--sqlite3` - add sqlite3 libraries
29
+ * `--sqlite3` - add sqlite3 libraries
30
+
31
+ Links:
32
+
33
+ * [Demos](./DEMO.md)
34
+ * [Preparations for Rails 7.1](https://community.fly.io/t/preparations-for-rails-7-1/9512)
35
+ * [Rails Dockerfile futures](https://discuss.rubyonrails.org/t/rails-dockerfile-futures/82091/1)
@@ -163,13 +163,13 @@ private
163
163
  end
164
164
 
165
165
  def node_version
166
- using_node? and `node --version`[/\d+\.\d+\.\d+/]
166
+ `node --version`[/\d+\.\d+\.\d+/]
167
167
  rescue
168
168
  "lts"
169
169
  end
170
170
 
171
171
  def yarn_version
172
- using_node? and `yarn --version`[/\d+\.\d+\.\d+/]
172
+ `yarn --version`[/\d+\.\d+\.\d+/]
173
173
  rescue
174
174
  "latest"
175
175
  end
@@ -182,6 +182,23 @@ private
182
182
  Rails.application.config.api_only
183
183
  end
184
184
 
185
+ def api_client_dir
186
+ return unless api_only?
187
+
188
+ file = Dir['*/package.json'].find do |file|
189
+ JSON.load_file(file).dig('scripts', 'build')
190
+ end
191
+
192
+ file && File.dirname(file)
193
+ end
194
+
195
+ def api_client_files
196
+ client = api_client_dir
197
+ return unless client
198
+
199
+ Dir["#{client}/{package.json,package-lock.json,yarn.lock}"]
200
+ end
201
+
185
202
  def dbprep_command
186
203
  if Rails::VERSION::MAJOR >= 6
187
204
  'db:prepare'
@@ -1,7 +1,40 @@
1
1
  # syntax = docker/dockerfile:1
2
2
 
3
- # Make sure it matches the Ruby version in .ruby-version and Gemfile
3
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4
4
  ARG RUBY_VERSION=<%= Gem.ruby_version %>
5
+ <% if api_client_dir -%>
6
+ ARG NODE_VERSION=<%= node_version %>
7
+
8
+ FROM node:$NODE_VERSION-slim as client
9
+
10
+ WORKDIR /rails/<%= api_client_dir %>
11
+
12
+ ENV NODE_ENV=production
13
+
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
+ <% end -%>
23
+ <% 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 -%>
5
38
  FROM ruby:$RUBY_VERSION-slim as base
6
39
 
7
40
  # Rails app lives here
@@ -122,11 +155,16 @@ RUN apt-get update -qq && \
122
155
  <% end -%>
123
156
  <% end -%>
124
157
 
125
- # Copy built application from second stage
158
+ # Copy built application from previous stage
126
159
  <% if options.ci? -%>
127
160
  COPY --from=build /usr/local/bundle /usr/local/bundle
128
161
  <% end -%>
129
162
  COPY --from=build /rails /rails
163
+ <% if api_client_dir -%>
164
+
165
+ # Copy built client
166
+ COPY --from=client /rails/<%= api_client_dir %>/build /rails/public
167
+ <% end -%>
130
168
 
131
169
  # Deployment options
132
170
  ENV RAILS_LOG_TO_STDOUT="1" \
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.1.0
4
+ version: 0.2.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-01-14 00:00:00.000000000 Z
11
+ date: 2023-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails