# Deploying DocuSeal on Google Cloud Run

Before you start, make sure you have an active Google Cloud account. If you don’t have one yet, you can sign up on the [Google Cloud website](https://cloud.google.com/). Although DocuSeal is open-source, you will incur expenses for utilizing Google Cloud services, such as PostgreSQL databases, compute instances, and storage. The overall cost will depend on your specific requirements. However, DocuSeal is optimized to run efficiently on smaller instances, so you can choose the most affordable server option from Google Cloud.

## How to deploy DocuSeal on Google Cloud Run?

### Create a new project on Google Cloud Platform

Before you begin, you need to create a new project on the Google Cloud platform. To do this, go to the [Google Cloud website](https://cloud.google.com/) and sign in to your account. To create a new project, click on the **Console** button in the upper right corner of the screen and select **New Project**.

1. On the **New Project** page, enter the name of your project. You can choose any name, but it must be unique.
2. If the project should be part of an organization, select the appropriate organization in the **Organization** dropdown.
3. Click on the **Create** button to create a new project.

### Create a PostgreSQL server

After creating the resource group, you need to set up a PostgreSQL server. This will serve as the database used by DocuSeal.

1. Navigate to **SQL** in the **Databases** menu on the Google Cloud toolbar or use the search function.
2. Click on the **Create Instance** button to create a new PostgreSQL server.
3. Select PostgreSQL as the database type.
4. On the page that opens, enter the instance name and the password for the database administrator. Do not use the symbols **!, ‘, or “** in the password, as they may cause the application to malfunction.
5. Select the version of PostgreSQL. It is recommended to choose the latest available version for better performance and security features.
6. Next, choose the Cloud SQL edition. We recommend selecting the cheaper option (e.g., Enterprise) as DocuSeal operates efficiently on smaller servers.
7. Select a region for the server location. We recommend choosing a region closest to your users’ location.
8. Go to the **Storage** tab and select the disk size for the database. We recommend using a small server to save costs but enabling automatic disk space increase.
9. Go to the **Connections** tab and select **Public IP** for internet access to the database.
10. Click on the **Add a network** button and enter the following value for **Network**:

    ```
    0.0.0.0/0
    ```

    Note: If your organization’s security policy does not allow internet access to the database, skip this step. In this case, you will need to enter the IP address of your server (which you will create later) or network in this field.
11. If needed, select additional options for the database and click on the **Create Instance** button to create the PostgreSQL server.
12. Now you need to create a database for DocuSeal. Open the page of the instance you created and go to the **Databases** tab.
13. On the opened page, click on the **Create database** button and enter the desired name for the database.
14. Now you need to create the database connection string. To do this, go to the **Overview** tab and copy the value of **Public IP address**.
15. Next, you need to create the database connection string. Use the value of **Public IP address** which can be found on the **Connections** or **Overview** page of the PostgreSQL instance.
16. Form the database connection string in the format:

    ```
    postgresql://postgres:password@ip:5432/database
    ```

    As a result, you will obtain a URL that looks something like this:

    ```
    postgresql://postgres:123456789@35.193.16.230:5432/docuseal_production
    ```

      - **postgres** - this is the database username (default is **postgres** ). You can create another user on the **Users** page of the PostgreSQL instance.
      - **password** - this is the database user’s password that you specified when creating the PostgreSQL server.
      - **ip** - this is the IP address of the PostgreSQL server which you found on the **Connections** or **Overview** page.
      - **database** - this is the name of the database you created for DocuSeal.
17. Save the formed database connection string, as you will need it later.

### Create a Cloud Run Service

1. Navigate to **Cloud Run** on the Google Cloud toolbar or use the search function.
2. Click on the **Create Service** button to create a new Cloud Run service.
3. Select **Deploy one revision from an existing container image**.
4. Enter the Container image URL:

   ```
   docker.io/docuseal/docuseal:latest
   ```

   You can use any version of the image, but it is recommended to use the latest one.  
   _To deploy the Pro Docker image, it is required to use a [Remote Repository](https://cloud.google.com/artifact-registry/docs/repositories/remote-repo)._
5. Enter the service name. It can be any name, but it must be unique.
6. Select a region for the service location. We recommend choosing a region closest to your users’ location.
7. Select **Allow unauthenticated invocations** for Authentication to allow access to the service without authorization.
8. After this, select **All** for Ingress control to allow access to the service from the internet.
9. Now you need to configure the port and environment variables for the service. To do this, go to **Container(s), Volumes, Networking, Security** and select the **Container(s)** tab.
10. In the opened tab, enter 3000 for **Container port**. This is the port on which DocuSeal operates.
11. Go to the **Variables & Secrets** tab. You need to set up two environment variables - **DATABASE_URL** and **SECRET_KEY_BASE**.
12. First, let’s generate **SECRET_KEY_BASE**. Open the console and enter the following command:

    ```
    openssl rand -hex 64
    ```

    Copy the generated key and paste it into the **SECRET_KEY_BASE** environment variable. Note that you can use any other method to generate the key.
13. Next, paste the database connection string you generated earlier into the **DATABASE_URL** environment variable.
14. Click on the **Create** button to create the Cloud Run service.

### Create file storage

DocuSeal offers several methods for file storage, but since Google Cloud has its own file storage service, you can utilize it. Here’s how to set it up:

1. Navigate to the **Cloud Storage** section on the Google Cloud Platform dashboard or use the search bar.
2. Click on the **Create Bucket** button to create a new storage bucket.
3. Enter the name of the bucket. You can choose any name, but it must be unique.
4. If needed, select a region for file storage. We recommend choosing a region closest to your users’ location.
5. Click on the **Create** button to create a new bucket.
6. Now you need to configure access to the bucket. To do this, go to **APIs & Services** and select **Credentials**.
7. Click on the **Create credentials** button and select the required service account. If it does not exist, create a new service account.
8. On the service account page, go to the **Keys** tab and click on the **Add Key** button to create a new access key.
9. In the window that appears, select **JSON** as the key format and click on the **Create** button to create a new access key.
10. After this, a file with the access key will be downloaded. Save it, as you will need it later.

### Set up access to storage

1. Log in to DocuSeal as an administrator.
2. Navigate to the **Settings** - **Storage** page.
3. Select **GCP** under the **Storage** section.
4. Enter the project id, bucket name, and credentials that you previously created. 
     - Project ID - the ID of the project you created on Google Cloud Platform.
     - Bucket name - the name of the bucket you created on Google Cloud Storage.
     - Credentials - the secret key you generated for the bucket.
5. Click the **Save** button.
6. Done! DocuSeal can now store files in the Google Cloud storage.

In this guide, we explored how to deploy DocuSeal on Google Cloud Run, but it’s important to remember that this is just one of the deployment options available. Your company might use other methods to organize resources and access them.