dockerfile-rails 1.0.13 → 1.0.14

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: d149f089ba3e54f14caebecec9aa80cf3b1195df61a6e5ae0c36e073da9bb890
4
- data.tar.gz: 2d6860ca397e75f156395c76e152d6a4c3aa882304d06e826fa9181213e8cdff
3
+ metadata.gz: 850bc5224e5a60f46df7ddf4c7c31374d891d27fc2145a15cb1eb021f798f63f
4
+ data.tar.gz: a4254547f34fbd026215ec07c1f4c81a1eef9a15780cbc5b664cb05df5e70ef3
5
5
  SHA512:
6
- metadata.gz: 175078b2e0f01d1bc52b83a431c7fa48d96f0fd4993ffe7e3cb9db392e07f8274d8e4604a3e533fa651f1886bc0f4945696168dc1aaf50267012270f3220050b
7
- data.tar.gz: 4bb3513b316a9333b20ac1509d1208ad1effeb84924f4cd294b2a47f42887d0bbb6285fcfc7b8603ae66bcd613d57e8465c775df4929cf3eca0942525fc3b97b
6
+ metadata.gz: 30e21fea124f3293d384c0fcaae6f1001985a81e5ed229b8b49d321733f61b98c8f46f5cd9586ad35c37198604e90ddbd107ad54e2a09a0d1b96067791c31c48
7
+ data.tar.gz: 52eed0118d7eb11ffe6833f4e6339d7736174d2035e94eee369d05586e6c0fe44051907481ec065e1e4d88212abc692277838c3ea34865dbbb2e3053e68de505
data/README.md CHANGED
@@ -22,8 +22,13 @@ Runtime Optimizations:
22
22
 
