Skip to main content
Deploying a Ruby on Rails app on a virtual machine can seem tricky, especially if you’re new to deployment. Clouddley simplifies the process by handling deployment and connects smoothly with DigitalOcean for you. This tutorial walks you through deploying your Rails app to a DigitalOcean Droplet with ease.

Prerequisites

Before we get started, make sure you have the following:

Create a Ruby on Rails Application

Before deploying your application, it’s important to make sure it runs smoothly on your local machine. Here’s how to create and test a Ruby on Rails application step by step.
1

Generate a new Rails application

In your terminal, run:
rails new app 
This command creates a new Rails project in a folder named app, complete with the default directory structure, configuration files, and a basic setup.
2

Navigate into your application directory

cd app
This is where all your Rails files and configuration live.
3

Start the Rails Development Server

To run the app locally, start the development server:
bin/rails server
By default, this launches the server on http://localhost:3000.
4

Open the App on Your Browser

Now that the server is running, open your browser and go to: http://localhost:3000 You should see the default Rails welcome page, which means your app is running correctly!

Containerize Your Rails App

Create a Dockerfile

To deploy your Rails app on Clouddley, you need to containerize it using Docker. This involves creating a Dockerfile named triggr.dockerfile that defines how your application will run in a container. Here’s a simple triggr.dockerfile for your Ruby on Rails app:
FROM ruby:3.4.4-alpine

# Install only the essentials for your gems
RUN apk add --no-cache \
    build-base \
    yaml-dev \
    nodejs \
    yarn \
    tzdata \
    git

# Set working directory
WORKDIR /app

# Copy Gemfile and Gemfile.lock first (for caching)
COPY Gemfile Gemfile.lock ./

# Install gems
RUN bundle install

# Copy the rest of the application
COPY . .

EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

Building and Running the Container Locally

Here’s how to test your container locally:
  1. Build the Docker Image:
    docker build -f triggr.dockerfile -t my-rails-app .
    
    This command builds a Docker image named my-rails-app using the triggr.dockerfile
  2. Run the Docker Container:
     docker run -p 3000:3000 my-rails-app
    
    This command runs the container, mapping port 3000 of the container to port 3000 on your local machine. You can now access your Rails app at http://localhost:3000.

Push Your App to GitHub

Once your Rails app is working locally, the next step is to track it with Git and push it to a remote repository like GitHub or BitBucket. This not only helps with version control, but it’s also essential for deploying on Clouddley. For this tutorial, we’ll be using GitHub. Let’s walk through the steps:
1

Create a New Repository on GitHub

Go to GitHub and create a new repository. Give it a name and leave the rest of the settings as default (no README, no .gitignore, you already have those locally).
2

Initialize Git

If you haven’t already, initialize a Git repository in your project folder:
git init
3

Add and Commit Your Code

Add your files and commit:
git add .
git commit -m "Initial commit"
4

Create branch and add Remote Repository

Create a branch and link your local repository to the GitHub repository you created:
git branch -M main
git remote add origin <your-repo-url>
5

Push code

Finally, push your code to GitHub:
git push -u origin main
Now your code is pushed to GitHub, it is ready for deployment.

Launch a DigitalOcean Droplet

We’ll create a Droplet from the command line using the doctl CLI. Before you begin, ensure you have your DigitalOcean API token ready.
  • Authenticate with your DigitalOcean account, run the following command in your terminal:
doctl auth init
  • Enter your API token when prompted. This will allow doctl to interact with your DigitalOcean account.
  • Before creating your Droplet, make sure you have your vpc_uuid and SSH key added to your DigitalOcean account.
Open your terminal and run the command:
doctl compute vpc list
This will display all your VPCs along with their UUIDs. Choose the one you want to use for your Droplet.
Open your terminal and run the command:
doctl compute ssh-key list
If you do not have a previously created one, follow the steps below.Step 1: To generate an SSH key, run the command:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Press Enter to accept the default file location and choose a passphrase if you want one.Step 2: To add your SSH key to digitalocean, run:
doctl compute ssh-key create "my-key-name" --public-key-file ~/.ssh/id_rsa.pub
Replace my-key-name with a name you’ll recognize.
  • Create a Droplet using the following command:
doctl compute droplet create app-droplet \
  --image ubuntu-24-10-x64 \
  --size s-1vcpu-1gb \
  --ssh-keys your_ssh_key_id \
  --region nyc1 \
  --vpc-uuid your_vpc_uuid
Make sure you replace your_vpc_uuid and your_ssh_key_id with your actual values. The SSH key added here allows Clouddley to securely connect to your Droplet during deployments. It uses this key to access the VM, run deployment scripts, and manage your app.
You will see the output below: Creating a droplet in DigitalOcean You’ve created a droplet named app-droplet with Ubuntu24.10 x64 image in the nyc1 region.
  • To verify the Droplet was created successfully, you can run:
