# Deploy a Ruby on Rails App on Clouddley

In this guide, you'll learn how to deploy a[ Ruby on Rails](https://rubyonrails.org/) Application on Clouddley, a backend infrastructure for your compute resources that is an advanced runtime auto-detection platform for zero-downtime deployments across different server types. Let's begin!

### Prerequisites

* A [GitHub](https://github.com/) or [Bitbucket](https://bitbucket.org/product) account.
* A [Clouddley](https://clouddley.com/) account.
* A [Ruby on Rails](https://rubyonrails.org/) application.
* A virtual machine on a Cloud platform or bare metal server.

### Deploy your Ruby on Rails Application

#### **Create a Dockerfile**

Before deploying your Ruby app on Clouddley, create a Dockerfile   `triggr.dockerfile`  which defines how the Ruby app should be containerized.

{% hint style="info" %}
**Best Practice:** When creating a Dockerfile, use a lightweight base image to reduce image size. Always specify exact versions for dependencies to ensure consistency.
{% endhint %}

{% code title="triggr.dockerfile" %}

```docker
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"]

```

{% endcode %}

**Building and Running the Container Locally**

Before deploying to **Apps**, verify that the container works locally.

1. **Build the Docker image**:

   ```
   docker build -t ruby-app -f triggr.dockerfile .
   ```
2. **Run the container**:

   ```
   docker run -d -p 3000:3000 --name ruby-container ruby-app
   ```
3. **Verify the app is running** by visiting `http://localhost:3000`

#### **Accessing Apps on Clouddley**

* Open your browser and log in to your Clouddley account
* Navigate to [Apps](https://app.clouddley.com/apps) and click on **Deploy App**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2FZ9UIaou7OsXgWrGxdGrz%2FApps-dashboard.png?alt=media&#x26;token=2879b599-28d6-4dce-ab03-022be8451432" alt="Image of Triggr Apps dashboard."><figcaption><p>Accessing Apps on Clouddley</p></figcaption></figure>

#### **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**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2FbcWQIDhWUOzWq5rdL6Tj%2FApps-configure-service.png?alt=media&#x26;token=af423ea1-36de-4614-8838-63b283e0768a" alt="Configuring Git hosting service during app deployment on Apps."><figcaption><p>Choose your Git hosting service</p></figcaption></figure>

#### **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**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2F3nnIjU5S70RcO9YhTcnj%2FApps-configure-git.png?alt=media&#x26;token=a42cb06e-0b64-480c-8ead-8e0315673f87" alt="Configuring the Git repository during app deployment on Apps."><figcaption><p>Setup the Ruby on Rails application repository on Clouddley</p></figcaption></figure>

#### **Step 3: Configure your Virtual Machine**

In the Choose or add server dropdown, select your virtual machine (VM) if it’s already listed. If not, select **+ Add Virtual Machine**.

Enter the following details to configure your VM:

* Hostname or IP address
* Username
* SSH port

After adding the details, use the **Clouddley CLI** (recommended) or connect via **SSH** to verify the connection.

{% tabs %}
{% tab title="Clouddley CLI" %}
The Clouddley CLI is a command-line tool that allows you to interact with the Clouddley Platform from your terminal.&#x20;

* Open the command line of the remote VM you want to configure to Clouddley and install Clouddley CLI by running the command:

```bash
curl -L https://raw.githubusercontent.com/clouddley/cli/main/install.sh | sh
```

* To add the SSH public key, run the command:

```bash
clouddley add key
```

Using the CLI, you can deploy resources, manage configurations, and automate tasks efficiently.
{% endtab %}

{% tab title="SSH" %}

* Download the public key to your local machine.
* Run the provided command on your local machine, allowing Clouddley to connect to your virtual machine.

```
ssh-copy-id -f -i ~/path/to/downloaded/Publickey username@ipaddress
```

{% hint style="info" %}
Replace `~/path/to/downloaded/Publickey` ,`username` and `ipaddress`  with your actual values.
{% endhint %}
{% endtab %}
{% endtabs %}

* Click on **Verify**. This verifies the connection.
* Click on **Next**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2FXBv3Sr2YqW1wPzRP9db9%2FApps-configure-VM.png?alt=media&#x26;token=52a58031-ed82-49c2-bf3e-5a117d201687" alt="Configuring the virtual machine during app deployment on Clouddley"><figcaption><p>Configuration of virtual machine on Clouddley</p></figcaption></figure>

#### **Step 4: Configure app settings**

* Insert the **name** of the application and its **port.**
* Click on **Next**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2FW7X3a5YhWYw00JDgei3B%2FApps-ruby-name.png?alt=media&#x26;token=5a6e126e-6e18-473f-a497-3b537217564d" alt="Configuring App settings (name and port) during app deployment on Clouddley"><figcaption><p>Configure the App name and port</p></figcaption></figure>

{% hint style="info" %}
The firewall of the virtual machine should allow access to the application port.
{% endhint %}

#### **Step 5: Configure Environment Variables**&#x20;

* To add environment variables, click on  :heavy\_plus\_sign: <mark style="color:blue;">**Add Variable**</mark>&#x20;
* Choose an ENV mode: either a **single variable** or **import variables**. Learn more [here](https://docs.clouddley.com/apps/extras/environment-variables).

{% tabs %}
{% tab title="Single Variable" %}

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2FltsodwqaWm7fIvzp3V0H%2FTA-singleVar.png?alt=media&#x26;token=341b06bb-cb42-4ef4-a4bd-5a03ba8ea503" alt="Image showing the single variable ENV mode on Clouddley" width="563"><figcaption><p>Single variable ENV mode</p></figcaption></figure>
{% endtab %}

{% tab title="Import Variables" %}

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2F47GAv9MeC0vjtNZfvXSG%2FTA-importVar.png?alt=media&#x26;token=2e757a76-177e-40ae-b6d5-212b26ee0544" alt="Image showing the Import Variables ENV mode on Clouddley." width="563"><figcaption><p>Import variables ENV mode</p></figcaption></figure>
{% endtab %}
{% endtabs %}

* Add the key-value pairs and click on **Save**
* Click on **Next**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2Fqhc9eRHrkURH1mFYaHGg%2FApps-ruby-env.png?alt=media&#x26;token=718fb3e5-1a4c-4aa4-9031-16c6f821d659" alt="Image showing environment variables added during app deployment on Clouddley."><figcaption><p>Adding environment variables</p></figcaption></figure>

#### **Step 6: Set up Notifications (optional)**

* To configure the **notification settings** of the application, click on :heavy\_plus\_sign: <mark style="color:blue;">**Add Alert**</mark>
* 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**

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2F6N1TWzXEGkaj4vLbtX03%2FApps-notif.gif?alt=media&#x26;token=f5ba3c3e-c8cf-43bd-8071-97c10ca466d9" alt="A gif showing how to set up notifications on Clouddley."><figcaption><p>Notifications set up and creation of Ruby on Rails application on Clouddley</p></figcaption></figure>

#### **Step 7: Test and Verify the app**

* Click on **Go to Dashboard. Y**our app will be visible on the apps dashboard.
* After the app deployment is complete, the app status changes from `Deploying` to `Online`

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2F25zphQI3UuTopKpqj4CV%2FApps-ruby-dashboard.png?alt=media&#x26;token=20fa5813-9122-4cce-9754-b44cca4e7d3f" alt="An image of the overview of a successfully deployed Ruby on Rails application on Clouddley."><figcaption><p>Ruby on Rails application dashboard overview</p></figcaption></figure>

* Click on :globe\_with\_meridians: **Website** at the top right corner of the page, which opens the URL of the deployed application in your browser.
* You can test the application functionalities.

<figure><img src="https://3695617198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1yp2SdNQtlQTJArGRUVU%2Fuploads%2Fh2YEzkwMdMAdM3U7A1PQ%2FApps-ruby.png?alt=media&#x26;token=4db074c1-993a-480f-b337-e597a82e0286" alt="An image of the Ruby on Rails application running on Clouddley on the web."><figcaption><p>Ruby on Rails application running from Clouddley on a cloud virtual machine</p></figcaption></figure>

You have deployed a Ruby on Rails application successfully on Clouddley. You can manage it directly from the app dashboard by clicking the three dots (**...**) at the top-right corner to access **Edit**, **Instant Rollback**, **Scale**, **Pause**, and **Delete** options.

Additionally, you can switch to different tabs on the application dashboard to perform the following actions: view your **deployment** history, view or download **logs**, add a **custom domain**, and view the **environment variables**.

### **Conclusion**

You've successfully deployed a Ruby on Rails application on Clouddley! To access the source code of this application, check [here](https://github.com/clouddley/examples/tree/main/ruby-on-rails). Furthermore, to explore how different frameworks can be deployed on Clouddley, check out our [how-to guides](https://docs.clouddley.com/apps/how-to-guides).
