Skip to content

Deploy your own typst bot

Vincent Tam edited this page Aug 24, 2025 · 8 revisions

Deploy your own typst Bot on Google Cloud Platform

This guide outlines the steps to build and deploy the typst-bot Docker container on a Google Cloud Platform (GCP) e2 virtual machine (VM). This approach uses Docker and GCR to efficiently manage the application without needing to rebuild slowly on the less powerful remote VM.

Prerequisites


Procedure

Step 1: Clone the Repository and Build the Docker Image Locally

First, clone the typst-bot repository and build the Docker image on your local, more powerful machine. This avoids the slow compilation on the e2 VM.

# Clone the repository
cd ~
git clone https://github.com/mattfbacon/typst-bot.git
cd typst-bot

# Build the Docker image
# This will run the slow Rust compilation on your local machine
docker build -t typst-bot .

Step 2: Push the Image to Google Container Registry (GCR)

Next, you will push the built image to GCR. This makes the image available to your GCP VM and other services.

  1. Authenticate Docker: Run this command on your local machine to configure Docker to use your gcloud credentials.

    gcloud auth configure-docker
  2. Tag the Image for GCR: Tag your local image with the GCR path. Replace [PROJECT_ID] with your GCP Project ID.

    docker tag typst-bot gcr.io/[PROJECT_ID]/typst-bot:latest

    Note: the [PROJECT_ID] can be found on the GCP console.

    gcp_proj_ID

  3. Push the Image: Push the tagged image to your GCR repository.

    docker push gcr.io/[PROJECT_ID]/typst-bot:latest

Step 3: Deploy the Image on the GCP e2 VM

Now that the image is in GCR, you will connect to your remote VM, pull the image, and run it.

  1. Add SSH keys to your terminal

    To avoid getting prompted for passphrase for the SSH key before each connection to remote VM.

    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/google_compute_engine
  2. Connect to your Remote VM: Use gcloud to SSH into your remote VM instance.

    gcloud compute ssh [USERNAME]@[VM_INSTANCE_NAME] --zone=[VM_ZONE]
  3. Authenticate Docker on the Remote VM: From within the remote VM's terminal, configure Docker to use the remote VM's service account credentials. This gives it permission to pull the private image.

    gcloud auth configure-docker
  4. Pull the Image from GCR: Pull the image you just pushed.

    docker pull gcr.io/[PROJECT_ID]/typst-bot:latest
  5. Remote Setup for Docker Compose Create the folder typst-bot under the user directory (to match host machine's path).

    cd ~
    mkdir typst-bot

    Then switch to this directory, and create a file named discord_token.txt with the Discord token. If you're using cat for saving a text file, after pasting the token, tap Enter and Ctrl-d to finish.

    cd typst-bot
    cat > discord_token.txt

    Logout from your remote VM. Copy your local docker-compose.yml to remote VM.

    gcloud compute scp docker-compose.yml [USERNAME]@[VM_INSTANCE_NAME]:/home/[USERNAME]/typst-bot/ --zone=[VM_ZONE]

    Then adjust the docker compose file on remote VM for final deployment.

    1. Log in to your remote VM again.
    2. Change directory to ~/typst-bot.
    3. In docker-compose.yml, replace build: . with image: gcr.io/[PROJECT_ID]/typst-bot:latest (because we are running from the image that we've just pushed to GCR, instead of building the image).
  6. Run the Container: Finally, run the container in detached mode.

     docker compose up -d

The typst-bot should now be running in a container on your remote VM. You can check its status and logs using the following commands:

# Check if the container is running
docker ps

# View the container logs
docker logs [CONTAINER]

[CONTAINER] is the name of the running container.