Use 2 docker containers for bot and webservice

This commit is contained in:
2022-03-12 20:02:39 +01:00
parent 5002d8509b
commit fdd7bc2d4c
14 changed files with 48 additions and 16 deletions

19
webservice/Dockerfile Normal file
View File

@@ -0,0 +1,19 @@
FROM python:3.10-alpine
WORKDIR /srv/flask_app
RUN apk add nginx build-base libffi-dev curl uwsgi
COPY requirements.txt /srv/flask_app/
RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location
COPY .. /srv/flask_app
COPY deploy/nginx.conf /etc/nginx
RUN chmod +x ./deploy/start.sh
RUN chmod +x ./deploy/healthcheck.sh
HEALTHCHECK --interval=15s --timeout=2s CMD ["./deploy/healthcheck.sh"]
EXPOSE 80
CMD ["./deploy/start.sh"]

25
webservice/app.py Normal file
View File

@@ -0,0 +1,25 @@
import multiprocessing as mp
import time
from flask import Flask
from telegram_bot.bot import bot
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
proc1 = mp.Process(target=app.run, args=())
proc1.start()
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
print(f"[EXCEPTION] {e}")
time.sleep(15)

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
curl -s http://localhost:80/ -o /dev/null || exit 1

View File

@@ -0,0 +1,41 @@
user root;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name homeserver.flokaiser.com;
root /var/www/html;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.socket;
uwsgi_read_timeout 1h;
uwsgi_send_timeout 1h;
proxy_send_timeout 1h;
proxy_read_timeout 1h;
}
}
}

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
nginx -g "daemon off;" &
uwsgi --ini deploy/uwsgi.ini

View File

@@ -0,0 +1,12 @@
[uwsgi]
module = app:app
uid = root
gid = root
master = true
processes = 5
socket = /tmp/uwsgi.socket
chmod-sock = 664
vacuum = true
die-on-term = true

View File

@@ -0,0 +1,4 @@
Flask~=2.0.3
python-dotenv==0.19.2
requests==2.27.1
uwsgi==2.0.20