dockerfile-rails 1.5.3 → 1.5.4

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: b14b8dc852c4d34ae6fa48251cb680e89a9c08fe81942d336d21f18418643e38
4
- data.tar.gz: 3d61361b94688abd9545d59a43cb22fda5fc4ecd947353a7397ee88e5cfa0b68
3
+ metadata.gz: fb14492c49c1cf3daf989207c2188413c0311a317a95727330fcec570f79632c
4
+ data.tar.gz: c18d7c536626010b3befe71e23ef8c99b53095680e7050dfbcfecd59960cba91
5
5
  SHA512:
6
- metadata.gz: becc43052f96c77dc89fa920039c43151737bfd284a8b533185e7334989506b28db8c6ab87da9748712c9c52de0cb7b344ef0308992d4306fc7b47a6be0eeac6
7
- data.tar.gz: 11210697f2034ea5295611f7b6548cad9e5712bdd8906e0acc083edde2e35404f51c22fb2624d8e4c087c02be7319c6f71a7f76d98f5054f85d6472012767fbc
6
+ metadata.gz: 50725e7ac313645b93fddb4742a2e711b08e01ba1c593bd0126a70135d04f7467b9d2caa476eb2642903392fc805e2a38ff811aede86c4a2c23843aa30be0189
7
+ data.tar.gz: 85c0608fc27c115b95d42ddeef4b86b2e5c6be63f652338d01d4b24886686036e2572bab94356f41b3f6e18123d07370b2982f4b224eba34997ef0707381f557
data/README.md CHANGED
@@ -85,6 +85,7 @@ Not all of your needs can be determined by scanning your application. For examp
85
85
  * `--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.
86
86
  * `--root` - run application as root
87
87
  * `--windows` - make Dockerfile work for Windows users that may have set `git config --global core.autocrlf true`
88
+ * `--private-gemserver-domain=gems.example.com` - set the domain name of your private gemserver. This is used to tell bundler for what domain to use the credentials of a private gemserver provided via a docker secret
88
89
 
89
90
  ### Advanced Customization:
90
91
 
@@ -119,7 +120,7 @@ rake test
119
120
  ruby test/test_minimal.rb
120
121
  ```
121
122
 
122
- 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.
123
+ To assist 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.
123
124
 
