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 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 will get:

  • Deploy your code with a simple git push.
  • Use your own custom domain, with automatic TLS certificate (HTTPS) management.
  • Run your application on a dedicated, private VM for top-level security and privacy.
  • Take advantage of support for HTTP/2, TLS 1.3 (HTTPS), WebSockets, GZIP and Brotli compression, ETag, TCP and UDP port access, and more.

The only thing you need to get started deploying your projects on Stackhero is Git installed on your computer.

If you are looking to save time or prefer to avoid setting up a complex local environment, you might want to check out Stackhero's Code-Hero.

Code-Hero is a ready-to-use development platform you can access right from your browser, on any computer, tablet, or phone. Built 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 hassles.

<!-- ![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 a simple process. Here are the steps you will follow, and we will walk through each in detail:

  1. Create a Ruby service on Stackhero.
  2. Add your SSH public key to your Ruby service configuration.
  3. Set up 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 can help you find a solution quickly. It is always a good idea to check there first to save time and minimize frustration.

If you have not created a Stackhero for Ruby service yet, you can do so from your Stackhero dashboard in just a couple of 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

Do not 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.

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

Tip: Want to save time in the future? You can add your SSH public key to your profile so any new services you create will include it by default.

Just click your profile picture in the top right corner of the dashboard, select "Your profile", and add your SSH public key there.

Deploying to Stackhero uses the Git CLI and the git push command, so you do not 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:

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 let Stackhero know 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.

If you are new to Makefiles or the make command, do not worry, the steps below will walk 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 is what is happening in this Makefile:

  1. The run rule is required, Stackhero will automatically execute it during deployment. Please keep this name as it acts as the entry point.
  2. The commands use rake and bundle, but you can customize them as needed for your application.
  3. Make sure each command line starts with a tab character, not spaces. If you see an error like *** missing separator, double-check this formatting.

In the example above, deployment will:

  1. Precompile assets like JavaScript and CSS into the public/assets directory.
  2. Run any needed database migrations.
  3. Start the Puma server to serve your application.

You are ready to go. To deploy your code to Stackhero, you can use:

git push stackhero main

The first time you run this, you will be asked to confirm the SSH key fingerprint. Just answer "yes" to continue.

After a short wait, your application will be live.

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

You can visit your deployed application at the website 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.

You have just learned how to deploy Ruby code to production using Stackhero, with a process that is both simple and powerful.

If you would like to learn even more, the Advanced Deployment Usages documentation covers topics like deploying different git branches, specific tags or commits, and managing multiple environments such as staging and production. You will also find tips for working with environment variables and more.

And remember, if any issues come up during deployment, the Troubleshooting documentation is a great resource to help you resolve them efficiently and keep your workflow smooth.