We will use our Paperclip-demo reference application to describe the usage of Paperclip with the anynines Swift service. This repository is a fork of Thoughtbot’s Paperclip reference application adjusted to the anynines use case. The app will demonstrate how to create different sized thumbnails, display resized images on different screens, and gracefully degrade to display missing avatars “missing.png” for friends without an avatar.
You can run the app locally by executing the following commands:
$> git clone firstname.lastname@example.org:anynines/paperclip_demo.git $> cd paperclip_demo $> bundle $> rake db:create db:migrate $> bundle exec rails s
A diff including all adjustments to the original app can be viewed here. The next paragraphs describe the adjustments in detail.
To enable Paperclip’s support for OpenStack Swift we added the fog gem to the Gemfile. The fog gem provides the api for accessing the object store to Paperclip. In addition we set the Ruby version to 2.0.0 and added the rails_12factor gem to adjust the application to the anynines PaaS environment.
Since anynines provides the Swift credentials within environment variables, we need to read the application environment and configure Paperclip to use the fog driver with the retrieved credentials. The config/initializers/paperclip.rb file implements the needed Paperclip configuration steps:
- Parse the Swift credentials from the environment
- Create a public Swift bucket to store our images if the bucket isn’t already present
- Configure paperclip to use the Swift credentials
Active Record Initializer
We added an initializer for the automatic execution of Active Record migrations at application startup in config/initializers/run_migrations.rb. This simplifies the app deployment process since we don’t need to execute the migrations manually when deploying the application for the first time.
The .cfignore file is used to exclude files and directories from the Cloud Foundry deployment process. Since we don’t want to upload our locally added images, logs and temporary files to the anynines servers, we added the according directories to the .cfignore file.
The application provides a manifest.yml example file which has to be configured to address your desired application identifier and route within the anynines system. Please copy the manifest.yml.example to app_root/manifest.yml and replace all occurrences of app_name with your desired application identifier.
Deploy the application to anynines.com
You can deploy the application to anynines by executing the cf push command from the applications root directory:
$> cf push
Please sign in to leave a comment.