This is a follow up post to yesterday’s article on how I work with asset pipeline for a Heroku hosted app.
While the setup described from the previous article works. It leaves a few sticking points.
- Before I do assets precompile, I have to either
exportthe necessary environment variables manually, or set them up in my .zshrc globally.
- It’s hard to precompile assets for different deployment targets, e.g. staging and production.
- I have to remember to run the assets clean rake task to keep my local dev env sane.
So … I did some follow up work. The README I wrote for the specific project is as follow.
Assets are precompiled locally and automatically uploaded to S3 with the help from the asset_sync gem.
After step into the project root directory, simply calling a custom ap() function, such as
to compile the assets and upload the compiled assets to S3.
For this to work, RVM on local development machine is required. The handy function
ap() is defined in
.rvmrc under the project root.
The argument passed into the
ap() function should be a valid Heroku Git remote name.
For example, we have staging setup on Heroku because of the following
git remote output.
This means we will need to create a
.projectrc.staging file under the project root. A projectrc template is provided,
.projectrc.sample. 3 config variables need to be filled in.
FOG_DIRECTORY is the Amazon S3 bucket name. To mute
fog’s noisy output during assets precompile, name the S3 bucket using only alphabets and
. is recommended.
The same 3 variables are also set on Heroku and can be found by doing
ap() function does the following
- precompile assets locally
- upload the compiled assets under
/public/assetsto the corresponding S3 buckets
- purge local compiled assets from
/public/assets, with the exception of
/public/assets/manifest.xml, which is pushed to Heroku.
Now to finish it up, here’s my .rvmrc
And here’s the .projectrc.sample
Hope this makes sense and helps.