How to Deploy a Ruby App in 2020
Deploying a Ruby app has evolved over the last decade. There are many traditional ways to deploy ruby into the cloud such as using virtual machines or docker containers, but now you can even more easily get online and update your ruby service for free. This guide will show you how to deploy a ruby app online for free and how to update the app’s code with no downtime.
Getting Started With Ruby
- Install git
- Install ruby
- This guide requires a free GitHub account
- This guide requires a free KintoHub account
Deploy A Ruby App To The Cloud
In the following steps, we are going to use KintoHub to deploy your app to the Cloud. The first thing we need to do is copy the example code onto your GitHub account. You can do this by going to the following repository and click Use this template at the top right.
Once you have created the ruby-app example within your Github account, login to your KintoHub account and do the following:
- Click on the Create Service at the top right
- Choose Web App from the service type list
- Connect and give access to your ruby-app on your Github account. Then select that repository.
- Change the Language from `Dockerfile` to `Ruby`
- Choose Language Version 2.5
- Set the Build Command to `gem install bundler && bundle install`
- Set the Start Command to `bundle exec ruby app.rb`
- Set the port to 8000
- Click Deploy at the top right.
After one minute, your app should be built and deployed and accessible with a URL at the bottom of the logs.
After opening the URL you can add the extension hello/stranger
and you will get the response
{“message”:”Hello stranger”}
Update your Ruby App
Now let’s say you want to make some changes to your app and you want to push an update to your users. First, we need to clone the code to your local machine. Make the changes, then push the new code.
- Go to your Github repository and click on Code and copy the URL.
- Open a terminal and run
git clone {paste-your-repo-here}
- Open up the app.rb file and change
/hello/
to/goodbye/
Test Your Ruby App Locally
Before pushing any code, you must test it! To test your ruby app, run the following command.
gem install bundler && bundle install
bundle exec ruby
- Open your browser to https://localhost:8000/goodbye/stranger and you should see a successful response
Now that we know your code works, you can push it to Github with the following commands:
git add . && git commit -m ":alien: refak(App): goodbye endpoint" && git push
Deploy Your changes
Finally, we need to deploy the changes you just tested which should be working correctly. Go back to KintoHub and do the following.
- Click on your ruby-app service
- Click Trigger Deploy at the top right
After a minute, you should see again a successful message at the bottom with the URL to access. When you trigger a deployment on KintoHub, it does not take down your old version until your new version is live and traffic has been redirected to it. This is known as a no-downtime deployment.
What’s Next?
KintoHub comes packed with many additional features to debug and enrich your Ruby App.
- Optimize your costs or scale your app with Advanced Settings
- Set up a Custom Domain to have your own custom URLs.
- View your Console Logs to debug any issues.
Conclusion
That’s it! Within a few minutes, you should have deployed and updated your Ruby App. If you have any issues with this example or want to learn more, please join us on Discord. There are also more advanced guides that can be found here.