Ruby: Deploy to production

How to deploy your Ruby code to production in minutes

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

Stackhero's Ruby cloud hosting service offers a powerful and user-friendly way to deploy your Ruby projects to production in just a few minutes.

Key features include:

  • Deployment with a simple git push.
  • Customizable domain with automatic management of TLS certificates (HTTPS).
  • Running on a dedicated, private VM for maximum security and confidentiality.
  • Support for HTTP/2, TLS 1.3 (HTTPS), WebSockets, GZIP & Brotli compression, ETag, TCP and UDP port access, and more.

To deploy your projects on Stackhero, the only requirement is to have Git installed on your computer.

To save time and avoid complex configuration, especially if your development environment is not ready, consider using Stackhero's Code-Hero.

Code-Hero is a powerful, user-friendly, and ready-to-use development platform accessible directly through your browser on any computer, tablet, or phone. It is based on a VSCode fork and includes all the essential tools for development, pre-installed and pre-configured, allowing you to start coding instantly without any hassle.

<!-- ![Example of a Code-Hero instance running directly on the browser](/images/docs/ruby/040_deploy/rubyInCodeHero.png) -->

Deploying your Ruby application to Stackhero is straightforward. You can follow these steps, each of which is detailed further in this guide:

  1. Create a Ruby service on Stackhero.
  2. Add your SSH public key to your Ruby service configuration.
  3. Configure the git push command on your development platform.
  4. Add a Makefile to your project.
  5. Deploy your code to production.

If you encounter any issues during deployment, the "Troubleshooting" documentation is likely to provide a solution. Make sure to consult this guide as it can save you time and prevent unnecessary frustration.

If you have not started a Stackhero for Ruby service yet, you can create one in your Stackhero dashboard. It takes just 2 minutes.

Once your Ruby service has started, you need to configure it by adding your SSH public key. You can locate your public key by running the command:

cat ~/.ssh/id_*.pub

Do not have SSH keys yet?

You can create them using:

ssh-keygen -t ed25519

To configure your Ruby service, navigate to the Stackhero dashboard, select your Ruby service, click the "Configure" button, and paste the content of your public key into the "SSH public keys" section.

<!-- ![Example of a Ruby service configuration](/images/docs/ruby/040_deploy/rubyStackheroPublicKey.png) -->

Tip: You can set your SSH public key globally so that future services automatically include it in their configuration.

To do this, navigate to the Stackhero dashboard, click on your profile picture in the top right corner, select "Your profile", and add your SSH public key.

Deploying to Stackhero is done using the Git CLI with the git push command. This approach makes deployments simple, fast, and reliable without requiring any extra tools on your computer.

To enable this feature, copy and paste the value of the git remote command from the main page of your service in the Stackhero dashboard. The command typically looks like this:

git remote add stackhero ssh://stackhero@<XXXXXX>.stackhero-network.com:222/project.git
<!-- ![Ruby Git remote command on Stackhero's dashboard](/images/docs/ruby/040_deploy/rubyStackheroGitRemote.png) -->

To deploy your code on Stackhero, you need to specify the commands for your application by creating a Makefile. This file acts as the bridge between Stackhero and your application.

If you are unfamiliar with Makefiles and the make command, do not worry. The instructions below will guide you through the process.

Create a Makefile at the root of your project and add the following content:

run:
	rake assets:precompile
	rake db:migrate RAILS_ENV=production
	RAILS_ENV=production bundle exec puma -C config/puma.rb

This Makefile contains three important components:

  1. The run rule, which is mandatory as it is automatically executed by Stackhero. Do not rename it because it serves as the entry point for your deployment.
  2. The commands executed using rake and bundle. You can replace them with the appropriate commands for your application if necessary.
  3. Each command must be prefixed with a tab character rather than spaces. If you see an error like "*** missing separator", verify that a tab character is used.

In this example, three commands are executed during deployment:

  1. Assets such as JavaScript and CSS are precompiled into the public/assets directory.
  2. Database migrations are run if needed.
  3. A Puma server starts to serve your application.

You are now ready to deploy your Ruby application! To deploy your code on Stackhero, run the following command:

git push stackhero main

The first time you run this command, you will be prompted to add the SSH key fingerprint. Respond with "yes" to continue.

After a few seconds, your application will be live.

<!-- ![Example of deploying Ruby code to Stackhero using the `git push` command](/images/docs/ruby/040_deploy/rubyDeployGitPush.png) -->

To check your deployed application, navigate to the website URL provided on the Stackhero dashboard. It typically looks like https://XXXXX.stackhero-network.com.

Congratulations, your application is now deployed in production!

Encountering issues during deployment?

Check out the Troubleshooting section, where you will likely find a solution!

This guide has provided a comprehensive and straightforward overview of how to deploy Ruby code to production using Stackhero. It lays a solid foundation for managing your application deployments effectively.

To expand your knowledge, consider exploring the "Advanced Deployment Usages" documentation. Here you will learn how to deploy various git branches, specific tags or commits, and manage multiple environments such as staging and production. You will also discover tips on working with environment variables and more.

If you face any problem during the deployment process, the "Troubleshooting" documentation is an invaluable resource that can help you resolve issues efficiently and minimize frustration.