Heroku and a jr. developer’s reputation
My teammates and I made this reputation sharing app for entrepreneurs, and we did it in under 10 days while attending a coding bootcamp in Toronto, ON. I was pretty happy with how it turned out and we even won a playful “Best App” award at the public demo. After bootcamp, I decided to deploy the app on Heroku so I could reference it in my portfolio. After a few weeks had gone by, I logged into the app to check on how many persons had actually signed up to try it. Lo and behold all the user uploaded images had disapeared! What happened?
To start my approach to resolving the problem, I looked up which gem my teammates and I used to handle the image uploading. In the Gemfile , the gem carrierwave was present without a version specifier. To list all the gems installed locally, from inside the app’s directory run
gem query --local
I got back a version 0.10.10. Well this didn’t seem right. It wasn’t even version 1! Because the feature wasn’t working properly already, it was worth upgrading the gem to the latest version ’~> 1.2, >= 1.2.1’ and I was content to move forward.
Next I looked into the uploader file `avatar_uploader.rb` and just did a quick review of the code which was only a few lines. What stuck out was the line where we were overriding the default directory to store the avatar images in, as something that could be related to the missing images issue.
After a quick search, I found out that Heroku allows you to upload files inside a temporary directory, but just in order to send to a 3rd party service. Everything in there gets destroyed after ~15 minutes. This explained why my images were not persisting. Problem identified!
AWS S3, or similar storage services, are important when designing applications to scale and are a perfect solution to Heroku’s ephemeral filesystem.
I must say it’s been over a year since I last set up an S3bucket, and I have to say that the UI had become much less complicated which made it fairly easy to setup.
In avatar_uploader.rb I noticed that the app was processing images to fit a pretty small image size, this was resulting in more than a comfortable amount of negative space around the user’s avatar in their public profile. Here I changed the process parameters to resize instead of fit to a larger image.
process resize_to_fill: [300, 300]
To interface with my new S3 service, I’d need to use a cloud services library and fog has full S3 integration so that was the one to use. I then created a CarrierWave initializer in which I configured the provider as fog/aws and supplied it my credentials.
That seemed to do the trick, and after re-deploying, everything was right again and my reputation could now start it’s road to recovery.