Skip to content

Instantly share code, notes, and snippets.

@jtsaito
Last active December 14, 2015 09:48
Show Gist options
  • Save jtsaito/29a5eb41b054dad6e82c to your computer and use it in GitHub Desktop.
Save jtsaito/29a5eb41b054dad6e82c to your computer and use it in GitHub Desktop.
On Provisioning a Simple Rails App with OpsWorks

Fourteen-step procedure

... which I followed for setting up a simple Rails App on Opsworks.

  1. Set up an IAM role for ssh to the instances later
  2. Set up a Stack
  3. Set up a Layer RDS instace (used MySQL)
  4. Set up the RDS' VPC id, endpoint, master user, password
  5. Create a database for the App and a user to connect to it using the db master user
  6. Add the RDS details in the database section of the custom JSON (see custom json below)
  7. Setup the Layer with Layer Type Rails App.
  8. Create an App
  9. setup github deploy key (generate pub key, put private key on Rails App's Github repo)
  10. setup set document root to public
  11. generate SECRET_KEY_BASE with bundle exec rake secret and store in OpsWorks' Environment Variables
  12. register rds as data source using Database instance and Database name
  13. Set up Rails App's Git repo.
  14. Remove the config/security.conf from the .gitignore. The config/security.conf file containting production entry secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  15. Create instance
  16. In EC2 Actions Security Groups assign the VPC default Security group to the instance (otherwise it won't talk to the RDS)
  17. In Instances, assign App
  18. Provision and deploy instance

Custom JSON

{
  "deploy": {
      "rails_app_short_name": {
        {  
          "database": {
            "username": "...",
            "password": "...",
            "database": "...",
            "host": "dbinstancename.....eu-west-1.rds.amazonaws.com",
            "adapter": "mysql" 
          }
        }
      }  
    } 
}

Remarks

In the Rails-App Layer, no recipes are needed other than the ones provided automatically.

Log files for the Passenger/Apache2 setup of the Layer end up in /var/logs/apache2/. For nginx/Unicorn they end up in the Rails application's log directory. The nginx/Unicorn logs I found to be more verbose and valuable for feedback because the contained stack traces where the others did not. The full custom JSON with all values contained can be found in /var/lib/aws/chef/[time-stamp-of-deployment].json. This comes in handy if you are in doubt about the values passed into the JSON from OpsWorks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment