Ruby
Article

Shelly Cloud: Deploy a Rails App in Less Than 5 Minutes

By Jesse Herrick

shellycloud

2 weeks gone, 1 app ready for production. What now? It’s time to deploy the app on a server. But you’re a developer, you can’t be expected to know everything about managing a VPS for a Rails app. Shelly Cloud is here to help. Shelly Cloud is a hosted developer platform for deploying Ruby or Ruby on Rails apps. If you’ve used Heroku before, it’s the same concept; just git push and you have a deployed app.

This concept is called Platform as a Service (a.k.a PaaS). In contrast to Virtual Private Server (VPS) hosting, PaaS configures the hardware and a deployment platform for you, whereas you must configure your own with a VPS. With a VPS, you must scale the application yourself. But with PaaS, this scaling is done for you as your traffic grows.

Shelly Cloud is a PaaS that does a lot for you; git-based deployment and various forms of scaling are the main ones. Shelly also includes various services (like databases) that are setup for you automatically. Sound awesome? Let’s deploy an app to Shelly Cloud.

As with any service, you’ll need an account. Shelly Cloud is not free, so check out their pricing and get signed up if you want to follow along

First we need something to deploy. Let’s create a simple little app. I won’t do much explanation of the code, as I can assume that you know basic Rails development if you’re reading this.

$ rails new shelly-books
$ rails generate controller pages index

Now for just a simple page:

# app/views/pages/index.html.erb
<h1>Hello, world!</h1>

<p>I'm alive! Thanks to a little help from <a href="https://shellycloud.com/"></p>

<small><%= Time.now %></small>

And now to route the root to this page…

# config/routes.rb

Rails.application.routes.draw do
  root to: 'pages#index'
end

This is just a little “Hello World” page that also displays the current time. Let’s see if we can deploy it.

Before we deploy, we need to add more dependencies to the Gemfile, then create a Cloudfile:

# ... other gems for app

gem 'puma' # or thin, if you'd like
gem 'shelly-dependencies', group: :production

# ...

Puma is one of the two web servers that Shelly Cloud supports, the other one being Thin. You may decide between these two using your own discretion, but for this example we’ll use Puma.

Make sure you bundle install and commit your changes before the next part.

Shelly Cloud has its own command line application, you can install it with RubyGems:

$ gem install shelly

Now let’s get our application ready for Shelly:

$ shelly login
Your public SSH key will be uploaded to Shelly Cloud after login.
Email (your@emailhere.com - default):
Password:

$ shelly add
# some options for your app

A new remote was added to your git repository, shelly, that we’ll push to in a moment. You’ll also notice a nice Cloudfile in your application root now. This is a purely Shelly Cloud configuration file so that the PaaS knows what to do with the application that you pushed. I added some comments to explain what each option does.

shelly-books: # our app name
  ruby_version: 2.2.2
  environment: production # RAILS_ENV
  domains: # a list of all the domains that you might be using
    - shelly-books.shellyapp.com
    # for example:
    # - something.here.com 
    # then point CNAME to shelly-books.shellyapp.com
servers: # you can make as many servers as you want
  app1: # our server name
    size: small # size of this server
    puma: 2 # minimum number of threads

    # other things you want on the server
    # delayed_job: 1
    # sidekiq: 1
    # clockwork: on
    # whenever: on
    # elasticsearch: on

    databases: # DBs to set up
      - postgresql
      # - mysql
      # - mongodb
      # - redis

We are now ready to push the app!

$ git push shelly master

Counting objects: 123, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (108/108), done.
Writing objects: 100% (123/123), 25.16 KiB | 0 bytes/s, done.
Total 123 (delta 24), reused 0 (delta 0)

 ---> Received push to cloud 'shelly-books'
 ---> Checking Gemfile
 ---> Creating code package... done.
 ---> Push accepted
 ---> Start your cloud using: `shelly start --cloud shelly-books`
To git@git.shellycloud.com:shelly-books.git
 * [new branch]      master -> master

Our app is almost ready for viewing, we just need to start our servers. Shelly Cloud’s pricing is based on usage, so you can start and stop servers as needed.

$ shelly start --cloud shelly-books
$ shelly open # your browser should open showing our beautiful page

Let’s see what we have!

Shelly Books (Alpha)

Good stuff! But that’s a pretty boring page, it just tells us the time. Let’s add some database stuff into it.

Disclaimer: I don’t particularly like the rails scaffold command, but we’re going to use it today in the interest of quickly showing off how to use a database on Shelly Cloud.

$ rails scaffold Book title:string author:string

You should be familiar with this output, so there’s no need to explain it. (You should probably commit here.) Now we need to setup our production database configuration.

Shelly Cloud provides environment variables for its databases. You can view those here.

# config/database.yml

# ... other DB config
production:
  adapter: postgresql
  database: <%= ENV['POSTGRESQL_DATABASE'] %>
  encoding: unicode
  pool: 16
  host: <%= ENV['POSTGRESQL_HOST'] %>
  username: <%= ENV['POSTGRESQL_USER'] %>
  password: <%= ENV['POSTGRESQL_PASSWORD'] %>
  port: 5432

Commit these changes and push the application to Shelly Cloud:

$ git commit -m "Add database config."
$ git push shelly master

You might be wondering if the migration needs to be manually run, and the answer is “no”. This article explains how code is deployed on Shelly Cloud, including when rake db:migrate runs. The answer is, on every push, the migration is run on the first deployment server.

Now let’s view our app again, but this time at the /books route.

Shelly-Books with some DB stuff

Feel free to play around with this to test the database functionality. It works great.

There you have it! A database-driven app deployed to Shelly Cloud in less than 5 minutes.

Extra: Custom Domain

To add a custom domain, simple append your domain to the domains list in your Cloudfile. Then point your domain’s CNAME record to your myappname.shellyapp.com domain.

Conclusion

From my experience writing this article, I would definitely recommend Shelly Cloud as a hosting provider; but there are plenty of options. Heroku is another PaaS option that provides languages other than Ruby — or maybe you want to set up your own VPS. No matter what hosting provider you use, the end goal is the same: easy deployment with reliable hosting. Shelly Cloud provides just that.

  • http://smefju.pl/ Maciej Małecki

    Hi Jesse,

    I am working at Shelly Cloud and I would like to thank you for writting this article. I noticed a few mistakes:

    1) It is not possible to use shellyapp.com as a CNAME. You can use a custom domain by pointing A record to the Shelly Cloud front-end server (https://shellycloud.com/documentation/domains)
    2) puma: 2 does not mean the minimum number of threads. This is the number of Puma webservers. Each server is configured to use up to 16 threads.
    3) config/database.yml file is overwritten by configuration files https://shellycloud.com/documentation/configuration_files. Shelly Cloud generates database config files by default. You can adjust settings using `shelly config edit` command.

    Once again, thanks for spreading a word about shelly. You can contact me in case of any futher questions ;)

  • Hunter Stevens

    To those interested in this service, it plans to shut down soon:

    Shelly Cloud will shut down on March 31, 2016. All services you use will be operational until then.

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in Ruby, once a week, for free.