-
Notifications
You must be signed in to change notification settings - Fork 0
Deploy your own typst bot
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 on the less powerful VM.
- A GCP Project with billing enabled.
- The Google Cloud CLI installed on your local machine.
- Docker installed on your local machine and on your GCP e2 VM.
- An active GCP e2 VM instance.
- Your Discord app token.
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 .Next, you will push the built image to GCR. This makes the image available to your GCP VM and other services.
-
Authenticate Docker: Run this command on your local machine to configure Docker to use your
gcloudcredentials.gcloud auth configure-docker
-
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
-
Push the Image: Push the tagged image to your GCR repository.
docker push gcr.io/[PROJECT_ID]/typst-bot:latest
Now that the image is in GCR, you will connect to your VM, pull the image, and run it.
-
Connect to your VM: Use
gcloudto SSH into your VM instance.gcloud compute ssh [VM_INSTANCE_NAME] --zone=[VM_ZONE]
-
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
-
Pull the Image from GCR: Pull the image you just pushed.
docker pull gcr.io/[PROJECT_ID]/typst-bot:latest
-
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
HISTCONTROLisignoreboth, start the followingdocker runcommand 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-botNote 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.