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
# ... 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 (firstname.lastname@example.org - 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 email@example.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!
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
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
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.