1421825741heroku-deployment

Simply Deploy React.js App to Heroku

If you have read my another post about creating a ToDo app in react you are good to go; if not see this post.

You know that React App is a single page application containing only static assets. So, you only need to setup a mechanism to serve your static assets like CSS, JS, HTML, IMAGE, etc. files when clients ask for. Either you can use market leader HTTP servers like Apache, Nginx, etc or simple Express server that runs in Node.js.

Continue reading

banner

React.js | Advanced Todo App from scratch for beginner | Bootstrap | In a nut shell

Introduction

It is a good practice to follow community standards while developing softwares. It has some major pros like

  • Its easier to understand and debug/maintain software
  • quicker to get help when needed from community
  • It will lower development cost [Money and Time]

We will be taking the convention used by this project into consideration. react-slingshot

Initialize

Make a dir called ‘todo‘ and initialize a node.js app. Continue reading

Developer’s checklist: Production deployment

One has to be very careful for shipping new changes/features to the production server.

When feature is said to be done

Assumption: Proper development processes have been followed

  1. Smoke Test in local machine
  2. Production Database backups
    • Generate snapshots or database-dumps
    • Store the backups in safe places
    • In case of Heroku, you will be provided with backup-tools
  3. Codebase versioning in Github / Diffusion
    • Create tags with proper naming conventions followed
    • eg V 0.1.1 or V 1.0.0 pre
  4. Deployment to production
    • Deploy the changes to the server
    • Make sure you run rake db:migrate is any migration pending
  5. Do data migrations if required
    • Already existing Production data might not co-op with your new code changes
      • reasons: there might be some data-fields manipulations or
        • new cols might have been added and data need to be filled in; data to be gathered from existing fields
    • Document the migration code you wrote for data-migrations [remember I am not taking about schema migrations]
    • eg
TransactionHistory.recurring_rewards.each do |tx|
   charge = Stripe::Charge.retrieve(tx.charge_id)
   invoice = Stripe::Invoice.retrieve(charge.invoice)
   subscription_id = invoice.subscription
   metadata = tx.transaction_additional_detail.metadata
   tx.transaction_additional_detail.update metadata: metadata.deep_merge(
                                           {
                                               subscription_id: subscription_id,
                                               invoice_id: invoice.id
                                           })
end
  1. Smoke test in production
ssh

Unix : SSH server add new user’s ssh keys

You have not chosen to deploy your application to fancy web hosting services like Engineyard, Digitalocean, or Heroku then you might be willing to know how to give other developers collaborating in this project access to the server via SSH. In other words you want to let others to deploy the application via SSH (eg. Capistrano).

Well, its pretty much simpler than you have thought.  Follow the steps

  • Copy the public key of your colleague to clipboard ( Ctrl + C )
  • SSH into the server
  • If you want to use the same username for all developer (say `deployer`)
    • $ cd /home/deployer/.ssh
      $ sudo nano authorized_keys
    • Paste the SSH public key of your colleague at the end of the file
    • Save the file
    • And you are Done!
    • Now your colleague should have access to the server
  • If want a separate username for every individual
    • It would be great if you create separate user-group for deployment purposes like `deployers`
    • create a new user in that group with privileges you like
      • to give sudo access you need to update the sudoers file
      • The configuration file for sudo is /etc/sudoers
    • goto that particular user’s home directory
    • add his ssh public key to the /home/user/.ssh/authorized_keys file
      • the .ssh folder might not already be available, you can create though
      • $ mkdir /home/user/.ssh
      • copy the content using `nano or echo`  into the file
    • Now you are Done!

 

capistranologo

Capistrano : SSHKit : Introduction

SSHKit is an amazing tool to run any commands on your VPS or docker images as any user. Capistrano uses it to all the server related stuffs. In other words you can build your own deployer software or server maintenance tools using SSHKit.

$ gem install sshkit

Simple Introduction

Lets create a ruby script to create a file in my VPS’s home directory

require 'sshkit'
require 'sshkit/dsl'
on ['deployer@4X.79.XXX.XX1'], in: :sequence, wait: 1 do |host|
  within '~' do # or '/home/deployer/'
    as :deployer do
      execute 'echo', 'My name is shiva > shiva.txt'
    end
  end
end

Go and check in your VPS, you see the file Continue reading

Capistrano 3.0 : Task Flow : Rails deployment

Deploy flow

When you run cap production deploy, it invokes the following tasks in sequence:

deploy:starting    - start a deployment, make sure everything is ready
deploy:started     - started hook (for custom tasks)
deploy:updating    - update server(s) with a new release
deploy:updated     - updated hook
deploy:publishing  - publish the new release
deploy:published   - published hook
deploy:finishing   - finish the deployment, clean up everything
deploy:finished    - finished hook

Notice there are several hook tasks e.g. :started, :updated for you to hook up custom tasks into the flow using after() and before().

Flow examples

Continue reading

Capistrano 3.0 for Rails app deployment

Capistrano is designed to run commands remotely. To do this we’ll need to specify a server, which we do by calling server. We need to pass this the address of a server and a role. We’ll explain roles later; for now we’ll just set this to web.

First you need to set the configurations. Common settings go to the `deploy.rb` and environment specific settings goes to either 'config/deploy/production.rb' or 'staging.rb'

Continue reading