1

I'm running a rails (4.2.10) application on Docker running on 64bit Amazon Linux/2.12.6. The application is running successfully, however, the asset pipeline is not. Oddly, I'm not receiving any error messages that I can see.

Furthermore, there are assets in app/public/assets

For example this .css file exists:

<link rel="stylesheet" media="all" href="assets/application-e627105c73433d07311d93ea3e4f53942589150887a45432397a6b1e80017a2e.css">

Dockerfile:

FROM ruby:2.4.2

ENV APP_HOME /app
ENV RAILS_ENV production
ENV RACK_ENV production
ENV SECRET_KEY_BASE 39c3bae00bf53ba9e3...

RUN apt-get update -qq && apt-get install -y --no-install-recommends build-essential
RUN apt-get install -y mysql-client
RUN apt-get install -y libxml2-dev libxslt1-dev
RUN apt-get install -y libqtwebkit4 libqt4-dev xvfb
RUN apt-get install -y nodejs
RUN apt-get clean autoclean \
  && apt-get autoremove -y \
  && rm -rf \
    /var/lib/apt \
    /var/lib/dpkg \
    /var/lib/cache \
    /var/lib/log

RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/tmp
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
RUN (bundle check || bundle install --without development test)

ADD . $APP_HOME

# NOTE: handles migrations (or db:setup if needed)
ENTRYPOINT ["sh", "script/docker/entrypoint.sh"]

RUN bundle exec rake assets:precompile --trace
VOLUME /app/public

EXPOSE 3000

CMD ["script/rails", "s", "-b", "0.0.0.0"]

Please let me know if you need further explanation or want to see anything else.

Asdrubal
  • 2,421
  • 4
  • 29
  • 37

1 Answers1

1

You need to add config.public_file_server.enabled = true in your config/environments/production.rb, or you can achieve that with an environment variable like that.

However, you might want to run a web server in front of your Ruby application server, so you need to check our Reverse Proxies.

  • Thank you for your answer, but from my understanding, this would only apply if I was using Rails 5 and I'm using Rails 4.2.10 – Asdrubal Jan 28 '19 at 15:46
  • @Asdrubal That config setting is still valid for rails 4 – Jay Dorsey Jan 28 '19 at 20:15
  • Wouldn't I be able to use `config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?` – Asdrubal Jan 29 '19 at 01:07
  • I assume that you use [the Asset Pipeline](https://guides.rubyonrails.org/v4.2/asset_pipeline.html#how-to-use-the-asset-pipeline), right? – Berkhan Berkdemir Jan 29 '19 at 21:49
  • @BerkhanBerkdemir yes – Asdrubal Jan 31 '19 at 15:13
  • I set config.serve_static_files to equal true (it was false), but I'm not sure if that's the best practice. Either way, it did work. – Asdrubal Feb 01 '19 at 16:03
  • Well, you have to set it `true`; otherwise, it can't serve assets over a Ruby application server. However, if you have a web server, you can serve assets over a web server. If you want to set a web server in front of your Ruby application, please check [Reverse Proxy](https://www.nginx.com/resources/glossary/reverse-proxy-server/). Also, if it helps, could you make the answer *correct answer*? – Berkhan Berkdemir Feb 01 '19 at 16:39