Key Takeaways
- Shelly Cloud is a hosted developer platform for deploying Ruby or Ruby on Rails apps, similar to Heroku. It is a Platform as a Service (PaaS) that configures the hardware and deployment platform, scales the application as traffic grows, and automatically sets up services like databases.
- To deploy an app on Shelly Cloud, you need to create an account, set up your application, add the necessary dependencies to the Gemfile, create a Cloudfile for Shelly Cloud to know what to do with the application, and push the app using Git. Shelly Cloud also supports two web servers, Puma and Thin.
- Shelly Cloud provides several benefits for Rails app deployment. It offers a robust, scalable infrastructure, automatic scaling, database backups, and 24/7 monitoring. It eliminates the need for server management, allowing developers to focus on coding. It also supports multiple environments, making it easy to manage different stages of an application.
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!
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.
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.
Frequently Asked Questions (FAQs) about Shelly Cloud and Rails App Deployment
What is Shelly Cloud and how does it work?
Shelly Cloud is a platform as a service (PaaS) that allows developers to deploy, manage, and scale their applications. It supports several programming languages, including Ruby on Rails. Shelly Cloud provides a user-friendly interface and a robust infrastructure that takes care of server management, allowing developers to focus on coding. It also offers features like automatic scaling, database backups, and 24/7 monitoring.
How can I deploy a Rails app on Shelly Cloud?
Deploying a Rails app on Shelly Cloud is a straightforward process. You need to create an account on Shelly Cloud, set up your application, and push your code using Git. Shelly Cloud will then build your application and deploy it. The platform also allows you to manage your application’s environment variables and add-ons.
What are the benefits of using Shelly Cloud for Rails app deployment?
Shelly Cloud offers several benefits for Rails app deployment. It provides a robust and scalable infrastructure, automatic scaling, database backups, and 24/7 monitoring. It also eliminates the need for server management, allowing developers to focus on coding. Moreover, Shelly Cloud supports multiple environments, making it easy to manage different stages of your application.
Can I use Shelly Cloud for other programming languages besides Ruby on Rails?
Yes, Shelly Cloud supports several programming languages besides Ruby on Rails. It also supports frameworks like Django for Python and Express for Node.js. You can check the Shelly Cloud documentation for a complete list of supported languages and frameworks.
How does Shelly Cloud handle database backups?
Shelly Cloud automatically backs up your database every 24 hours. You can also manually trigger a backup at any time. The backups are stored for 30 days, and you can download them at any time during this period.
How does Shelly Cloud ensure the security of my application?
Shelly Cloud takes several measures to ensure the security of your application. It uses SSL encryption for all data in transit, isolates each application in its own container, and regularly updates its infrastructure to protect against vulnerabilities.
What kind of support does Shelly Cloud offer?
Shelly Cloud offers 24/7 support to its users. You can reach out to their support team via email or live chat. They also have a comprehensive documentation and a community forum where you can find answers to common questions.
How does Shelly Cloud handle application scaling?
Shelly Cloud automatically scales your application based on its resource usage. You can also manually scale your application by adding or removing dynos. This allows you to handle traffic spikes without any downtime.
Can I use Shelly Cloud for free?
Shelly Cloud offers a free tier for small applications. However, for larger applications or for applications with high traffic, you will need to choose one of their paid plans.
How can I monitor my application’s performance on Shelly Cloud?
Shelly Cloud provides a dashboard where you can monitor your application’s performance. It shows metrics like response time, throughput, and error rate. You can also set up alerts to be notified when your application’s performance degrades.
Jesse Herrick is an avid Ruby developer who specializes in web development. He is a back-end developer at Littlelines and loves programming. You can read his personal blog at: https://jesse.codes.