124
125
  ```
125
126
  rake test:capture
@@ -28,6 +28,7 @@ class DockerfileGenerator < Rails::Generators::Base
28
28
  "postgresql" => false,
29
29
  "precompile" => nil,
30
30
  "prepare" => true,
31
+ "private-gemserver-domain" => nil,
31
32
  "procfile" => "",
32
33
  "redis" => false,
33
34
  "registry" => "",
@@ -183,6 +184,9 @@ class DockerfileGenerator < Rails::Generators::Base
183
184
  class_option "procfile", type: :string, default: OPTION_DEFAULTS.procfile,
184
185
  desc: "custom procfile to start services"
185
186
 
187
+ class_option "private-gemserver-domain", type: :string, default: OPTION_DEFAULTS["private-gemserver-domain"],
188
+ desc: "domain name of a private gemserver used when installing application gems"
189
+
186
190
 
187
191
  class_option "add-base", type: :array, default: [],
188
192
  desc: "additional packages to install for both build and deploy"
@@ -538,6 +542,7 @@ private
538
542
  # start with the essentials
539
543
  packages = %w(build-essential)
540
544
  packages += @@packages["build"] if @@packages["build"]
545
+ packages += %w(nodejs npm) if node_version == "lts"
541
546
 
542
547
  # add databases: sqlite3, postgres, mysql
543
548
  packages << "pkg-config" if options.sqlite3? || @sqlite3
@@ -849,7 +854,9 @@ private
849
854
 
850
855
  def binfile_fixups
851
856
  # binfiles may have OS specific paths to ruby. Normalize them.
852
- shebangs = Dir["bin/*"].map { |file| IO.read(file).lines.first }.join
857
+ shebangs = Dir["bin/*"].map do |file|
858
+ IO.read(file).lines.first.encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "")
859
+ end.join
853
860
  rubies = shebangs.scan(%r{#!/usr/bin/env (ruby.*)}).flatten.uniq
854
861
 
855
862
  binfixups = (rubies - %w(ruby)).map do |ruby|
@@ -1039,6 +1046,19 @@ private
1039
1046
  nil
1040
1047
  end
1041
1048
 
1049
+ # Takes the domain of the private gemserver and returns the name of the
1050
+ # environment variable, as expected by bundler.
1051
+ #
1052
+ # For example, if the domain is "gems.example.com", the environment variable
1053
+ # name will be "BUNDLE_GEMS__EXAMPLE__COM".
1054
+ def private_gemserver_env_variable_name
1055
+ option = options["private-gemserver-domain"]
1056
+
1057
+ return nil if option.blank?
1058
+
1059
+ "BUNDLE_#{option.upcase.gsub(".", "__")}"
1060
+ end
1061
+
1042
1062
  # if running on fly v2, make a best effort to attach consul
1043
1063
  def fly_attach_consul
1044
1064
  # certainly not fly unless there is a fly.toml
@@ -86,10 +86,15 @@ ENV <%= build_env.join(" \\\n ") %>
86
86
  COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock ./
87
87
  <% if options.cache? -%>
88
88
  RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
89
+ <% if private_gemserver_env_variable_name -%>
90
+ --mount=type=secret,id=gemserver_credentials,dst=/kaniko/gemserver_credentials \
91
+ <%= private_gemserver_env_variable_name %>="$(cat /kaniko/gemserver_credentials)" && \
92
+ export <%= private_gemserver_env_variable_name %> && \
93
+ <% end -%>
89
94
  bundle config set app_config .bundle && \
90
95
  bundle config set path /srv/vendor && \
91
96
  bundle install && \
92
- <% if depend_on_bootsnap? -%>
97
+ <% if depend_on_bootsnap? && options.precompile != "defer" -%>
93
98
  bundle exec bootsnap precompile --gemfile && \
94
99
  <% end -%>
95
100
  bundle clean && \
@@ -98,8 +103,16 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
98
103
  cp -ar /srv/vendor .
99
104
 
100
105
  <% else -%>
101
- RUN bundle install<% if depend_on_bootsnap? -%> && \
106
+ <% if private_gemserver_env_variable_name -%>
107
+ RUN --mount=type=secret,id=gemserver_credentials,dst=/kaniko/gemserver_credentials \
108
+ <%= private_gemserver_env_variable_name %>="$(cat /kaniko/gemserver_credentials)" && \
109
+ export <%= private_gemserver_env_variable_name %> && \
110
+ bundle install<% if depend_on_bootsnap? && options.precompile != "defer" -%> && \
102
111
  bundle exec bootsnap precompile --gemfile<% end %> && \
112
+ <% else -%>
113
+ RUN bundle install<% if depend_on_bootsnap? && options.precompile != "defer" -%> && \
114
+ bundle exec bootsnap precompile --gemfile<% end %> && \
115
+ <% end -%>
103
116
  rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
104
117
 
105
118
  <% end -%>
@@ -115,7 +128,7 @@ COPY --from=node /usr/local/node /usr/local/node
115
128
  ENV PATH=/usr/local/node/bin:$PATH
116
129
 
117
130
  <% elsif using_node? -%>
118
- <%= render partial: 'npm_install', locals: {sources: Dir[*%w(package.json package-lock.json yarn.lock)]} %>
131
+ <%= render partial: 'npm_install', locals: {sources: Dir[*%w(.npmrc .yarnrc package.json package-lock.json yarn.lock)]} %>
119
132
 
120
133
  <% end -%>
121
134
  # Copy application code
@@ -5,13 +5,13 @@
5
5
  <% elsif yarn_version -%>
6
6
  # Install yarn
7
7
  <% end -%>
8
- <% if node_version -%>
8
+ <% if node_version && node_version != 'lts' -%>
9
9
  ARG NODE_VERSION=<%= node_version %>
10
10
  <% end -%>
11
11
  <% if yarn_version -%>
12
12
  ARG YARN_VERSION=<%= yarn_version %>
13
13
  <% end -%>
14
- <% if node_version -%>
14
+ <% if node_version && node_version != 'lts' -%>
15
15
  ENV PATH=/usr/local/node/bin:$PATH
16
16
  RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
17
17
  /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
@@ -1,5 +1,8 @@
1
1
  # Install node modules
2
2
  COPY<% if options.link? %> --link<% end %> <%= sources.join(' ') %> ./
3
+ <% if sources.join.include?('.yarnrc') && !Dir['.yarn/releases/*'].empty? -%>
4
+ COPY<% if options.link? %> --link<% end %> .yarn/releases/* .yarn/releases/
5
+ <% end -%>
3
6
  <% if sources.join.include? 'yarn' -%>
4
7
  RUN <% if options.cache? -%>--mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
5
8
  YARN_CACHE_FOLDER=/root/.yarn <% end -%>yarn install<% if options.lock? %> --frozen-lockfile<% end %>
@@ -3,6 +3,10 @@ services:
3
3
  web:
4
4
  <% if all_args.empty? -%>
5
5
  build: .
6
+ <% if private_gemserver_env_variable_name -%>
7
+ secrets:
8
+ - gemserver_credentials
9
+ <% end -%>
6
10
  <% else -%>
7
11
  build:
8
12
  context: .
@@ -10,6 +14,10 @@ services:
10
14
  <% all_args.each do |name, value| -%>
11
15
  <%= name %>: <%= value.html_safe? ? value : "\"#{Shellwords.escape(value)}\"" %>
12
16
  <% end -%>
17
+ <% if private_gemserver_env_variable_name -%>
18
+ secrets:
19
+ - gemserver_credentials
20
+ <% end -%>
13
21
  <% end -%>
14
22
  ports:
15
23
  - "3000:3000"
@@ -110,3 +118,9 @@ services:
110
118
  condition: service_healthy
111
119
  <% end -%>
112
120
  <% end -%>
121
+ <% if private_gemserver_env_variable_name -%>
122
+
123
+ secrets:
124
+ gemserver_credentials:
125
+ file: ./GEMSERVER_CREDENTIALS.secret.txt
126
+ <% end -%>
@@ -39,6 +39,11 @@
39
39
  <% end -%>
40
40
  <% unless options.api? -%>
41
41
 
42
+ <% if private_gemserver_env_variable_name -%>
43
+ # Ignore gemserver credentials.
44
+ GEMSERVER_CREDENTIALS.secret.txt
45
+
46
+ <% end -%>
42
47
  # Ignore assets.
43
48
  /node_modules/
44
49
  /app/assets/builds/*
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.5.3
4
+ version: 1.5.4
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-08-20 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails