# Install on Google Cloud Platform (GCP)

This tutorial deploys Squidex as a container on [Cloud Run](https://cloud.google.com/run/), which is a managed compute platform that lets you run containerized applications.

The tutorial does not cover the basics of GCP. You should be familiar with them before you begin with the installation instructions. This tutorial uses the following services from GCP:

* [Google Cloud Storage](https://cloud.google.com/storage)
* [Google Cloud Run](https://cloud.google.com/run/)
* [MongoDB Atlas](https://www.mongodb.com/cloud/atlas/mongodb-google-cloud) running on Google Cloud

This tutorial used MongoDB Atlas on Cloud running in shared (free) mode and is recommended for non-production, trial or sandboxed environments as it has limited resources and basic configuration. For production environments, it is best to go for one of the Pay-as-you-go models such as Dedicated. You can also deploy your own cluster.

Use this tutorial as a getting started guide in GCP to explore Squidex or use it as a Dev/Sandbox environment. This setup may not be recommended for a production environment as it does meet requirements such as scalability and high-availability.

## Prerequisites

Before you begin, ensure you meet the following requirements:

1. An active Google Cloud account.
2. A *Project* in GCP

## Deployment Specifications & Other Details

Over the course of this installation you will create the following resources:

* A Cloud Storage bucket
* A Cloud Run instance
* A free MongoDB Atlas cluster at <https://cloud.mongodb.com/>

**Important Details**

* Default resource allocations
  * Squidex instance: **1 vCPU and 1.5 GiB memory**

## 1. Create a MongoDB Atlas Cluster

Visit [MongoDB Atlas on Google Cloud](https://www.mongodb.com/cloud/atlas/mongodb-google-cloud) and click **Start Free** (1).

![Create MongoDB Step 1](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-8af00f26f385dbbf116a167f8fc9b1467c02755e%2F2022-10-20_07-33.png?alt=media)

Register by clicking **Sign up with Google** (2) and sign-in using your existing Google Cloud credentials. This is the fastest way to register. On successful registration and login you will be redirected to the cloud.mongodb.com portal *Projects* page.

![Create MongoDB Step 2](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-220ffab92b3978a7d23d7934386c3ad59d54ff25%2F2022-10-20_07-37.png?alt=media)

Start by creating a project. Click **New Project** (3).

![Create MongoDB Step 3](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-00c3aec92183a6610b3f19d74f1648a09ca4167b%2F2022-10-20_07-46.png?alt=media)

Provide a project name such as *Squidex* (4) and click **Next** (5) to continue.

![Create MongoDB Step 4](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-57aafe049c07e173d22227594b70113303db3de9%2F2022-10-20_07-51.png?alt=media)

Finish project creation by clicking **Create Project** (6).

![Create MongoDB Step 5](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-266c5accebc9df8625df114a79f5fcd7a3caf89d%2F2022-10-20_07-53.png?alt=media)

The next step is to create the MongoDB database. Click **Build a Database** (7) to start.

![Create MongoDB Step 6](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-c9157996d529c0f1651000179c01b4774826117a%2F2022-10-20_07-56.png?alt=media)

Select **Create** under *Shared* which provides 1 free cluster.

![Create MongoDB Step 7](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-519dbb9b1acde51731ffe4c405d27269b22cdc5f%2F2022-10-20_07-58.png?alt=media)

Ensure again that **Free Shared** (9) option is selected, click **Google Cloud** (10), select a region of choice (11) and click **Create Cluster** (12).

![Create MongoDB Step 8](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-af5c66005dca7290c073ef5b916b544a139ac883%2F2022-10-20_08-31.png?alt=media)

In the next step, set Security details. Enter a Username (13) and Password (14) of choice (or click Autogenerate Secure Password to get one generated). Click **Create User** (15).

![Create MongoDB Step 10](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-9c2990a37b2c5a550d6e6636334641728c43c89c%2F2022-10-20_08-12.png?alt=media)

Finally, add network access permissions so Squidex can talk to it. Ensure **My Local Environment** (16) is selected, enter 0.0.0.0/0 (17) for IP Address and any Description (18). Click **Add Entry** (19).

![Create MongoDB Step 11](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-9afa244bbc3b9b2bb38434ffe0002776afccd587%2F2022-10-20_08-15.png?alt=media)

Click **Finish and Close**. This will redirect you to the Database Deployments page similar to the screenshot below.

![Create MongoDB Step 12](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-e9dbc81a4c588c8a94c63b885b5558eb525ed15f%2F2022-10-20_12-45.png?alt=media)

You will need the connection information for this MongoDB for use in the app configuration later. To copy the connection string click **Connect** (20) and then select **Connect your application** (21).

![Create MongoDB Step 13](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-673f64eb086f640c3eea665d701e41c2fd07f332%2F2022-10-20_12-41.png?alt=media)

Select C#/.NET (22) & 2.13 or later (23), copy the connection string (24) and click **Close** (24)

![Create MongoDB Step 14](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-7436caf2a221493bb8e20d7cb6d684daf883b5b6%2F2022-10-20_12-44.png?alt=media)

This completes creating the free MongoDB Atlas cluster.

## 2. Upload Squidex image to Artifact Registry

The following steps require Google cloud CLI, which can be installed on your development machine or you can use the Cloud Shell. The later is preferred for convenience. To launch Cloud Shell click  on the google cloud web console next to the search bar.

<figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-9fa968f86dbb46f5ad4654ffcdb168758c2d2ed0%2F2022-10-20_18-24.png?alt=media" alt=""><figcaption></figcaption></figure>

Run the following commands in sequence to create an Artifact Registry, download the latest Squidex from dockerhub and push it to Artifact Registry.

```
gcloud services enable artifactregistry.googleapis.com
```

```
export ARTIFACT_REGISTRY_NAME=squidex
export PROJECT_ID=$(gcloud config get-value project)
export REGION=us-central1
```

```
gcloud artifacts repositories create $ARTIFACT_REGISTRY_NAME --repository-format=docker --location=$REGION
```

```
docker pull squidex/squidex:latest
```

```
gcloud auth configure-docker $REGION-docker.pkg.dev
```

```
docker tag squidex/squidex:latest $REGION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY_NAME/squidex:latest
```

```
docker push $REGION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY_NAME/squidex:latest
```

## 3. Create Storage Bucket

Follow the steps below to create a Cloud Storage bucket for Squidex assets.

Sign into Google Cloud Console and navigate to Cloud Storage page. Select **Buckets** (1) (should be already selected) and click **+ Create** (2).

![Create Bucket Step 2](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-862dad40b0c027d384d2ea3527112d6036a86a3d%2F2022-10-20_00-32.png?alt=media)

Enter a unique name (3) for the bucket and click **Create** (4). You can leave the rest of the settings as it is or feel free to modify them as per needs.

![Create Bucket Step 3](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-ce3ee30b7178312c3f69a9c94c17f559af605654%2F2022-10-20_00-49.png?alt=media)

You may be prompted with a message. Click **Confirm** (5).

![Create Bucket Step 4](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-39580d1d7c0d1796f8224d74f5c7fb3f45feb365%2F2022-10-20_00-52.png?alt=media)

You will be taken to the bucket page. This completes the storage bucket creation step.

## 4. Create & Configure Cloud Run instance

Navigate to Cloud Run page in Google Cloud. Click **+ Create Service** (1) to begin.

![Create Cloud Run Step 1](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-2d24b3fd6da0706faec40dab858ef330800ec112%2F2022-10-20_13-21.png?alt=media)

Click **Select** (2), choose **Artifact Registry** tab and select (3) the Squidex image added earlier. Click **Select** (4) to continue.

![Create Cloud Run Step 2](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-7efa62d8dc69d53d6b355ba6d859ac02e6c598d2%2F2022-10-20_13-24.png?alt=media)

A Service name (5) is already assigned, modify this if needed. Set **Minimum number of instance** to *1* and **Maximum number of instance** to *1* (6).

{% hint style="info" %}
At this point Squidex has not been tested for autoscaling on Cloud Run, setting more than 1 instances here may have issues.
{% endhint %}

![Create Cloud Run Step 3](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-69fee80f0d9e980a6935dbc1c98a0fa959b38903%2F2022-10-20_13-29.png?alt=media)

Scroll down and select **Allow all traffic** (7) and **Allow unauthenticated invocations** (8). Then expand (9) the *Containers, Connections, Security* section.

![Create Cloud Run Step 4](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-a97ab6710113e05754ee248c89d6b3271f17e717%2F2022-10-20_13-31.png?alt=media)

Set **Container port** to *5000* (10) and set Memory to *1* and CPU to *1* (11).

![Create Cloud Run Step 5](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-527cc2596fe86c4ea8ccad3f06b88a9f0e572342%2F2022-10-20_13-34.png?alt=media)

Finally we set the environment variables. Click **+Add Variable** (12) and set the following environment variables (13) one by one replacing the values with your actual values where applicable, click **Create** (14) when done.

<table><thead><tr><th width="414.33333333333337">Key</th><th>Value</th><th>Notes</th></tr></thead><tbody><tr><td><code>[ASSETSTORE__TYPE]</code></td><td>GoogleCloud</td><td>Do not change this value</td></tr><tr><td><code>[ASSETSTORE__GOOGLECLOUD__BUCKET]</code></td><td><em>[STORAGE BUCKET NAME]</em></td><td>Provide your own value</td></tr><tr><td><code>[EVENTSTORE__MONGODB__CONFIGURATION]</code></td><td><em>[MONGODB CONNECTION STRING]</em></td><td>Provide your own value</td></tr><tr><td><code>[STORE__MONGODB__CONFIGURATION]</code></td><td><em>[MONGODB CONNECTION STRING]</em></td><td>Provide your own value</td></tr><tr><td><code>[ASPNETCORE_URLS]</code></td><td>http://+:5000</td><td>Do not change this value</td></tr></tbody></table>

![Create Cloud Run Step 6](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-96f0fb6a060fda76eac265a72a934638751ac506%2F2022-10-20_13-42.png?alt=media)

Wait until the deployment is complete and you have sucessful notification with a green check. Copy the URL (15) and click **Edit & Deploy New Version** (16).

![Create Cloud Run Step 7](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-972c04e5fe9761a32ac7200a68f475eff5a08825%2F2022-10-20_13-52.png?alt=media)

Add a new environment variable by clicking **+Add Variable** (17) and then adding the following (18). Click **Deploy** (19) when done.

| Key               | Value              | Notes                  |
| ----------------- | ------------------ | ---------------------- |
| `[URLS__BASEURL]` | *\[CLOUD RUN URL]* | Provide your own value |

{% hint style="info" %}
If you want to use your \*\*custom domain\*\*, enter the domain/sub-domain here instead of the Cloud Run URL.
{% endhint %}

![Create Cloud Run Step 8](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-6f923205005edb05ebb9afc4dc1f9b03d05f19b7%2F2022-10-20_13-56.png?alt=media)

This should deploy a new revision of the Cloud Run and update the Base URL value in the app.

![Create Cloud Run Step 9](https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2Fgit-blob-5bcb939bd3de12287838a6edf44cf0b240b831d8%2F2022-10-20_16-45.png?alt=media)

You can now open the URL in a browser and continue with Squidex setup.
