From 0100e6576813720bed8965201bfcb7589d1a4605 Mon Sep 17 00:00:00 2001 From: bral bral Date: Thu, 20 Jun 2024 19:27:27 +0300 Subject: [PATCH] added k8s deploy section --- README.MD | 28 +++++++++--- deploy/{ => docker}/example.config.yaml | 0 .../{ => docker}/example.docker-compose.yml | 0 deploy/k8s/00_namespace.yaml | 5 +++ deploy/k8s/01_configmap.yaml | 43 +++++++++++++++++++ deploy/k8s/02_deployment.yaml | 40 +++++++++++++++++ src/constants.py | 2 +- 7 files changed, 112 insertions(+), 6 deletions(-) rename deploy/{ => docker}/example.config.yaml (100%) rename deploy/{ => docker}/example.docker-compose.yml (100%) create mode 100644 deploy/k8s/00_namespace.yaml create mode 100644 deploy/k8s/01_configmap.yaml create mode 100644 deploy/k8s/02_deployment.yaml diff --git a/README.MD b/README.MD index 017243c..add59e5 100644 --- a/README.MD +++ b/README.MD @@ -16,7 +16,7 @@ Use this bot for communicate with users in case you do not want to provide your Messages with an **available content type** *(TEXT, ANIMATION, AUDIO, DOCUMENT, PHOTO, VIDEO, VOICE)* will be transferred to **admin group** or **admin chat**. -*(See variable `chat_id` from [config.yaml](./deploy/example.config.yaml#L6))* +*(See variable `chat_id` from [config.yaml](deploy/docker/example.config.yaml#L6))* If the transfer is successful, the requesting party will be notified. @@ -26,7 +26,7 @@ The user will receive the reply as a **reply** to the original message. If the m If the transfer is successful, the administrator will be notified. -You can [customize the bot's responses](./deploy/example.config.yaml#12), or use default values. +You can [customize the bot's responses](deploy/docker/example.config.yaml#12), or use default values. ## Deploy @@ -42,7 +42,7 @@ Install requirements: `pip install -r requirements.txt` -Fill [config.yml](./deploy/example.config.yaml) and place it to root dir. (In parent dir to `src`) +Fill [config.yml](deploy/docker/example.config.yaml) and place it to root dir. (In parent dir to `src`) Run: @@ -52,7 +52,7 @@ Run: > Stable release with `main` tag on [dockerhub](https://hub.docker.com/r/bral1488/telegram-feedback-bot/tags) -Just copy [docker-compose.yml](./deploy/example.docker-compose.yml) and fill in [config.yaml](./deploy/example.config.yaml). +Just copy [docker-compose.yml](deploy/docker/example.docker-compose.yml) and fill in [config.yaml](deploy/docker/example.config.yaml). Run containers: @@ -68,7 +68,25 @@ and build docker image: `docker build -t :` -And use this image with [docker-compose.yml](./deploy/example.docker-compose.yml) from `deploy` dir. +### Install with k8s + +> Stable release with `main` tag on [dockerhub](https://hub.docker.com/r/bral1488/telegram-youtube-notifier/tags) + +Manifests located in [k8s](deploy%2Fk8s) directory. + +It consists of `Namespace`, `ConfigMap`, and `Deployment` files. + +You need fill sections in [01_configmap.yaml](deploy%2Fk8s%2F01_configmap.yaml) file. + +Apply deployment: + +`kubectl apply -f ` + +Or you can do it step by step: + +`kubectl apply -f ` + +And use this image with [docker-compose.yml](deploy/docker/example.docker-compose.yml) from `deploy` dir. ## Hosting You can rent a server from various hosters, for example from [Aeza](https://aeza.net/?ref=380831). diff --git a/deploy/example.config.yaml b/deploy/docker/example.config.yaml similarity index 100% rename from deploy/example.config.yaml rename to deploy/docker/example.config.yaml diff --git a/deploy/example.docker-compose.yml b/deploy/docker/example.docker-compose.yml similarity index 100% rename from deploy/example.docker-compose.yml rename to deploy/docker/example.docker-compose.yml diff --git a/deploy/k8s/00_namespace.yaml b/deploy/k8s/00_namespace.yaml new file mode 100644 index 0000000..226bfea --- /dev/null +++ b/deploy/k8s/00_namespace.yaml @@ -0,0 +1,5 @@ +# create separate namespace +apiVersion: v1 +kind: Namespace +metadata: + name: tg-feedback-namespace \ No newline at end of file diff --git a/deploy/k8s/01_configmap.yaml b/deploy/k8s/01_configmap.yaml new file mode 100644 index 0000000..f008cfc --- /dev/null +++ b/deploy/k8s/01_configmap.yaml @@ -0,0 +1,43 @@ +# create config map +# for config.yaml +# and cookies.txt (optional) +apiVersion: v1 +kind: ConfigMap +metadata: + name: tg-feedback-config + namespace: tg-feedback-namespace +data: + config.yaml: | + bot: + # get bot token from https://t.me/botfather + token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + + # chat id for redirect messages + chat_id: -100XXXXXXXXXXXXX + + # Fill variables below as you want, or use default values. + # You can use HTML tags provided by the sulguk package. + # https://github.com/Tishka17/sulguk#readme + + #messages: + # notify_user_about_success_deliver: ✅ Please wait for response. + # help_message: | + #

+ # 👋 Hello! + #

+ #

+ # I can redirect to recipient text, audios, voice messages, images, files to recipient. + #

+ # + #

+ # Just send your message and wait for a response! + #

+ # notify_admin_about_success_answer: ✅ Answered. + # + #errors: + # unsupported_type: ❌ Unsupported message type.
Please check /help command. + # too_long_message_text: ❌ Too long message text. + # too_long_message_caption: ❌ Too long message caption. + # copy_message: ❌ Error during copying + # extract_user_id: ❌ Error during extract_id + # chat_not_found: ❌ Chat not found. Make sure you have added the bot to the admin group \ No newline at end of file diff --git a/deploy/k8s/02_deployment.yaml b/deploy/k8s/02_deployment.yaml new file mode 100644 index 0000000..ecc3f96 --- /dev/null +++ b/deploy/k8s/02_deployment.yaml @@ -0,0 +1,40 @@ +# create deployment +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tg-feedback + namespace: tg-feedback-namespace +spec: + replicas: 1 + selector: + matchLabels: + app: tg-feedback + template: + metadata: + labels: + app: tg-feedback + spec: + containers: + - name: tg-feedback + image: bral1488/telegram-feedback-bot:main + imagePullPolicy: Always + command: ["sh", "-c", "python -m src"] + volumeMounts: + - name: config-volume + mountPath: /app/config.yaml + subPath: config.yaml + readOnly: true + resources: + limits: + memory: "64Mi" + cpu: "125m" + securityContext: + runAsUser: 0 + volumes: + - name: config-volume + configMap: + name: tg-feedback-config + tolerations: + - key: "node.kubernetes.io/disk-pressure" + operator: "Exists" + effect: "NoSchedule" diff --git a/src/constants.py b/src/constants.py index 0151077..2bcc21e 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,6 +1,6 @@ import os -VERSION: str = "2024-06-16.18" +VERSION: str = "2024-06-20.19" ROOT_DIR: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) CONFIG_FILE_PATH: str = os.path.join(ROOT_DIR, "config.yaml")