23
23
  * `--fullstaq` - use [fullstaq](https://fullstaqruby.org/) [images](https://github.com/evilmartians/fullstaq-ruby-docker) on [quay.io](https://quay.io/repository/evl.ms/fullstaq-ruby?tab=tags&tag=latest)
24
24
  * `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator
25
- * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
26
25
  * `--swap=n` - allocate swap space. See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes
26
+ * `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler
27
+
28
+ Build optimizations:
29
+
30
+ * `--cache` - use build caching to speed up builds
31
+ * `--parallel` - use multi-stage builds to install gems and node modules in parallel
27
32
 
28
33
  Features:
29
34
 
@@ -31,11 +36,6 @@ Features:
31
36
  * `--compose` - generate a `docker-compose.yml` file
32
37
  * `--nginx` - serve static files via [nginx](https://www.nginx.com/)
33
38
 
34
- Build:
35
-
36
- * `--cache` - use build caching to speed up builds
37
- * `--parallel` - use multi-stage builds to install gems and node modules in parallel
38
-
39
39
  Dependencies:
40
40
 
41
41
  Generally the dockerfile generator will be able to determine what dependencies you
@@ -50,9 +50,10 @@ additional support may be needed:
50
50
  Configuration:
51
51
 
52
52
  * `--bin-cd` - adjust binstubs to set current working directory
53
+ * `--label=name:value` - specify docker label. Can be used multiple times. See [LABEL](https://docs.docker.com/engine/reference/builder/#label) for detail
53
54
  * `--no-prepare` - omit `db:prepare`. Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases
54
55
  * `--platform=s` - specify target platform. See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details
55
- * `--label=name:value` - specify docker label. Can be used multiple times. See [LABEL](https://docs.docker.com/engine/reference/builder/#label) for detail
56
+ * `--precompile=defer` - may be needed when your configuration requires access to secrets that are not available at build time. Results in larger images and slower deployments.
56
57
 
57
58
  Options are saved between runs into `config/dockerfile.yml`. To invert a boolean options, add or remove a `no-` prefix from the option name.
58
59
 
@@ -15,6 +15,7 @@ class DockerfileGenerator < Rails::Generators::Base
15
15
  'parallel' => false,
16
16
  'platform' => nil,
17
17
  'postgresql' => false,
18
+ 'precompile' => nil,
18
19
  'prepare' => true,
19
20
  'redis' => false,
20
21
  'swap' => nil,
@@ -41,6 +42,9 @@ class DockerfileGenerator < Rails::Generators::Base
41
42
  class_option :ci, type: :boolean, default: OPTION_DEFAULTS.ci,
42
43
  desc: 'include test gems in bundle'
43
44
 
45
+ class_option :precompile, type: :string, default: OPTION_DEFAULTS.precompile,
46
+ desc: 'if set to "defer", assets:precompile will be done at deploy time'
47
+
44
48
  class_option 'bin-cd', type: :boolean, default: OPTION_DEFAULTS['bin-cd'],
45
49
  desc: 'modify binstubs to set working directory'
46
50
 
@@ -118,6 +122,17 @@ class DockerfileGenerator < Rails::Generators::Base
118
122
  template 'docker-compose.yml.erb', 'docker-compose.yml' if options.compose
119
123
 
120
124
  template 'dockerfile.yml.erb', 'config/dockerfile.yml', force: true
125
+
126
+ if @gemfile.include?('vite_ruby')
127
+ package = JSON.load_file('package.json')
128
+ unless package.dig('scripts', 'build')
129
+ package['scripts'] ||= {}
130
+ package['scripts']['build'] = 'vite build --outDir public'
131
+
132
+ say_status :update, 'package.json'
133
+ IO.write('package.json', JSON.pretty_generate(package))
134
+ end
135
+ end
121
136
  end
122
137
 
123
138
  private
@@ -495,4 +510,15 @@ private
495
510
  }
496
511
  end
497
512
  end
513
+
514
+ def more_docker_ignores
515
+ more = ''
516
+
517
+ if @gemfile.include?('vite_ruby')
518
+ lines = IO.read('.gitignore')[/^# Vite.*?\n\n/m].to_s.chomp.lines -
519
+ ["node_modules\n"]
520
+
521
+ more += "\n" + lines.join
522
+ end
523
+ end
498
524
  end
@@ -8,9 +8,9 @@ ARG RUBY_VERSION=<%= RUBY_VERSION %>
8
8
 
9
9
  <% end -%>
10
10
  <% if options.fullstaq -%>
11
- FROM <%= platform %>quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= @options.jemalloc ? 'jemalloc-' : '' %>slim as base
11
+ FROM <%= platform %>quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-<%= @options.jemalloc ? 'jemalloc-' : '' %>slim<% unless options.precompile == "defer" %> as base<% end %>
12
12
  <% else -%>
13
- FROM <%= platform %>ruby:$RUBY_VERSION-slim as base
13
+ FROM <%= platform %>ruby:$RUBY_VERSION-slim<% unless options.precompile == "defer" %> as base<% end %>
14
14
  <% end -%>
15
15
 
16
16
  <% unless options.label.empty? -%>
@@ -44,10 +44,12 @@ RUN gem update --system --no-document && \
44
44
  <%= render partial: 'install_node', locals: {yarn_version: nil} %>
45
45
 
46
46
  <% end -%>
47
+ <% unless options.precompile == "defer" -%>
47
48
 
48
49
  # Throw-away build stage<%= parallel? ? 's' : '' %> to reduce size of final image
49
50
  FROM base as <%= parallel? ? 'pre' : '' %>build
50
51
 
52
+ <% end -%>
51
53
  # Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
52
54
  <%= render partial: 'apt_install', locals: {packages: build_packages, clean: false, repos: ''} %>
53
55
 
@@ -112,6 +114,7 @@ RUN bundle exec bootsnap precompile app/ lib/
112
114
  <%= "RUN " + binfile_fixups.join(" && \\\n ") %>
113
115
 
114
116
  <% end -%>
117
+ <% unless options.precompile == "defer" -%>
115
118
  <% if Dir.exist?('app/assets') and !api_only? -%>
116
119
  # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
117
120
  RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_with?('7.0') ? '=DUMMY' : '_DUMMY=1' %> ./bin/rails assets:precompile
@@ -120,8 +123,9 @@ RUN SECRET_KEY_BASE<%= Rails::VERSION::MAJOR<7 || Rails::VERSION::STRING.start_w
120
123
 
121
124
  # Final stage for app image
122
125
  FROM base
123
- <% unless deploy_packages.empty? -%>
124
126
 
127
+ <% end -%>
128
+ <% unless deploy_packages.empty? -%>
125
129
  # Install packages needed for deployment
126
130
  <%= render partial: 'apt_install', locals: {packages: deploy_packages, clean: true, repos: deploy_repos} %>
127
131
  <% end -%>
@@ -133,6 +137,7 @@ FROM base
133
137
  RUN gem install foreman
134
138
 
135
139
  <% end -%>
140
+ <% unless options.precompile == "defer" -%>
136
141
  # Copy built application from previous stage
137
142
  COPY --from=build /rails /rails
138
143
  <% if api_client_dir -%>
@@ -141,6 +146,7 @@ COPY --from=build /rails /rails
141
146
  COPY --from=client /rails/<%= api_client_dir %>/build /rails/public
142
147
  <% end -%>
143
148
 
149
+ <% end -%>
144
150
  <% unless deploy_env.empty? -%>
145
151
  # Deployment options
146
152
  ENV <%= deploy_env.join(" \\\n ") %>
@@ -17,6 +17,9 @@ if [ "${*}" == "foreman start --procfile=Procfile.prod" ]; then
17
17
  <% else -%>
18
18
  # If running the rails server then create or migrate existing database
19
19
  if [ "${*}" == "./bin/rails server" ]; then
20
+ <% end -%>
21
+ <% if options.precompile == "defer" -%>
22
+ ./bin/rails assets:precompile
20
23
  <% end -%>
21
24
  ./bin/rails <%= dbprep_command %>
22
25
  fi
@@ -45,3 +45,4 @@
45
45
  <% end -%>
46
46
  /public/assets
47
47
  <% end -%>
48
+ <%= more_docker_ignores -%>
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.13
4
+ version: 1.0.14
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-10 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails