dockerfile-rails 0.5.0 → 0.5.2

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: 906eaaf2f4166356a6cece9b347dd58a29324a0e7a3d0f557cfea85054c34816
4
- data.tar.gz: 0c071eb1fd4da339676916705498c18fb2d5e08e0115b8f47745def8229390e3
3
+ metadata.gz: 90f5f36199b97da2a9a8cb8d787970846a8b50c17d68cd8192e335684d80dfd2
4
+ data.tar.gz: dc1106eb805b3d1640cc2fb7bbf292e512209f33367a91ba563e781fbca6e1f8
5
5
  SHA512:
6
- metadata.gz: 66b27141d048276513a4384b6dd88fae87f929d2128a9e6a19187cac6a1d75f751d5e261ccd4f94424ae7ae53ca0713141db34163d04cb997a719731a6e39dde
7
- data.tar.gz: 7e927389954e205c3cc89e6de75506d85265ac394a749f0b394d9b5263b4de719a5dc935d8ff493f1c1cfdc30854b70f7f5b77f6c48599095a7132f0f050a0cd
6
+ metadata.gz: 7bf221c15c7041792a736296d90732949bd31c27b660a06fc0ee743cf295516b0db874be835e7263c57836df8b748cb73548264b92aeb6383327226e513a3d38
7
+ data.tar.gz: abb6c6468353f3ea793d145c503e807ba301f752d227fec8406040989e303d1ad60372758fac3bc7a053f56f01bbf378197302710e6587ad9aac334816c1db5c
data/DEMO.md CHANGED
@@ -10,10 +10,12 @@ 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 # add --load to save the image to local Docker
13
+ docker buildx build . -t rails-welcome
14
14
  docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) rails-welcome
15
15
  ```
16
16
 
17
+ Add `--load` to the `buildx` command if you want to save the image to local Docker.
18
+
17
19
  # Demo 2 - Action Cable and Active Record
18
20
 
19
21
  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.
@@ -101,7 +103,7 @@ node moddules and ruby gems in parallel.
101
103
  ```bash
102
104
  rails new welcome --api
103
105
  cd welcome
104
- npx create-react-app client
106
+ npx -y create-react-app client
105
107
 
106
108
  bin/rails generate controller Api versions
107
109
 
data/README.md CHANGED
@@ -4,12 +4,13 @@ Provides a Rails generator to produce Dockerfiles and related files. This is be
4
4
 
