dockerfile-rails 0.4.5 → 0.4.6
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 +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 +22 -2
- data/lib/generators/templates/_apt_install.erb +10 -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: a58947d6c45936ce561ae3ddfdd3799773d17c5145fb15ae8013c9b293b53ce1
|
4
|
+
data.tar.gz: 0a9aff0df9a5e4688d47fa40fe151f6aabe4cdc8f5010c0e5e5514bd0d013fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44675c3dbac8f26938a990209e821a2974bd330c4ee1ab7a1cf59316ae2a622ed0cfb03ccf0bf6dfe5f776d200dff31ce789c0840c407fcd6fa64c96e88c4d89
|
7
|
+
data.tar.gz: 9f37b005a98f99c06d724c25afd61a50cb0d1e3c63391fd252b8a7179493b78624b1dd2ae70df45fedd5b92405f99a44bfc6b980369f194e8caa15d66d79bdaf
|
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,32 @@ 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
|
+
if package['packageManager'].to_s.start_with? "yarn@"
|
239
|
+
version = package['packageManager'].sub('yarn@', '')
|
240
|
+
else
|
241
|
+
version = `yarn --version`[/\d+\.\d+\.\d+/]
|
242
|
+
system "yarn set version #{version}"
|
243
|
+
|
244
|
+
# apparently not all versions of yarn will update package.json
|
245
|
+
package = JSON.parse(IO.read('package.json'))
|
246
|
+
unless package['packageManager']
|
247
|
+
package['packageManager'] = "yarn@#{version}"
|
248
|
+
IO.write('package.json', JSON.pretty_generate(package))
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
version
|
233
253
|
rescue
|
234
254
|
"latest"
|
235
255
|
end
|
@@ -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
|
+
|
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.6
|
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-21 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:
|