Backend Deployment

Backend Deployment

Apr 8, 2022 8:13 AM
Ruby on Rails


Cloud 66

Previous preparation

  • If you require to run a command on every new deployment, add a .cloud66/deploy_hooks.yml configuration file. An example structure for installing a Linux package can be:
  • staging: # Environment
      first_thing: # Hook point
        - command: apt-get install ffmpeg -y # Hook type
          target: any # Hook fields
          execute: true
    production: # Environment
      first_thing: # Hook point
        - command: apt-get install ffmpeg -y # Hook type
          target: any # Hook fields
          execute: true
  • If you require workers, add a Procfile to the root directory. Example content:
  • worker: bundle exec sidekiq -e $RAILS_ENV

New Rails server deployment

  1. On the Cloud 66 Dashboard, click on New Application.
    • If you haven’t, link your Github account to your Cloud66 account.
  2. Select the git repository you wish to deploy
  3. Select the branch, the environment, and the application name. Conventions to follow are:
    • staging branch will go to the Staging environment, master branch will go to the Production environment
    • The application name will be in Title Case and end with API for backend applications. The environment name is not needed.
  4. Click on Analyze Application and wait for a couple minutes
  5. Configure the deployment servers that will be used. Take into account:
    • At Cloud Provider, select the customer’s cloud account. If it doesn’t appear there, add it or contact your team leader
    • Server Region is customer dependant, get it from your team leader or the product manager.
    • Server Size should be t2.micro for staging and t2.medium for production
    • Deploy PostgreSQL should be Shared with the Rails server for staging and a New cloud server for production
  6. Click on Deploy Application.
  7. In the newly deployed application, add the RAILS_MASTER_KEY environment variable, as per the secure credentials instructions.
  8. Add a new SSL certificate
  9. With SSL set up, open your applications, go to Network Settings in the right-hand menu, go to the Redirects tab, and select the Redirect HTTP to HTTPS checkmark. Click on Apply Redirects before you leave
  10. If your project requires background jobs, set up the worker server and the Redis server

Setting up CName record

  1. On the AWS Route53 console dashboard click on Hosted Zone.
  2. image
  3. In the hosted zones you can find hosted zone details and the list of records.(click on Create record )
  4. image
  5. Fill up the necessary fields.
    • Fill in the record name. i.e.
    • Select the record type CNAME.
    • In the value, field fills in the domain name to which the Cloud66 server was hosted to and create the record.
    • image

Useful commands

To run these commands, first, install the Cloud66 toolbelt on your machine by running curl -sSL | bash

  1. cx stack list: List all the stacks. Useful to get the $STACK_NAME value for the other commands, and see the last deployment status and date/time
  2. cx ssh -s $STACK_NAME web: Open an ssh session at the desired stack’s main web server
  3. cx redeploy -s $STACK_NAME: Redeploy the desired stack
  4. cx tail -s $STACK_NAME web $LOGFILE View real-time logs of the desired log file. Values for $LOGFILE can be:
    • staging.log / production.log: The main Rails application log server. Choose the right name according to the server’s environment
    • nginx_error.log: The Nginx HTTP server log