feat(bot): ✨ Finish migrating to k8s.

This commit is contained in:
Nyeki.py
2024-10-31 12:17:02 -03:00
parent c0616cbcfe
commit cd578e43bd
4 changed files with 22 additions and 19 deletions
+2 -2
View File
@@ -6,6 +6,6 @@ COPY . .
RUN pip install uv RUN pip install uv
RUN uv sync --no-dev RUN uv sync --no-dev
ENTRYPOINT [ "/bin/bash" ] ENTRYPOINT [ "uv" ]
CMD [ "uv", "run", "--no-dev", "python3", "-u", "run.py" ] CMD [ "run", "--no-dev", "python3", "-u", "run.py" ]
+14 -11
View File
@@ -8,12 +8,9 @@ Payphone is deployed using Kubernetes + Docker. To set up a local kubernetes clu
This section will guide you step by step to create a multi-node cluster or a local development This section will guide you step by step to create a multi-node cluster or a local development
cluster and start up Payphone. Make sure to have: cluster and start up Payphone. Make sure to have:
1. A Docker Hub account with a slot for a private image. By default all free accounts allow 1 1. The Discord bot's token, either for development or production depending on what you're setting
private image, so if you haven't uploaded any private images to your account, you do have an
available slot.
2. The Discord bot's token, either for development or production depending on what you're setting
up the cluster for. up the cluster for.
3. You'll probably need at least 5 CPU cores (6 recommended) across all of your machines + 1 core 2. You'll probably need at least 5 CPU cores (6 recommended) across all of your machines + 1 core
per shard, 8 GB of ram + 512Mb of RAM per shard, and 30Gb of disk space available. It'll still per shard, 8 GB of ram + 512Mb of RAM per shard, and 30Gb of disk space available. It'll still
run with less, but it'll be way slower. In multi-node environment, these specifications are run with less, but it'll be way slower. In multi-node environment, these specifications are
cluster-wide, meaning that if you have 3 nodes with 3 cores, that makes it 9 cores in total and cluster-wide, meaning that if you have 3 nodes with 3 cores, that makes it 9 cores in total and
@@ -192,13 +189,19 @@ kubectl exec citus-0 -- psql -U payphone payphone -c "SELECT * FROM citus_get_ac
#### Setting Up Payphone #### Setting Up Payphone
Finally, you need to start the bot's instance. Finally, you need to start the bot's instance. First, log into your `git.nyeki.dev` account from
`kubectl` with the following command:
```sh
kubectl create secret docker-registry regcred --docker-server=https://git.nyeki.dev/v1/ --docker-username=<your-username> --docker-password=<your-password>
```
After that command is ran, the next step is to update the amount of shards. To set the amount,
open `k8s/bot.yml` and set the total number of shards in both `spec.replicas` and
`spec.template.spec.containers.bot.env.TOTAL_SHARDS.value`.
Once it's done, you can save and close the file and run the final command.
```sh ```sh
# Steps before running this command:
# 1. Update the image name in `bot.yml` to your own image name (the one that you have in your
# private docker hub registry)
# 2. Set the total number of shards in both `spec.replicas` and
# `spec.template.spec.containers.bot.env.TOTAL_SHARDS.value`.
kubectl apply -f k8s/bot.yml kubectl apply -f k8s/bot.yml
``` ```
+4 -1
View File
@@ -18,10 +18,11 @@ spec:
containers: containers:
- name: bot - name: bot
image: git.nyeki.dev/payphone/payphone:latest image: git.nyeki.dev/payphone/payphone:latest
imagePullPolicy: "Always"
envFrom: envFrom:
- configMapRef: - configMapRef:
name: bot-config name: bot-config
- secretsRef: - secretRef:
name: bot-secrets name: bot-secrets
env: env:
- name: IS_DEBUG - name: IS_DEBUG
@@ -39,6 +40,8 @@ spec:
requests: requests:
cpu: "250m" cpu: "250m"
memory: "256Mi" memory: "256Mi"
imagePullSecrets:
- name: regcred
volumeClaimTemplates: volumeClaimTemplates:
- metadata: - metadata:
name: bot-storage name: bot-storage
+2 -5
View File
@@ -1,4 +1,4 @@
import aerich import os
from payphone import bot from payphone import bot
from payphone.db import setup from payphone.db import setup
@@ -19,10 +19,7 @@ async def init() -> None:
"""Initializes the DB.""" """Initializes the DB."""
if config.SHARD_ID == 0: if config.SHARD_ID == 0:
command = aerich.Command(config.TORTOISE_ORM, "models", "./payphone/db/migrations") os.system("aerich upgrade")
await command.init_db(True)
await command.upgrade()
await setup.init() await setup.init()