5
5
  * Supports all [Rails supported releases](https://guides.rubyonrails.org/maintenance_policy.html), not just Rails 7.1, and likely works with a number of previous releases.
6
6
  * Can be customized using flags on the `generate dockerfile` command, and rerun to produce a custom tailored dockerfile based on detecting the actual features used by your application.
7
+ * Will set `.node_version`, `packageManager` and install gems if needed to deploy your application.
7
8
  * Can produce a `docker-compose.yml` file for locally testing your configuration before deploying.
8
9
 
9
10
  ## Usage
10
11
 
11
12
  ```
12
- bundle add dockerfile-rails --group development
13
+ bundle add dockerfile-rails --version ">= 0.5.0" --group development
13
14
  bin/rails generate dockerfile
14
15
  ```
15
16
 
@@ -77,3 +78,4 @@ Many of the following links relate to the current development status with respec
77
78
  * [Rails Dockerfile futures](https://discuss.rubyonrails.org/t/rails-dockerfile-futures/82091/1) - rationale for a generator
78
79
  * [Fly Cookbooks](https://fly.io/docs/rails/cookbooks/) - deeper dive into Dockerfile design choices
79
80
  * [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
81
+ * Fly.io [Cut over to Rails Dockerfile Generator on Sunday 29 Jan 2023](https://community.fly.io/t/cut-over-to-rails-dockerfile-generator-on-sunday-29-jan-2023/10350)
@@ -4,7 +4,7 @@ module DockerfileRails
4
4
 
5
5
  ### database ###
6
6
 
7
- database = YAML.load_file('config/database.yml').
7
+ database = YAML.load_file('config/database.yml', aliases: true).
8
8
  dig('production', 'adapter') rescue nil
9
9
 
10
10
  if database == 'sqlite3'
@@ -14,6 +14,7 @@ class DockerfileGenerator < Rails::Generators::Base
14
14
  'mysql' => false,
15
15
  'parallel' => false,
16
16
  'platform' => nil,
17
+ 'postgresql' => false,
17
18
  'prepare' => true,
18
19
  'redis' => false,
19
20
  'swap' => nil,
@@ -86,6 +87,8 @@ class DockerfileGenerator < Rails::Generators::Base
86
87
 
87
88
  scan_rails_app
88
89
 
90
+ Bundler.with_original_env { install_gems }
91
+
89
92
  template 'Dockerfile.erb', 'Dockerfile'
90
93
  template 'dockerignore.erb', '.dockerignore'
91
94
 
@@ -96,7 +99,7 @@ class DockerfileGenerator < Rails::Generators::Base
96
99
 
97
100
  template 'docker-compose.yml.erb', 'docker-compose.yml' if options.compose
98
101
 
99
- template 'dockerfile.yml.erb', 'config/dockerfile.yml'
102
+ template 'dockerfile.yml.erb', 'config/dockerfile.yml', force: true
100
103
  end
101
104
 
102
105
  private
@@ -155,6 +158,20 @@ private
155
158
  @keeps = !Dir['**/.keep']
156
159
  end
157
160
 
161
+ def install_gems
162
+ if options.postgresql? or @postgresql
163
+ system "bundle add pg" unless @gemfile.include? 'pg'
164
+ end
165
+
166
+ if options.mysql? or @mysql
167
+ system "bundle add mysql2" unless @gemfile.include? 'mysql2'
168
+ end
169
+
170
+ if options.redis? or using_redis?
171
+ system "bundle add redis" unless @gemfile.include? 'redis'
172
+ end
173
+ end
174
+
158
175
  def build_packages
159
176
  # start with the essentials
160
177
  packages = %w(build-essential)
@@ -162,13 +179,13 @@ private
162
179
  # add databases: sqlite3, postgres, mysql
163
180
  packages << 'pkg-config' if options.sqlite3? or @sqlite3
164
181
  packages << 'libpq-dev' if options.postgresql? or @postgresql
165
- packages << 'default-libmysqlclient-dev' if options.mysql or @mysql
182
+ packages << 'default-libmysqlclient-dev' if options.mysql? or @mysql
166
183
 
167
184
  # add git if needed to install gems
168
185
  packages << 'git' if @git
169
186
 
170
187
  # add redis in case Action Cable, caching, or sidekiq are added later
171
- packages << "redis" if using_redis?
188
+ packages << "redis" if options.redis? or using_redis?
172
189
 
173
190
  # ActiveStorage preview support
174
191
  packages << "libvips" if @gemfile.include? 'ruby-vips'
@@ -224,6 +241,31 @@ private
224
241
  packages.sort
225
242
  end
226
243
 
244
+ def deploy_env
245
+ env = []
246
+
247
+ if Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_with?('7.0')
248
+ env << 'RAILS_LOG_TO_STDOUT="1"'
249
+ env << 'RAILS_SERVE_STATIC_FILES="true"'
250
+ end
251
+
252
+ if options.yjit
253
+ env << 'RUBY_YJIT_ENABLE="1"'
254
+ end
255
+
256
+ if options.jemalloc and not options.fullstaq
257
+ if (options.platform || Gem::Platform::local.cpu).include? 'arm'
258
+ env << 'LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libjemalloc.so.2"'
259
+ else
260
+ env << 'LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"'
261
+ end
262
+
263
+ env << 'MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true"'
264
+ end
265
+
266
+ env
267
+ end
268
+
227
269
  def binfile_fixups
228
270
  # binfiles may have OS specific paths to ruby. Normalize them.
229
271
  shebangs = Dir["bin/*"].map { |file| IO.read(file).lines.first }.join
@@ -126,17 +126,11 @@ COPY --from=build /rails /rails
126
126
  COPY --from=client /rails/<%= api_client_dir %>/build /rails/public
127
127
  <% end -%>
128
128
 
129
+ <% unless deploy_env.empty? -%>
129
130
  # Deployment options
130
- ENV RAILS_LOG_TO_STDOUT="1" \
131
- RAILS_SERVE_STATIC_FILES="true"<% if options.yjit %> \
132
- RUBY_YJIT_ENABLE="1"<% end %><% if options.jemalloc and not options.fullstaq %> \
133
- <% if (options.platform || Gem::Platform::local.cpu).include? 'arm' -%>
134
- LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libjemalloc.so.2" \
135
- <% else -%>
136
- LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" \
137
- <% end -%>
138
- MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true"<% end %>
131
+ ENV <%= deploy_env.join(" \\\n ") %>
139
132
 
133
+ <% end -%>
140
134
  <% if options.prepare -%>
141
135
  # Entrypoint prepares the database.
142
136
  <% else -%>
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.5.0
4
+ version: 0.5.2
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-24 00:00:00.000000000 Z
11
+ date: 2023-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails