Skip to content

Deploy your own typst bot

Vincent Tam edited this page Aug 13, 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 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
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 VM, pull the image, and run it.

  1. Connect to your VM: Use gcloud to SSH into your VM instance.

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

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

    docker pull gcr.io/[PROJECT_ID]/typst-bot:latest
  4. Run the Container: Finally, run the container in detached mode, passing your Discord bot token as an environment variable. To avoid leaving a trace of the token value in the command history, after ensuring that the environment variable HISTCONTROL is ignoreboth, start the following docker run command with a leading whitespace.

     docker run -d \
        --name typst-bot \
        -e DISCORD_TOKEN="YOUR_BOT_TOKEN_HERE" \
        --restart unless-stopped \
        gcr.io/[PROJECT_ID]/typst-bot:latest

The typst-bot should now be running in a container on your 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 typst-bot

Note on Stability: To prevent future connection issues, consider promoting your VM's external IP to a static address in the GCP Console. This ensures the IP address never changes, making it easier to connect consistently.

Clone this wiki locally