Ruby: Deploy to production
How to deploy your Ruby code to production in just a few minutes
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use Ruby cloud solution offering a range of advantages, including:
- Deploy your application within seconds using a simple
git push.- Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
- Take advantage of automatic backups, one-click updates, and clear, transparent, and predictable pricing.
- Enjoy optimal performance and enhanced security thanks to a private, dedicated infrastructure.
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 deploy your Ruby projects to production in just a few minutes, combining a powerful platform with an intuitive user experience.
Here is 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 maximum security and privacy.
- Benefit from support for HTTP/2, TLS 1.3 (HTTPS), WebSockets, GZIP and Brotli compression, ETag, TCP and UDP port access, and much more.
Prerequisites
The only thing you need to start deploying your projects on Stackhero is Git installed on your computer.
<!--  -->If you want to save time or would rather avoid setting up a complex local environment, consider trying Stackhero's Code-Hero.
Code-Hero is a ready-to-use development platform you can access directly from your browser, on any computer, tablet, or phone. Based on a VSCode fork, it comes with all the essential tools pre-installed and pre-configured, so you can start coding instantly without any setup.
Steps to deploy on Stackhero
Deploying your Ruby application on Stackhero is a straightforward process. Here are the steps you will follow, which we will detail 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 can help you quickly find a solution. It's always a good idea to check there first to save time and avoid frustration.
Configuring your Stackhero for Ruby service
If you have not yet created a Stackhero for Ruby service, you can do so from your Stackhero dashboard in just a few minutes.
Once your Ruby service is running, the next step is to add your SSH public key. You can find your public key by running:
cat ~/.ssh/id_*.pub
Don't have SSH keys yet?
You can generate them 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: Want to save time in the future? Add your SSH public key to your profile so it will be automatically included when you create new services.
Simply click your profile picture in the top right corner of the dashboard, select "Your profile", and add your SSH public key there.
Setting up the git push command for deployment
Deployment on Stackhero uses the Git CLI and the git push command, so you do not need to install any additional 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, you need to create a Makefile at the root of your project. This file defines the commands Stackhero will use during deployment.
New to Makefiles or the
makecommand? Don't worry, the steps below will guide you through everything you need.
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
Here's what happens in this Makefile:
- The
runrule is required; Stackhero will automatically execute it during deployment. Please keep this name, as it serves as the entry point. - The commands use
rakeandbundle, but you can adapt them as needed for your application. - Make sure each command line starts with a tab character, not spaces. If you see an error like
*** missing separator, check this formatting.
In the example above, deployment will:
- Precompile assets such as JavaScript and CSS into the
public/assetsdirectory. - Run any required database migrations.
- Start the Puma server to serve your application.
Deploying your Ruby application
You're ready. To deploy your code to Stackhero, use:
git push stackhero main
The first time you run this command, you will be asked to confirm the SSH key fingerprint. Simply answer "yes" to continue.
After a short wait, your application will be online.
<!--  -->You can access your deployed application at the URL shown in your Stackhero dashboard. It will typically look like https://<XXXXXX>.stackhero-network.com.
Congratulations. Your application is now live in production.
Having trouble with deployment?
Be sure to check the Troubleshooting section for quick solutions.
Conclusion
You have just learned how to deploy Ruby code to production using Stackhero, with a process that is both simple and powerful.
To go further, the Advanced Deployment Usages documentation covers topics such as deploying different git branches, specific tags or commits, and managing multiple environments like staging and production. You'll also find tips for working with environment variables and much more.
And remember, if you encounter any issues during deployment, the Troubleshooting documentation is an excellent resource to help you resolve them efficiently and keep your workflow smooth.