From cd578e43bddef61a9f7f80005879ef12fb479d13 Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:17:02 -0300 Subject: [PATCH] feat(bot): :sparkles: Finish migrating to k8s. --- Dockerfile | 4 ++-- README.md | 25 ++++++++++++++----------- k8s/bot.yml | 5 ++++- run.py | 7 ++----- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index d65d976..69274fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ COPY . . RUN pip install uv 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" ] diff --git a/README.md b/README.md index 27d098d..52bc187 100644 --- a/README.md +++ b/README.md @@ -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 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 - 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 +1. The Discord bot's token, either for development or production depending on what you're setting 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 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 @@ -192,13 +189,19 @@ kubectl exec citus-0 -- psql -U payphone payphone -c "SELECT * FROM citus_get_ac #### 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= --docker-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 -# 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 ``` diff --git a/k8s/bot.yml b/k8s/bot.yml index 3d2281a..3ce74f5 100644 --- a/k8s/bot.yml +++ b/k8s/bot.yml @@ -18,10 +18,11 @@ spec: containers: - name: bot image: git.nyeki.dev/payphone/payphone:latest + imagePullPolicy: "Always" envFrom: - configMapRef: name: bot-config - - secretsRef: + - secretRef: name: bot-secrets env: - name: IS_DEBUG @@ -39,6 +40,8 @@ spec: requests: cpu: "250m" memory: "256Mi" + imagePullSecrets: + - name: regcred volumeClaimTemplates: - metadata: name: bot-storage diff --git a/run.py b/run.py index f619690..74d16b1 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ -import aerich +import os from payphone import bot from payphone.db import setup @@ -19,10 +19,7 @@ async def init() -> None: """Initializes the DB.""" if config.SHARD_ID == 0: - command = aerich.Command(config.TORTOISE_ORM, "models", "./payphone/db/migrations") - - await command.init_db(True) - await command.upgrade() + os.system("aerich upgrade") await setup.init()