These instructions describe a process for manually hosting the bot on GCE. This will not have automated deployments.
Note: These instructions were written before Docker images were created for this project. Check the AWS instructions to get a general idea of how to run a Docker container instead.
These instructions do not mention how to gather your environment variables. You can see the structure of the .env
file here and instructions on how to gather them in the Heroku instructions.
These instructions also assume you have created a PostgreSQL database on Heroku, as instructed in the Heroku instructions. Even if you do not want to host the bot on Heroku, you probably want to utilize Heroku's free PostgreSQL database. It's recommended to go through the Heroku instructions, create your Heroku app with the database, then disable the dyno and proceed to host the bot on the VM described here.
-
Create a VM instance under the Google Compute Engine.
-
Use an
e2-micro
instance in a free region if you want to remain in the free tier. For example, theus-central1
region. -
(Optional) Choose an Ubuntu machine (latest version).
-
SSH into the instance.
-
sudo apt update
-
sudo apt install python ffmpeg
-
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -
-
sudo apt install -y nodejs
-
git clone https://github.com/mikeyaworski/Utility-Discord-Bot.git
-
cd ~/Utility-Discord-Bot
-
npm ci`
-
Retrieve your
DATABASE_URL
environment variable with:heroku config:get DATABASE_URL -a miky-utility-discord-bot
Where
miky-utility-discord-bot
is replaced to whatever your Heroku app is named. Note that this value is subject to change. When/if it changes, you will need to update the environment variable and restart the app.As previously mentioned, these instructions assume you have gone through the Heroku instructions to create a Heroku app with a free PostgreSQL database.
-
Create a
.env
file with all of the environment variables filled in. This means your secrets are written to the instance's disk. If this is a security concern for you, then there are alternative ways to define secrets, but are more effort.You can see the structure of the
.env
file here and instructions on how to gather the environment variables in the Heroku instructions.If unfamiliar with the command line, here are instructions to create the
.env
file using vim:- Create it on your local computer and copy the contents of the file.
- In your SSH session, run
vi .env
(make sure you are inside theUtility-Discord-Bot
folder). - Press
i
to enter Insert mode - Paste. This pastes the content of the
.env
file. If on Windows WSL, you may need to right click your WSL bar, click Properties and check "Use Ctrl+Shift+C/V as Copy/Paste" first. And then useCtrl + Shift + V
to paste. - Type
:x
to save and quit.
You can use something like nano instead of vim if you struggle with the instructions above.
-
npm run start:nohup
cd ~/Utility-Discord-Bot
npm run stop:nohup
npm run start:nohup
cd ~/Utility-Discord-Bot
git pull
If there are dependency changes, then you will need to stop the app, update the dependencies, and run it again.
npm run stop:nohup
npm ci
npm run start:nohup
cd ~/Utility-Discord-Bot
npm run stop:nohup
Or find the node process and kill it (using its PID).
ps -ef | grep "[b]in/ts-node"
kill -9 ...
cd ~/Utility-Discord-Bot
cat log
- Build this VM from an image.