> ## Documentation Index
> Fetch the complete documentation index at: https://docs.briefer.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# GCE Virtual Machine (GCP)

> A GCP-specific guide for deploying Briefer.

This guide describes how to set up Briefer on a Google Cloud Platform (GCP) instance using Google's Compute Engine (GCE), Docker, and, optionally, Nginx as a reverse proxy for public access.

<Note>
  These are recommendations from October 2024 and may be subject to change due
  to updates in GCP. If you encounter any issues, please create an issue or
  submit a pull request [on our GitHub
  repo](https://github.com/briefercloud/briefer).
</Note>

## Table of Contents

1. [Prerequisites](#1-prerequisites)
2. [Creating the Compute Engine Instance](#2-creating-the-compute-engine-instance)
3. [Installing Docker](#3-installing-docker)
4. [Running Briefer](#4-running-briefer)
5. [(Optional) Configuring Nginx for Public Access](#optional-5-configuring-nginx-for-public-access)

## 1. Prerequisites

* A Google Cloud Platform (GCP) account
* Access to Google Cloud Console
* An SSH key configured to access the GCP instance

## 2. Creating the Compute Engine Instance

1. Access the [Google Cloud Console](https://console.cloud.google.com/) and navigate to Compute Engine > VM instances.
2. Click on "Create Instance."
3. We recommend configuring the VM with these settings (or higher):
   * **vCPUs**: 2
   * **Memory**: 8 GB
   * **Disk**: 10 GB balanced
   * **IOPS**: 3060 provisioned
   * **Processing capacity**: 155 provisioned
     <Info>
       These system requirements are ideal for most cases. However, they can be
       adjusted up or down depending on your project's needs and demands.
     </Info>
4. Give your instance a name and click "Create."

Once the instance is initialized, connect to it via SSH.

## 3. Installing Docker

1. Update the instance's packages:
   ```bash theme={null}
   sudo apt update && sudo apt upgrade -y
   ```
2. Install the necessary packages for HTTPS repositories:
   ```bash theme={null}
   sudo apt install apt-transport-https ca-certificates curl software-properties-common
   ```
3. Add the Docker repository:
   ```bash theme={null}
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
   sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
   sudo apt update
   ```
4. Install Docker:
   ```bash theme={null}
   sudo apt install docker-ce -y
   ```
5. Add your user to the `docker` group:
   ```bash theme={null}
   sudo usermod -aG docker ${USER}
   ```
6. Verify if Docker was installed correctly:

   ```bash theme={null}
   docker ps
   ```

## 4. Running Briefer

After installing Docker, you can run Briefer using the following command:

```bash theme={null}
docker run -d \
  -p 3000:3000
  -v briefer_psql_data:/var/lib/postgresql/data \
  -v briefer_jupyter_data:/home/jupyteruser \
  -v briefer_briefer_data:/home/briefer \
  briefercloud/briefer
```

Ensure that Briefer is running by accessing port `3000` on your instance's public IP:

```bash theme={null}
curl http://<your_public_ip>:3000
```

The Briefer interface should be accessible directly from the browser using the same URL.

<Warning>
  You should not be able to login yet because you're serving Briefer over HTTP
  and have not set the `ALLOW_HTTP` environment variable to `true`. If you want
  to continue using Briefer over HTTP please add `--env ALLOW_HTTP=true` to the
  `docker run` command. If you want to use HTTPS, please set up SSL
  certificates.
</Warning>

***

## (Optional) 5. Configuring Nginx for Public Access

To expose Briefer through a reverse proxy using Nginx:

1. Install Nginx:

   ```bash theme={null}
   sudo apt install nginx -y
   sudo systemctl start nginx
   sudo systemctl enable nginx
   ```

2. Ensure that Nginx is running by accessing the public IP of the instance in your browser.

3. Configure Nginx to serve Briefer:

   ```bash theme={null}
   cd /etc/nginx/sites-available/
   sudo nano /etc/nginx/sites-available/briefer
   ```

   We recommend that you configure your Nginx instance with a file similar to the one below.

   ```nginx theme={null}
   server {
       listen 80;

       server_name _;

       client_max_body_size 0;

       location / {
           proxy_pass http://localhost:3000;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_request_buffering off;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "Upgrade";
       }
   }
   ```

4. Enable the new Nginx configs.

   ```bash theme={null}
   sudo ln -s /etc/nginx/sites-available/briefer /etc/nginx/sites-enabled/
   sudo rm /etc/nginx/sites-enabled/default
   sudo nginx -t
   sudo systemctl restart nginx
   ```

Now, Briefer will be accessible through your instance's public IP without needing to specify port `3000`.
