We are trying to run Rails 5 with Webpacker in a Docker environment. We do not want the webpacker-dev-server; we want to pre-compile the assets.
Our docker file looks like the following:
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y \
build-essential \
libxml2-dev \
libxslt1-dev \
redis-tools \
npm
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get install -y nodejs
RUN apt-get update && apt-get install yarn
# cleanup
RUN rm -rf /var/lib/apt/lists/*
RUN mkdir -p /landing_app
WORKDIR /landing_app
ADD Gemfile /landing_app
ADD Gemfile.lock /landing_app
RUN bundle install
COPY . /landing_app
RUN npm rebuild node-sass --force
RUN yarn install
RUN RAILS_ENV=beta NODE_ENV=production SKIP_REDIS=true bundle exec rails webpacker:compile
EXPOSE 3042
CMD bundle exec rails s -p 3042 -b '0.0.0.0'
Our webpacker.yaml file looks like this:
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .coffee
- .erb
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR (Hot Module Replacement)
inline: false
overlay: true
disable_host_check: true
use_local_ip: false
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
beta:
<<: *default
compile: false
cache_manifest: true
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
Inside the docker container, I see all of the compiled files in APP_HOME/public/packs, and the manifest.json looks correct in the same location.
However, whenever I try to access the page, the Rails app is returning with the above error message.
I don't understand why files in the public directory are not being served.
You have to enable config.public_file_server.enabled in Rails so it can serve static assets.
nm, our config/environments/beta.rb
had config.public_file_server.enabled set to an environment variable we weren't passing in.
Most helpful comment
You have to enable
config.public_file_server.enabledin Rails so it can serve static assets.