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.

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.

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

Deploying your Ruby application to Stackhero is straightforward. Here’s the workflow, with each step detailed below:

  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 helps you quickly find solutions and keep moving forward.

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.

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

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.

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
<!-- ![Ruby Git remote command on Stackhero's dashboard](/images/docs/ruby/040_deploy/rubyStackheroGitRemote.png) -->

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 make command, 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:

  1. The run rule is required. Stackhero looks for this rule as the entry point during deployment. Keep this rule name.
  2. The example uses rake and bundle, but you can adjust these commands to fit your application.
  3. Each command line must start with a tab character, not spaces. If you see a *** missing separator error, check for tabs.

In the example above, deployment will:

  1. Precompile assets such as JavaScript and CSS into the public/assets directory.
  2. Run database migrations.
  3. Start the Puma server to serve your 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.

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

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.

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.