Rails assets precompiled in before_release are not avail for the app

Hey,

So we have a Rails app and our .aptible.yml looks like this
before_release:
- bundle exec rake db:migrate
- bundle exec rake assets:precompile

When the app is deployed, it looks like the assets are not there and the app is compiling them on the fly.

My guess here would be that before_release runs in the context of an ephemeral container, not the container that was deployed. is that the case? Or is there something else at play here?

Thanks!

My guess here would be that before_release runs in the context of an ephemeral container, not the container that was deployed. is that the case? Or is there something else at play here?

That is correct. before_release commands are executed in an ephemeral container before actual release containers (which will serve your traffic) are deployed. You should run asset precompilation as part of your Docker build to have precompiled assets available in the latter.

Note that you might need access to your app’s environment in the build for this to work. If so, review these instructions.

1 Like

Thanks again, very helpful!

Yeah, ENV vars were a problem, but Aptible docs are clear about that.

Speaking of docs - I think it will be awesome to mention the context before_release commands are executed in here

Cheers!

Definitely! I was hoping to link you to that page in my earlier reply, then I realized this information was indeed missing from our docs!

I’ve completed this section now :slight_smile:

Thanks!

I’m trying to reconcile this information with the advice on serving static assets from S3 (https://www.aptible.com/documentation/enclave/tutorials/faq/static-assets.html).

I’ve successfully incorporated the asset_sync gem and my assets are being served from S3… but I don’t understand why the static asset documentation suggests that the precompile should be run as a before_release command. This implied to me that you would MOVE the precompile out of the Dockerfile to the before_release, but I couldn’t get that to work, possibly because of the way I did it:

In the Dockerfile, I make sure to source the .aptible.env file:
RUN set -a && . /app/.aptible.env &&
bundle exec rake assets:precompile

Whereas in the .aptible.yml, I’m not doing that. Should I be?

Any clarification would be appreciated. Thanks.
–Jessica