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?
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.
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