Skip to content

Commit 932650a

Browse files
davezuckermanDavid Zuckerman
andauthored
Added symbolic link to node_modules for production build and configure yarn build in prod target (#17)
* Added symbolic link to node_modules for production build and configure yarn build in prod target Moved yarn build removed commented out code * setting type to module in application layout, setting asset precompile in assets.rb initializer,having bundle call rails in Dockerfile for precompile * added symbolic link to node_modules --------- Co-authored-by: David Zuckerman <dzuckerm@library.berkeley.edu>
1 parent b5c7d5a commit 932650a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ RUN mkdir -p /opt/app/tmp \
7676
# Add binstubs to the path.
7777
ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/.bin:$PATH"
7878

79+
# Add path to node_modules
80+
ENV NODE_PATH=/usr/local/yarn/node_modules
81+
7982
# If run with no other arguments, the image will start the rails server by
8083
# default. Note that we must bind to all interfaces (0.0.0.0) because when
8184
# running in a docker container, the actual public interface is created
@@ -85,7 +88,7 @@ ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/.bin:$PATH"
8588
# yet, so if the build fails before the `bundle install` step below, you
8689
# will need to override the default command when troubleshooting the buggy
8790
# image.
88-
CMD ["rails", "server", "-b", "0.0.0.0"]
91+
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
8992

9093
# =============================================================================
9194
# Target: development
@@ -131,7 +134,7 @@ RUN bundle install
131134
# re-install.
132135
COPY --chown=$APP_USER:$APP_USER . .
133136

134-
RUN yarn install --cwd /usr/local/yarn
137+
RUN yarn install --frozen-lockfile --cwd /usr/local/yarn
135138

136139
# =============================================================================
137140
# Target: production
@@ -160,18 +163,19 @@ COPY --from=development --chown=$APP_USER /usr/local/yarn /usr/local/yarn
160163
# Ensure the bundle is installed and the Gemfile.lock is synced.
161164
RUN bundle config set frozen 'true'
162165
RUN bundle install --local
163-
166+
RUN ln -s /usr/local/yarn/node_modules /opt/app/node_modules
164167
# ------------------------------------------------------------
165168
# Precompile production assets
166169

167170
# TODO: Figure out why jsbundling-rails doesn't invoke `yarn build`
168171
# *before* Sprockets reads app/assets/config/manifest.js
169-
RUN yarn install --cwd /usr/local/yarn
172+
WORKDIR /opt/app
173+
RUN yarn build
170174

171175
# Pre-compile assets so we don't have to do it after deployment.
172176
# NOTE: dummy SECRET_KEY_BASE to prevent spurious initializer issues
173177
# -- see https://github.com/rails/rails/issues/32947
174-
RUN SECRET_KEY_BASE=1 rails assets:precompile --trace
178+
RUN SECRET_KEY_BASE=1 bundle exec rails assets:precompile --trace
175179

176180
# ------------------------------------------------------------
177181
# Preserve build arguments

app/views/layouts/application.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
<%= csp_meta_tag %>
1010

1111
<link rel="stylesheet" href="https://use.typekit.net/rxa5jay.css">
12-
13-
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
12+
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true, type: "module" %>
1413
<%= javascript_include_tag "items", "data-turbo-track": "reload", defer: true %>
1514
<%= javascript_include_tag "terms", "data-turbo-track": "reload", defer: true %>
1615
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>

config/initializers/assets.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
# folder are already added.
1414
Rails.application.config.assets.precompile += %w[*.png]
1515

16+
Rails.application.config.assets.precompile += %w[
17+
application.js
18+
items.js
19+
terms.js
20+
viewer.js
21+
marc-reload.js
22+
]
1623
# Rails.application.config.assets.configure do |env|
1724
# env.css_compressor = :sass
1825
# end

0 commit comments

Comments
 (0)