Ruby: Deploy to production

Deploy Ruby code to production in minutes with Stackhero

👋 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, dedicated infrastructure.

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 take your Ruby projects live in just a few minutes. You get a robust platform designed to streamline deployment and let you focus on your application, not infrastructure.

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 strong 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 more.

All you need to get started is Git installed on your computer.

If you want to save time or prefer to avoid configuring a local environment, you might want to explore Stackhero's Code-Hero.

Code-Hero is a browser-based development environment that works on any device. Built on a VSCode fork, it comes with key tools pre-installed and pre-configured, so you can begin coding right away with zero setup.

<!-- ![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. Here is the workflow, and each step is explained 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 run into any issues during deployment, the Troubleshooting documentation is a quick way to find solutions and keep things moving.

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 display your public key by running:

cat ~/.ssh/id_*.pub

Do not 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 later, you can add your SSH public key to your Stackhero profile. New services you create will include it automatically.

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

Deploying to Stackhero uses the Git CLI and the git push command, so there is no need for 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 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 are 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 are ready to deploy. You can use:

git push stackhero main

During the first deployment, Git will ask you to confirm the SSH key fingerprint. Enter "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) -->

Visit your deployed application at the website URL shown in your Stackhero dashboard. The address will look like https://<XXXXXX>.stackhero-network.com.

Your application is now live in production.

If you run into any trouble during deployment, the Troubleshooting section covers common issues and solutions.

You have seen how to deploy Ruby code to production using Stackhero, with a process designed to be both powerful and simple.

For advanced topics, such as deploying different Git branches, tags, or commits, and managing multiple environments like staging and production, see the Advanced Deployment Usages documentation. You will also find tips for working with environment variables and other useful features.

If any questions or issues come up, the Troubleshooting documentation is always available to help you keep your deployment workflow smooth and efficient.