1
0
Fork 0

Init commit

This commit is contained in:
Ethanell 2020-01-12 21:54:20 +01:00
commit 1515dcd150
4 changed files with 70 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
webhook_secret.env
TelegramEDT/

10
Dockerfile Normal file
View file

@ -0,0 +1,10 @@
FROM alpine
RUN apk add --no-cache bash git python3 zbar jpeg-dev zlib-dev python3-dev
RUN pip3 install flask alembic
RUN mkdir /TelegramEDT
RUN git clone https://github.com/flifloo/TelegramEDT.git /TelegramEDT
RUN apk add --no-cache --virtual .build-deps build-base linux-headers
RUN pip3 install -r /TelegramEDT/requirements.txt
RUN apk del .build-deps
COPY ./app.py /root/app.py
CMD python3 /root/app.py

47
app.py Normal file
View file

@ -0,0 +1,47 @@
from flask import Flask, request, abort, request
from subprocess import run, Popen
import hmac
import hashlib
from os import environ
from os.path import isdir, isfile
from os import mkdir
from sqlite3 import connect
if not isdir("/TelegramEDT/.git"):
run(["git", "clone", "https://github.com/flifloo/TelegramEDT.git", "/TelegramEDT"])
if (not isdir("/TelegramEDT/alembic")) and isfile("/TelegramEDT/edt.db"):
c = connect("/TelegramEDT/edt.db")
c.execute("delete from alembic_version;")
c.commit()
app = Flask(__name__)
webhook_secret = environ.get("webhook_secret")
bot = Popen(["python3", "main.py"], cwd="/TelegramEDT/")
@app.route("/git", methods=["POST"])
def git():
if not "X-Hub-Signature" in request.headers:
abort(400)
request.get_data()
signature = request.headers['X-Hub-Signature']
payload = request.data
secret = webhook_secret.encode()
hmac_gen = hmac.new(secret, payload, hashlib.sha1)
digest = "sha1=" + hmac_gen.hexdigest()
if signature != digest:
abort(400)
global bot
bot.kill()
run(["git", "pull"], cwd="/TelegramEDT/")
run(["bash", "./update.sh"], cwd="/TelegramEDT/")
bot = Popen(["python3", "main.py"], cwd="/TelegramEDT/")
return "Ok"
if __name__ == "__main__":
app.run(host="0.0.0.0")

11
docker-compose.yml Normal file
View file

@ -0,0 +1,11 @@
version: '3'
services:
bot:
build: .
ports:
- "5002:5000"
volumes:
- /home/docker/TelegramEDT/TelegramEDT:/TelegramEDT
env_file:
- webhook_secret.env