From fdd7bc2d4c84598b86568986cf139d62e18f511b Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Sat, 12 Mar 2022 20:02:39 +0100 Subject: [PATCH] Use 2 docker containers for bot and webservice --- .drone.yml | 21 +++++++++++++++---- deploy/start.sh | 5 ----- telegram_bot/Dockerfile | 17 +++++++++++++++ bot.py => telegram_bot/bot.py | 0 .../deploy}/healthcheck.sh | 0 telegram_bot/deploy/start.sh | 2 ++ telegram_bot/requirements.txt | 1 + Dockerfile => webservice/Dockerfile | 2 +- app.py => webservice/app.py | 2 +- webservice/deploy/healthcheck.sh | 2 ++ {deploy => webservice/deploy}/nginx.conf | 0 webservice/deploy/start.sh | 3 +++ {deploy => webservice/deploy}/uwsgi.ini | 0 .../requirements.txt | 9 ++++---- 14 files changed, 48 insertions(+), 16 deletions(-) delete mode 100644 deploy/start.sh create mode 100644 telegram_bot/Dockerfile rename bot.py => telegram_bot/bot.py (100%) rename {deploy => telegram_bot/deploy}/healthcheck.sh (100%) create mode 100644 telegram_bot/deploy/start.sh create mode 100644 telegram_bot/requirements.txt rename Dockerfile => webservice/Dockerfile (94%) rename app.py => webservice/app.py (92%) create mode 100644 webservice/deploy/healthcheck.sh rename {deploy => webservice/deploy}/nginx.conf (100%) create mode 100644 webservice/deploy/start.sh rename {deploy => webservice/deploy}/uwsgi.ini (100%) rename requirements.txt => webservice/requirements.txt (55%) diff --git a/.drone.yml b/.drone.yml index a16f074..2c4ae1d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: linux-amd64 platform: arch: amd64 os: linux - + steps: - name: generate_tag image: golang @@ -13,7 +13,7 @@ steps: - echo -n "${DRONE_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}, latest" > .tags -- name: publish +- name: publish_webservice image: plugins/docker settings: username: @@ -23,8 +23,21 @@ steps: registry: from_secret: registry repo: - from_secret: repo - dockerfile: Dockerfile + from_secret: repo_webservice + dockerfile: webservice/Dockerfile + +- name: publish_bot + image: plugins/docker + settings: + username: + from_secret: username + password: + from_secret: password + registry: + from_secret: registry + repo: + from_secret: repo_bot + dockerfile: telegram_bot/Dockerfile - name: deploy image: appleboy/drone-ssh diff --git a/deploy/start.sh b/deploy/start.sh deleted file mode 100644 index 5090c1c..0000000 --- a/deploy/start.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh -#nginx -g "daemon off;" & -#uwsgi --ini deploy/uwsgi.ini - -python3 app.py \ No newline at end of file diff --git a/telegram_bot/Dockerfile b/telegram_bot/Dockerfile new file mode 100644 index 0000000..e22afcf --- /dev/null +++ b/telegram_bot/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.10-alpine + +WORKDIR /srv/flask_app + +COPY requirements.txt /srv/flask_app/ + +RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location + +COPY .. /srv/flask_app +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"] diff --git a/bot.py b/telegram_bot/bot.py similarity index 100% rename from bot.py rename to telegram_bot/bot.py diff --git a/deploy/healthcheck.sh b/telegram_bot/deploy/healthcheck.sh similarity index 100% rename from deploy/healthcheck.sh rename to telegram_bot/deploy/healthcheck.sh diff --git a/telegram_bot/deploy/start.sh b/telegram_bot/deploy/start.sh new file mode 100644 index 0000000..4ee7078 --- /dev/null +++ b/telegram_bot/deploy/start.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +python bot.py \ No newline at end of file diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt new file mode 100644 index 0000000..c26829a --- /dev/null +++ b/telegram_bot/requirements.txt @@ -0,0 +1 @@ +pyTelegramBotAPI~=4.4.0 \ No newline at end of file diff --git a/Dockerfile b/webservice/Dockerfile similarity index 94% rename from Dockerfile rename to webservice/Dockerfile index 22210e9..5abea66 100644 --- a/Dockerfile +++ b/webservice/Dockerfile @@ -7,7 +7,7 @@ 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 .. /srv/flask_app COPY deploy/nginx.conf /etc/nginx RUN chmod +x ./deploy/start.sh RUN chmod +x ./deploy/healthcheck.sh diff --git a/app.py b/webservice/app.py similarity index 92% rename from app.py rename to webservice/app.py index 14d7d4d..e33f017 100644 --- a/app.py +++ b/webservice/app.py @@ -3,7 +3,7 @@ import time from flask import Flask -from bot import bot +from telegram_bot.bot import bot app = Flask(__name__) diff --git a/webservice/deploy/healthcheck.sh b/webservice/deploy/healthcheck.sh new file mode 100644 index 0000000..390f507 --- /dev/null +++ b/webservice/deploy/healthcheck.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +curl -s http://localhost:80/ -o /dev/null || exit 1 diff --git a/deploy/nginx.conf b/webservice/deploy/nginx.conf similarity index 100% rename from deploy/nginx.conf rename to webservice/deploy/nginx.conf diff --git a/webservice/deploy/start.sh b/webservice/deploy/start.sh new file mode 100644 index 0000000..77fb780 --- /dev/null +++ b/webservice/deploy/start.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +nginx -g "daemon off;" & +uwsgi --ini deploy/uwsgi.ini \ No newline at end of file diff --git a/deploy/uwsgi.ini b/webservice/deploy/uwsgi.ini similarity index 100% rename from deploy/uwsgi.ini rename to webservice/deploy/uwsgi.ini diff --git a/requirements.txt b/webservice/requirements.txt similarity index 55% rename from requirements.txt rename to webservice/requirements.txt index d7858ae..011c512 100644 --- a/requirements.txt +++ b/webservice/requirements.txt @@ -1,5 +1,4 @@ -Flask~=2.0.3 -python-dotenv==0.19.2 -requests==2.27.1 -uwsgi==2.0.20 -pyTelegramBotAPI~=4.4.0 \ No newline at end of file +Flask~=2.0.3 +python-dotenv==0.19.2 +requests==2.27.1 +uwsgi==2.0.20 \ No newline at end of file