# Deploy a Go Application on Clouddley

This article will walk you through the process of deploying a [Go](https://go.dev/doc/) application to a server using Clouddley,  a backend infrastructure platform for your compute resources that auto-detects your runtime and deploys your application to your server (virtual machines and bare metal). Let’s dive in!

### Prerequisites

* A [GitHub](https://github.com/) or [Bitbucket](https://bitbucket.org/product) Account.
* A [Clouddley](https://app.clouddley.com/auth/signup) account.
* A [Go](https://go.dev/doc/) application.
* A virtual machine on a Cloud platform or bare metal server.

### Deploy your Go Application&#x20;

**Optimize your codebase for deployment**

Based on Clouddley's design, deploying a Go application differs for API and full-stack development. We will be showing these two use cases below.

{% tabs %}
{% tab title="Go Full-Stack" %}
To deploy a full-stack Go application on Clouddley, you need to create a [Toml](https://docs.fileformat.com/programming/toml/#what-is-a-toml-file) file `project.toml` in the root directory of your project.

{% code title="project.toml" %}

```toml
[[build.env]]
name="BP_KEEP_FILES"
value="static/*"
```

{% endcode %}

The `value` should specify the folder containing all the files without the `.go` extension for Clouddley to include them during the build process. For this application, the files can be found in a folder named `static`

You can check out the code for this application [here](https://github.com/clouddley/examples/tree/main/go/go-fullstack).
{% endtab %}

{% tab title="Go API" %}
For this use case, we deployed a simple Go API

You can check out the code for this application[ here](https://github.com/clouddley/examples/tree/main/go/go-api).
{% endtab %}
{% endtabs %}

#### **Accessing Apps**

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

<figure><img src="/files/7hiMQsGBbJLWH1hAlqJu" alt="Image of Apps dashboard on Clouddley."><figcaption><p>Accessing Apps</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="/files/wGRJv4utI9yHwvgWvVAW" alt="Configuring Git hosting service during app deployment on Clouddley."><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="/files/faCh2Fru8KlKWXlPPYOT" alt="Configuring the Git repository during app deployment on Clouddley."><figcaption><p>Setup the Go 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.

* 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.
* Ru**n** the provided command on your local machine, allowing Triggr 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="/files/qtcRfmLeUDV5fe8r7nQk" 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="/files/JH0L3vhUFNpOTCFwkCnk" 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](/apps/extras/environment-variables.md).

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

<figure><img src="/files/g4PjEAekY8aojSeKi1XF" 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="/files/60lrDpuC46Uwr2tcIvfH" 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="/files/ZuYu4yCm8h6NDFWIoKvs" 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="/files/ItAmC6aXlBntUjIxE82E" alt="A gif showing how to set up notifications on Clouddley."><figcaption><p>Notifications set up and creation of Go application on Clouddley</p></figcaption></figure>

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

* Click on **Go to Dashboard.** Your app appears on the apps dashboard.
* After the app deployment is complete, the app status changes from `Deploying` to `Online`

<figure><img src="/files/QtTVLZBq7LSmmgcQvOSg" alt="An image of the overview of a successfully deployed Go application on Clouddley."><figcaption><p>Go 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="/files/9C2vyvr0v3aIWRFQUqSn" alt="An image of the Go application running from Clouddley on the web."><figcaption><p>Go application running from Clouddley on a cloud virtual machine</p></figcaption></figure>

You have successfully deployed a Go application 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

Congratulations:tada: on successfully deploying a Go application on Clouddley. Check out how different frameworks can be deployed to Clouddley in our [how-to guides](/apps/how-to-guides.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clouddley.com/apps/how-to-guides/deploy-a-go-application-on-clouddley.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
