Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bumps reqs && reformat k8s files #72

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ And use this image with [docker-compose.yml](./deploy/example.docker-compose.yml

> Stable release with `main` tag on [dockerhub](https://hub.docker.com/r/bral1488/telegram-youtube-notifier/tags)

Just copy [deployment.yml](deploy%2Fk8s%2Fexample.deployment.yml) and fill in sections in `ConfigMap`, `PersistentVolume` sections.
Manifests located in [k8s](deploy%2Fk8s) directory.

It consists of `Namespace`, `ConfigMap`, `PersistenVolume`, `PersistentVolumeClaim`, and `Deployment` files.

You need fill sections in [01_configmap.yaml](deploy%2Fk8s%2F01_configmap.yaml) and [02_persistent_volume.yaml](deploy%2Fk8s%2F02_persistent_volume.yaml) files.

> ⚠️ Deployment use `storageClassName: local-path`. A detailed description can be found [here](https://kubernetes.io/docs/concepts/storage/storage-classes/#local)

Apply deployment:

`kubectl apply -f deployment.yml`
`kubectl apply -f <directory with configs>`

Or you can do it step by step:

`kubectl apply -f <file from config dir>`

## Setup Cookies

Expand Down
5 changes: 5 additions & 0 deletions deploy/k8s/00_namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# create separate namespace
apiVersion: v1
kind: Namespace
metadata:
name: yt-notifier-namespace
51 changes: 51 additions & 0 deletions deploy/k8s/01_configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# create config map
# for config.yaml
# and cookies.txt (optional)
apiVersion: v1
kind: ConfigMap
metadata:
name: yt-notifier-config
namespace: yt-notifier-namespace
data:
config.yaml: |
bot:
token: XXXXXXXXXXXXXXXXXXXXX
chat_id: -100XXXXXXXXXXXXXXXXX
temp_chat_id: -100XXXXXXXXXXXX
report:
template: |
<h1>✅ СЕЙЧАС В ЭФИРЕ:</h1>
<br/>
<ol type='1'>
{% for channel in channels %}
<li>
<b><a href='{{channel.url}}'>{{channel.label}}</a></b> <br/>
{% if channel.concurrent_view_count is not none %}
<b>👀{{channel.concurrent_view_count}}</b>
{% endif %}
{% if channel.like_count is not none %}
<b>👍{{channel.like_count}}</b>
{% endif %}
{% if channel.duration is not none %}
<b>🕑{{channel.duration}}</b>
{% endif %}
</li>
<br/>
{% endfor %}
</ol>
<hr/>
<i>💬 Заходите в наш <a href='https://t.me/Discordovchat'>чат</a>.</i>
<br/>
<i>🤖 <a href='https://t.me/discordovo_feedback_bot'>Бот-предложка</a>, присылайте интересные ссылки на каналы/видео/картинки. </i>
empty: |
<b>🤷 Интересных стримов сейчас нет.</b>
<hr/>
<i>💬 Заходите в наш <a href='https://t.me/Discordovchat'>чат</a>.</i>
<br/>
<i>🤖 <a href='https://t.me/discordovo_feedback_bot'>Бот-предложка</a>, присылайте интересные ссылки на каналы/видео/картинки. </i>

start_scheduler: True
interval_s: 300
cookies.txt: |
# Netscape HTTP Cookie File
# This file is generated by yt-dlp. Do not edit.
24 changes: 24 additions & 0 deletions deploy/k8s/02_persistent_volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# create persistent volume for database
apiVersion: v1
kind: PersistentVolume
metadata:
name: yt-notifier-pv
namespace: yt-notifier-namespace
spec:
capacity:
storage: 128Mi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-path
local:
path: /path/to/database/on/host/machine
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- my-k8s-node # get value from kubectl get nodes
13 changes: 13 additions & 0 deletions deploy/k8s/03_persistent_volume_claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# create volume claim for database
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yt-notifier-pvc
namespace: yt-notifier-namespace
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 128Mi
storageClassName: local-path
53 changes: 53 additions & 0 deletions deploy/k8s/04_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# create deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: yt-notifier
namespace: yt-notifier-namespace
spec:
replicas: 1
selector:
matchLabels:
app: yt-notifier
template:
metadata:
labels:
app: yt-notifier
spec:
containers:
- name: yt-notifier
image: bral1488/telegram-youtube-notifier:main
imagePullPolicy: Always
command: ["sh", "-c", "python -m src"]
volumeMounts:
- name: config-volume
mountPath: /app/config.yaml
subPath: config.yaml
readOnly: true
- name: config-volume
mountPath: /app/cookies.txt
subPath: cookies.txt
readOnly: true
- name: db-volume
mountPath: /db/youtube-notifier-bot.db
subPath: youtube-notifier-bot.db
resources:
limits:
memory: "256Mi"
cpu: "500m"
securityContext:
runAsUser: 0
env:
- name: SQLITE_DATABASE_FILE_PATH
value: "/db/youtube-notifier-bot.db"
volumes:
- name: config-volume
configMap:
name: yt-notifier-config
- name: db-volume
persistentVolumeClaim:
claimName: yt-notifier-pvc
tolerations:
- key: "node.kubernetes.io/disk-pressure"
operator: "Exists"
effect: "NoSchedule"
150 changes: 0 additions & 150 deletions deploy/k8s/example.deployment.yml

This file was deleted.

6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
aiogram==3.7.0
aiogram-dialog==2.2.0a3
aiogram-dialog==2.2.0a4
pydantic==2.7.2
APScheduler==3.10.4
yt-dlp==2024.5.27
sulguk==0.8.0
jinja2==3.1.4
pyyaml==6.0.1
pydantic_settings==2.2.1
pydantic_settings==2.3.3
structlog==24.2.0
orjson==3.10.3
orjson==3.10.5
uvloop==0.19.0
SQLAlchemy==2.0.30
alembic==1.13.1
Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pre-commit==3.6.2
pre-commit==3.7.1
black==24.4.2
autoflake==2.3.1
reorder-python-imports==3.13.0
pyupgrade==3.16.0
pytest==8.2.1
pytest==8.2.2
pytest-cov==5.0.0
git+https://github.com/aio-libs/sort-all.git
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SQLITE_DATABASE_FILE_PATH: str = os.environ.get(
"SQLITE_DATABASE_FILE_PATH", os.path.join(ROOT_DIR, "youtube-notifier-bot.db")
)
VERSION: str = "2024-06-16.16"
VERSION: str = "2024-06-20.10"

__all__ = [
"CONFIG_FILE_PATH",
Expand Down
Loading