Update ntfy.py to be able to be dockerize, Dockerization of ntfy.py

This commit is contained in:
2024-03-01 12:00:10 +01:00
parent 76aa16e0b9
commit 6e89bd2c3e
4 changed files with 47 additions and 9 deletions

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM python:3.11.8-alpine3.19
LABEL maintainer="BreizhHardware"
ADD ntfy.py /
ADD requirements.txt /
RUN pip install -r requirements.txt
# Définir les variables d'environnement pour username et password
ENV USERNAME="" \
PASSWORD="" \
NTFY_URL=""
# Exécuter la commande pour générer l'authentification base64 à partir des variables d'environnement
RUN echo -n "$USERNAME:$PASSWORD" | base64 > /auth.txt
CMD ["python", "./ntfy.py"]

View File

@@ -6,15 +6,29 @@ Personal ntfy alerts system
## Description:
This script is used to watch the github repos and send a notification to the ntfy server when a new release is published.
## Utilisation:
````python
python ntfy.py <auth> <ntfy_url>
````
auth and ntfy_url are required to be set as environment variables.
auth: can be generataed by the folowing command: echo -n 'username:password' | base64
ntfy_url: the url of the ntfy server including the topic
````python
python ntfy.py
````
## Docker:
If you want to use the docker image you can use the following docker-compose file:
````yaml
version: '3'
services:
github-ntfy:
image: breizhhardware/github-ntfy
container_name: github-ntfy
environment:
- USERNAME=username
- PASSWORD=password
- NTFY_URL=ntfy_url
restart: unless-stopped
````
Acctualy the watched repos list is hardcoded in the ntfy.py file under the name of watched_repos_list.
## TODO:
- [ ] Dockerize the ntfy.py
- [x] Dockerize the ntfy.py
- [ ] Add the watched repos list as a parameter
- [ ] Add the watched repos list as a file
- [ ] Add the watched repos list as a database

14
ntfy.py
View File

@@ -1,5 +1,6 @@
import requests
import time
import os
from sys import argv as args
watched_repos_list = ['dani-garcia/vaultwarden', 'jellyfin/jellyfin', 'linuxserver/Heimdall',
@@ -53,12 +54,17 @@ def send_to_ntfy(releases, auth, url):
if __name__ == "__main__":
if len(args) == 3:
with open('/auth.txt', 'r') as f:
auth = f.read().strip()
ntfy_url = os.environ.get('NTFY_URL')
if auth and ntfy_url:
while True:
latest_release = get_latest_releases(watched_repos_list)
if latest_release:
send_to_ntfy(latest_release, args[1], args[2])
send_to_ntfy(latest_release, auth, ntfy_url)
time.sleep(3600) # Attendre une heure avant de vérifier à nouveau
else:
print("Usage: python ntfy.py <auth> <ntfy_url>")
print("auth: can be generataed by the folowing command: echo -n 'username:password' | base64")
print("Usage: python ntfy.py")
print("auth: can be generataed by the folowing command: echo -n 'username:password' | base64 and need to be stored in a file named auth.txt")
print("NTFY_URL: the url of the ntfy server need to be stored in an environment variable named NTFY_URL")

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
requests==2.31.0