dockerfile-rails 0.4.5 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DEMO.md +8 -8
- data/README.md +28 -7
- data/Rakefile +14 -0
- data/lib/dockerfile-rails/scanner.rb +6 -1
- data/lib/generators/dockerfile_generator.rb +26 -2
- data/lib/generators/templates/Dockerfile.erb +1 -1
- data/lib/generators/templates/_apt_install.erb +10 -0
- data/lib/generators/templates/_install_node.erb +9 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7578107905d7265d79a480e52c9a960e58d5b5cde92e6a3c6de22e3a7c2b269
|
4
|
+
data.tar.gz: 8a1a483463c405746298d425a259838d18a1128231aac5e0c68733be607f1e7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d459f7291d6588b1f1b6353f27bde783f018f1f7dd16d80dc4f643cb8ec5a3934c5cc1d96eaabd857a7c0cb43a947917cdaf44b4e064e24397bfc2a8876f1cc
|
7
|
+
data.tar.gz: 0f4b1859a1b07a8f7b6e7e3679a7a3566a1957148f708d66be5be0ec2e2ead03706a4f7d30ac964a216e7912d0896bcf2e83612534a9c841780454c73c726b78
|
data/DEMO.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
If you have Rails and Docker installed on your machine, running each of these demos is a matter of opening a terminal window, navigating to an empty directory, and copy/pasting a block of instructions into that window. Once started, navigate to http://localhost:3000/ to see the results.
|
1
|
+
If you have Rails and Docker installed on your machine, running each of these demos is a matter of opening a terminal window, navigating to an empty directory, and copy/pasting a block of instructions into that window. Once started, navigate to http://localhost:3000/ to see the results.
|
2
2
|
|
3
3
|
# Demo 1 - Minimal
|
4
4
|
|
5
5
|
Rails provides a _smoke test_ for new applications that makes sure that you have your software configured correctly enough to serve a page. The following deploys that smoke test in production. Once done take a look at the `Dockerfile` file produced.
|
6
6
|
|
7
|
-
```
|
7
|
+
```bash
|
8
8
|
rails new welcome --minimal
|
9
9
|
cd welcome
|
10
10
|
echo 'Rails.application.routes.draw { root "rails/welcome#index" }' > config/routes.rb
|
11
11
|
bundle add dockerfile-rails --group development
|
12
12
|
bin/rails generate dockerfile
|
13
|
-
docker buildx build . -t rails-welcome
|
13
|
+
docker buildx build . -t rails-welcome # add --load to save the image to local Docker
|
14
14
|
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-welcome
|
15
15
|
```
|
16
16
|
|
17
17
|
# Demo 2 - Action Cable and Active Record
|
18
18
|
|
19
|
-
Real applications involve a network of services. The following demo makes use of PostgreSQL and Redis to display a welcome screen with a live, updating, visitors counter. Once done, take a look at the
|
19
|
+
Real applications involve a network of services. The following demo makes use of PostgreSQL and Redis to display a welcome screen with a live, updating, visitors counter. Once done, take a look at the `docker-compose.yml` file produced.
|
20
20
|
|
21
|
-
```
|
21
|
+
```bash
|
22
22
|
rails new welcome --database postgresql
|
23
23
|
cd welcome
|
24
24
|
|
@@ -98,7 +98,7 @@ docker compose up
|
|
98
98
|
This demo deploys a [Create React App](https://create-react-app.dev/) client and a Rails API-only server. Ruby and Rails version information is retrieved from the server and displayed below a spinning React logo. Note that the build process installs the
|
99
99
|
node moddules and ruby gems in parallel.
|
100
100
|
|
101
|
-
```
|
101
|
+
```bash
|
102
102
|
rails new welcome --api
|
103
103
|
cd welcome
|
104
104
|
npx create-react-app client
|
@@ -160,14 +160,14 @@ While optional, bundling Javascript is a popular choice, and starting with
|
|
160
160
|
Rails 7 there are three options: esbuild, rollup, and webpack. The
|
161
161
|
the following demonstrates Rails 7 with esbuild:
|
162
162
|
|
163
|
-
```
|
163
|
+
```bash
|
164
164
|
rails new welcome --javascript esbuild
|
165
165
|
cd welcome
|
166
166
|
|
167
167
|
yarn add react react-dom
|
168
168
|
bin/rails generate controller Time index
|
169
169
|
|
170
|
-
cat <<-"EOF" >> app/javascript/application.js
|
170
|
+
cat <<-"EOF" >> app/javascript/application.js
|
171
171
|
import "./components/counter"
|
172
172
|
EOF
|
173
173
|
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ are actually using. But should you be using DATABASE_URL, for example, at runti
|
|
29
29
|
additional support may be needed:
|
30
30
|
|
31
31
|
* `--mysql` - add mysql libraries
|
32
|
-
* `--
|
32
|
+
* `--postgresql` - add postgresql libraries
|
33
33
|
* `--redis` - add redis libraries
|
34
34
|
* `--sqlite3` - add sqlite3 libraries
|
35
35
|
|
@@ -40,10 +40,31 @@ Optimizations:
|
|
40
40
|
* `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
|
41
41
|
* `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes
|
42
42
|
|
43
|
-
|
43
|
+
## Testing
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
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.
|
46
|
+
|
47
|
+
Running all tests, or even a single individual test can be done as follows:
|
48
|
+
|
49
|
+
```
|
50
|
+
rake test
|
51
|
+
ruby test/test_minimal.rb
|
52
|
+
```
|
53
|
+
|
54
|
+
To assis with this process, outputs of tests can be captured automatically. This is useful when adding new tests and when making a change that affects many tests. Be sure to inspect the output (e.g., by using `git diff`) before committing.
|
55
|
+
|
56
|
+
```
|
57
|
+
rake test:capture
|
58
|
+
TEST_CAPTURE=1 ruby test/test_minimal.rb
|
59
|
+
```
|
60
|
+
|
61
|
+
## Links
|
62
|
+
|
63
|
+
Many of the following links relate to the current development status with respect to Rails 7.1 and will be removed once that is resolved.
|
64
|
+
|
65
|
+
* [Demos](./DEMO.md) - scripts to copy and paste into an empty directory to launch demo apps
|
66
|
+
* [Test Results](./test/results) - expected outputs for each test
|
67
|
+
* [Preparations for Rails 7.1](https://community.fly.io/t/preparations-for-rails-7-1/9512) - [Fly.io](https://fly.io/)'s plans and initial discussions with DHH
|
68
|
+
* [Rails Dockerfile futures](https://discuss.rubyonrails.org/t/rails-dockerfile-futures/82091/1) - rationale for a generator
|
69
|
+
* [Fly Cookbooks](https://fly.io/docs/rails/cookbooks/) - deeper dive into Dockerfile design choices
|
70
|
+
* [app/templates/Dockerfile.tt](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt) - current Rails 7.1 template
|
data/Rakefile
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
3
|
# Run `rake release` to release a new version of the gem.
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = FileList['test/test*.rb']
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :test do
|
13
|
+
task :capture do
|
14
|
+
ENV['TEST_CAPTURE'] = 'true'
|
15
|
+
Rake::Task[:test].invoke
|
16
|
+
end
|
17
|
+
end
|
@@ -13,6 +13,8 @@ module DockerfileRails
|
|
13
13
|
@postgresql = true
|
14
14
|
elsif database == 'mysql' or database == 'mysql2'
|
15
15
|
@mysql = true
|
16
|
+
elsif database == 'sqlserver'
|
17
|
+
@sqlserver = true
|
16
18
|
end
|
17
19
|
|
18
20
|
### ruby gems ###
|
@@ -29,7 +31,10 @@ module DockerfileRails
|
|
29
31
|
begin
|
30
32
|
gemfile_definition = Bundler::Definition.build('Gemfile', nil, [])
|
31
33
|
@gemfile += gemfile_definition.dependencies.map(&:name)
|
32
|
-
|
34
|
+
|
35
|
+
unless ENV['RAILS_ENV'] == 'test'
|
36
|
+
@git = !gemfile_definition.spec_git_paths.empty?
|
37
|
+
end
|
33
38
|
rescue => error
|
34
39
|
STDERR.puts error.message
|
35
40
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'erb'
|
2
|
+
require_relative '../dockerfile-rails/scanner.rb'
|
2
3
|
|
3
4
|
class DockerfileGenerator < Rails::Generators::Base
|
4
5
|
include DockerfileRails::Scanner
|
@@ -223,13 +224,36 @@ private
|
|
223
224
|
end
|
224
225
|
|
225
226
|
def node_version
|
226
|
-
|
227
|
+
if File.exist? '.node_version'
|
228
|
+
IO.read('.node_version')[/\d+\.\d+\.\d+/]
|
229
|
+
else
|
230
|
+
`node --version`[/\d+\.\d+\.\d+/]
|
231
|
+
end
|
227
232
|
rescue
|
228
233
|
"lts"
|
229
234
|
end
|
230
235
|
|
231
236
|
def yarn_version
|
232
|
-
|
237
|
+
package = JSON.parse(IO.read('package.json'))
|
238
|
+
|
239
|
+
if ENV['RAILS_ENV'] == 'test'
|
240
|
+
# yarn install instructions changed in v2
|
241
|
+
version = '1.22.19'
|
242
|
+
elsif package['packageManager'].to_s.start_with? "yarn@"
|
243
|
+
version = package['packageManager'].sub('yarn@', '')
|
244
|
+
else
|
245
|
+
version = `yarn --version`[/\d+\.\d+\.\d+/] || '1.22.19'
|
246
|
+
system "yarn set version #{version}"
|
247
|
+
package = JSON.parse(IO.read('package.json'))
|
248
|
+
# apparently not all versions of yarn will update package.json...
|
249
|
+
end
|
250
|
+
|
251
|
+
unless package['packageManager']
|
252
|
+
package['packageManager'] = "yarn@#{version}"
|
253
|
+
IO.write('package.json', JSON.pretty_generate(package))
|
254
|
+
end
|
255
|
+
|
256
|
+
version
|
233
257
|
rescue
|
234
258
|
"latest"
|
235
259
|
end
|
@@ -95,7 +95,7 @@ RUN bundle exec bootsnap precompile app/ lib/
|
|
95
95
|
<%= "RUN " + binfile_fixups.join(" && \\\n ") %>
|
96
96
|
|
97
97
|
<% end -%>
|
98
|
-
<% if Dir.exist?('assets') and !api_only? -%>
|
98
|
+
<% if Dir.exist?('app/assets') and !api_only? -%>
|
99
99
|
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
|
100
100
|
RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_with?('7.0') ? '=DUMMY' : '_DUMMY=1' %> ./bin/rails assets:precompile
|
101
101
|
|
@@ -8,3 +8,13 @@ RUN apt-get update -qq && \
|
|
8
8
|
apt-get install --no-install-recommends -y <%= packages.join(" ") %><% if clean %> && \
|
9
9
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives<% end %>
|
10
10
|
<% end -%>
|
11
|
+
<% if @sqlserver -%>
|
12
|
+
# install freetds required by tiny_tds gem
|
13
|
+
RUN wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.3.16.tar.gz && \
|
14
|
+
tar -xzf freetds-1.3.16.tar.gz && \
|
15
|
+
cd freetds-1.3.16 && \
|
16
|
+
./configure --prefix=/usr/local --with-tdsver=7.3 && \
|
17
|
+
make && \
|
18
|
+
make install
|
19
|
+
<% end -%>
|
20
|
+
|
@@ -17,5 +17,14 @@ RUN curl -fsSL https://fnm.vercel.app/install | bash && \
|
|
17
17
|
ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH
|
18
18
|
<% end -%>
|
19
19
|
<% if yarn_version -%>
|
20
|
+
<% if yarn_version < '2' -%>
|
20
21
|
RUN npm install -g yarn@$YARN_VERSION
|
22
|
+
<% else -%>
|
23
|
+
<% if (node_version.split('.').map(&:to_i) <=> [16,10,0]) < 0 -%>
|
24
|
+
RUN npm i -g corepack && \
|
25
|
+
<% else -%>
|
26
|
+
RUN corepack enable && \
|
27
|
+
<% end -%>
|
28
|
+
corepack prepare yarn@$YARN_VERSION --activate
|
29
|
+
<% end -%>
|
21
30
|
<% 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: 0.4.
|
4
|
+
version: 0.4.7
|
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-
|
11
|
+
date: 2023-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -46,11 +46,11 @@ files:
|
|
46
46
|
- lib/generators/templates/docker-entrypoint.erb
|
47
47
|
- lib/generators/templates/dockerignore.erb
|
48
48
|
- lib/generators/templates/node-version.erb
|
49
|
-
homepage: https://github.com/rubys/
|
49
|
+
homepage: https://github.com/rubys/dockerfile-rails
|
50
50
|
licenses:
|
51
51
|
- MIT
|
52
52
|
metadata:
|
53
|
-
homepage_uri: https://github.com/rubys/
|
53
|
+
homepage_uri: https://github.com/rubys/dockerfile-rails
|
54
54
|
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|