doctl compute droplet list
This will show you all your active Droplets, their names, IPs, and statuses. Listing all droplets in DigitalOcean Note its public IP address for SSH access.

Deploy

Now you have your Ruby on Rails app and Droplet ready, it’s time to deploy your app.
  • Open your browser and log in to your Clouddley account
  • Navigate to Apps and click on Deploy App

Accessing Apps


Step 1: Configure Service
  • Choose your Git hosting service; either GitHub or Bitbucket. For this tutorial, we will be using GitHub.
  • Click on Continue with GitHub

Choose your Git hosting service


Step 2: Configure Git
  • To connect your GitHub user or organization account, click the Select username/organization dropdown and Add GitHub account.
  • Select your repository and the branch from the dropdown list or quickly search.
  • Click on Next

Setup the Ruby on Rails application repository on Clouddley


Step 3: Configure your Virtual Machine
  • From the Choose or add server dropdown, select your VM if it appears in the list. If not, click + Add Virtual Machine.
  • To add your VM, enter your droplet’s IP address as VM host, VM user, and the VM port for SSH access.
  • Once you’ve entered the details, verify the connection using the Clouddley CLI(recommended) or SSH.
  • Open your local machine’s command line, then connect to the remote VM you want to configure with Clouddley. Use this command to SSH into your DigitalOcean Droplet:
ssh root@<your-droplet-ip>
  • Install Clouddley CLI by running the command:
curl -L https://raw.githubusercontent.com/clouddley/cli/main/install.sh | sh
  • To add the SSH public key, run the command:
clouddley add key
Using the CLI, you can deploy resources, manage configurations, and automate tasks efficiently.
  • Click on Verify. This verifies the connection.
  • Click on Next

Configure virtual machine on Clouddley


Step 4: Configure app settings
  • Insert the name of the application and its port.
  • Click on Next.

Configure the App name and port


The firewall of the virtual machine should allow access to the application port.
Step 5: Configure Environment Variables
  • To add environment variables, click on Add Variable
  • Choose an ENV mode: either a single variable or import variables. Learn more here.
Single Variable ENV mode
  • Add the key-value pairs and click on Save
  • Click on Next

Adding environment variables


Step 6: Setup Notifications (optional)
  • To configure the notifications settings of the application, click on Add Alert
  • Select the Alert type. For this tutorial, we will set up Email Alerts.
  • Toggle on the buttons of the deployment event (failed, timed out, or success) you want to be notified of.
  • Enter the Email address where you want to receive alerts. (You can add multiple email addresses)
  • Click on Save
  • Click on Deploy

Notifications set up and creation of Ruby on Rails application on Clouddley


Step 7: Test and Verify the app
  • Click on Go to Dashboard. Your app will be visible on the apps dashboard.
  • After the app deployment is complete, the app status changes from Deploying to Online

Ruby on Rails application dashboard overview


  • Click on 🌐 Website at the top right corner of the page, this opens the URL of the deployed application in your browser.
  • You can test the application’s functionalities.

Ruby on Rails application running from Clouddley on a DigitalOcean Droplet


Post-Deployment: Managing Your Ruby on Rails App

Once your Ruby on Rails app is up and running on a DigitalOcean Droplet using Clouddley, management is simple.
The apps dashboard lets you handle key tasks without touching the server. You can adjust the settings, scale your app, roll back to earlier versions, pause or resume the app, or remove the app if needed. You’ll also find helpful features to view your deployment history, check logs, manage environment variables, and connect a custom domain, all in one place.
Want to keep your Rails app clean, fast, and easy to maintain? Here are a few tried-and-true best practices to follow: Follow Rails conventions
Stick to the framework’s naming and folder structure—it makes your code easier to understand and maintain.
Keep things modular
Use services or concerns to break out logic and avoid bloated models or controllers.
Secure your config
Store sensitive data like API keys and secrets in environment variables or use Rails credentials.
Write clear commit messages
Good commit messages help track changes and make debugging easier down the road.
Test your code
Add basic tests with RSpec or Minitest to catch bugs early and make updates with confidence.
Watch performance
Use eager loading, caching, and proper indexing to keep your app running smoothly in production.
Stay current
Keep Rails and your gems up to date to benefit from security patches and performance improvements.

Conclusion

That’s it! You’ve now seen how easy it is to deploy your Ruby application on a DigitalOcean droplet using Clouddley. We built Clouddley to make deployments on your favorite cloud platform simpler so you can focus on building great products. If you’ve got feedback or ideas to make Clouddley even better, let us know here. We’re excited to see the cool things you’ll deploy with it!

Getting started with Clouddley?

A backend infrastructure for your own compute. Run apps, databases, brokers, and AI workloads on your VMs, bare metal, or VPS.

Additional Resources

Here are some helpful links to keep learning and refining your deployment setup: