Ruby: Deploy to production
Deploy Ruby code to production in minutes with Stackhero
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use Ruby cloud solution that delivers numerous advantages, including:
- Deploy your application in just a few seconds with a simple
git push.- Use your own domain name and take advantage of automatic configuration of HTTPS certificates for enhanced security.
- Benefit from automatic backups, one-click updates, and clear, transparent, and predictable pricing.
- Enjoy optimal performance and enhanced security thanks to a private, dedicated VM.
Save time and make your life easier: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!
Stackhero's Ruby cloud hosting service makes it easy to put your Ruby projects online in just a few minutes. You benefit from a robust platform designed to simplify deployment and let you focus on your application, not the infrastructure.
Here’s what you get:
- Deploy your code with a simple
git push. - Use your own custom domain, with automatic TLS certificate (HTTPS) management.
- Run your application on dedicated, isolated infrastructure for enhanced security and privacy.
- Take advantage of HTTP/2, TLS 1.3 (HTTPS), WebSockets, GZIP and Brotli compression, ETag support, TCP and UDP port access, and much more.
Prerequisites
All you need to get started is Git installed on your computer.
<!--  -->If you want to save time or would rather avoid setting up a local environment, you can check out Stackhero’s Code-Hero.
Code-Hero is a browser-based development environment that works on any device. Based on a VSCode fork, it comes with essential tools already installed and configured, so you can start coding right away with zero setup.
Steps to deploy on Stackhero
Deploying your Ruby application to Stackhero is straightforward. Here’s the workflow, with each step detailed below:
- Create a Ruby service on Stackhero.
- Add your SSH public key to your Ruby service configuration.
- Set up the
git pushcommand on your development platform. - Add a Makefile to your project.
- Deploy your code to production.
If you encounter any issues during deployment, the Troubleshooting documentation helps you quickly find solutions and keep moving forward.
Configuring your Ruby service
If you haven’t created a Stackhero for Ruby service yet, you can do so from your Stackhero dashboard in just a few minutes.
Once your Ruby service is up and running, the next step is to add your SSH public key. To display your public key, run:
cat ~/.ssh/id_*.pub
Don’t have SSH keys yet?
You can generate one with:
ssh-keygen -t ed25519
To add your SSH key, go to your Stackhero dashboard, select your Ruby service, click "Configure", and paste your public key into the "SSH public keys" section.
<!--  -->Tip: To save time in the future, you can add your SSH public key to your Stackhero profile. Any new services you create will include it automatically.
Click your profile picture at the top right of the dashboard, select "Your profile", and add your SSH public key.
Setting up the git push command for deployment
Deployment on Stackhero uses the Git CLI and the git push command, so there’s no need to install any extra tools.
You can copy the git remote command from your service’s main page in the Stackhero dashboard. It usually looks like this:
git remote add stackhero ssh://stackhero@<XXXXXX>.stackhero-network.com:222/project.git
Creating a Makefile for Stackhero deployment
To tell Stackhero how to run your application, add a Makefile at the root of your project. This file defines the commands Stackhero will use during deployment.
If you’re new to Makefiles or the
makecommand, the steps below will guide you through creating a working Makefile.
Create a Makefile with the following content:
run:
rake assets:precompile
rake db:migrate RAILS_ENV=production
RAILS_ENV=production bundle exec puma -C config/puma.rb
What this Makefile does:
- The
runrule is required. Stackhero looks for this rule as the entry point during deployment. Keep this rule name. - The example uses
rakeandbundle, but you can adjust these commands to fit your application. - Each command line must start with a tab character, not spaces. If you see a
*** missing separatorerror, check for tabs.
In the example above, deployment will:
- Precompile assets such as JavaScript and CSS into the
public/assetsdirectory. - Run database migrations.
- Start the Puma server to serve your application.
Deploying your Ruby application
You’re ready to deploy. Use:
git push stackhero main
During the first deployment, Git will ask you to confirm the SSH key fingerprint. Type "yes" to continue.
After a short wait, your application will be online.
<!--  -->Access your deployed application at the address shown in your Stackhero dashboard. The address will look like https://<XXXXXX>.stackhero-network.com.
Your application is now live in production.
If you encounter any issues during deployment, the Troubleshooting section covers common problems and their solutions.
Conclusion
You’ve seen how to deploy Ruby code to production with Stackhero, using a process that’s both powerful and straightforward.
For advanced topics, such as deploying different Git branches, tags, or commits, or managing multiple environments like staging and production, see the Advanced Deployment Usages documentation. You’ll also find tips for using environment variables and other useful features.
If you have any questions or run into issues, the Troubleshooting documentation is always available to help you keep your deployment workflow smooth and efficient.