Before you continue
Please make sure you have done the following :
- A Github account
- A Digital Ocean account & cash-in the voucher given earlier
- Have Ruby installed locally
- Have Redis Server installed locally
- Have PostgreSQL installed locally
- Prepare SSH key for your machine
Outline
In this tutorial we are building 2 simple apps - Shopping Cart & Customer Relationship Management (CRM) portal.
The Shopping Cart will have a catalogue of products, then customers can buy and sales will be captured. And in the end the customer’s information is sent to the CRM.
In addition to that, we want to queue up the API requests so that the purchase process is not blocked / slowed down.
And finally, we need to write an automated deployment script to deploy both apps to their respective servers.
Step 1: Creating the Shopping Cart
Estimate time: 20 mins
Create Rails App with PostgreSQL database [how ah?]
$ rails new shopping_cart --database=postgresql
$ cd shopping_cart
$ rake db:create
Admin login using Devise [how ah?]
# Gemfile
gem 'devise'
$ rails generate devise:install
$ rails generate devise Admin
$ rake db:migrate
Setup Upmin Admin on /admin [how ah?]
# Gemfile
gem 'upmin-admin'
# config/routes.rb
mount Upmin::Engine => '/admin'
Scaffold “Products” Model
Add some styles
[how ah?]
# Gemfile
gem 'foundation-rails'
$ rails g foundation:install
Scaffold “Sales”
Product Checkout & Sales
Step 2: Creating the CRM
Estimate time: 30 mins
User login using Devise [how ah?]
# Gemfile
gem 'devise'
$ rails generate devise:install
$ rails generate devise Admin
$ rake db:migrate
Scaffold Customers Model [how ah?]
$ rails g resource Customer email:string first_name:string last_name:string address:string zipcode:string country:string
Setup Upmin Admin [how ah?]
# Gemfile
gem 'upmin-admin'
# config/routes.rb
mount Upmin::Engine => '/'
“API Applications” Model
Setup API with Grape
Setup API Documentation with Grape-Swagger-Rails
Step 3: Integrating with API
Estimate time: 20 mins
Generate API token for Shopping Cart app
Use API token to send customer data to CRM
Setup Rails Config
Step 4: Queue Up Jobs
Estimate time: 15 mins
Setup Sidekiq
Use Sidekiq to queue up jobs
Step 5: Setup Digital Ocean
Estimate time: 15 mins
Generate / Get public SSH Key for machine
Add SSH Key
Create two (2) 14.04 x64 Ubuntu droplets with private networking
Step 6: Prep the Servers
Estimate time: 20 mins
Install rbenv with ruby-build
Install PostgreSQL
Install Redis Server
Security tweaks: change SSH port and disable root access
Step 7: Deployment
Estimate time: 15 mins
Setup Capistrano with Capistrano Rbenv + Capistrano Sidekiq + Capistrano Unicorn Nginx
Create & upload production settings
Finally … Deploy Live !!