From 03496f5d448a9fc79392644da51e1cba805059a1 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 23 Feb 2021 22:19:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B8=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 6 ++++-- install.sh | 40 ++++++++++++++++++++++++++++++++++++++++ setenv.py | 10 ++++++---- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100755 install.sh diff --git a/docker-compose.yml b/docker-compose.yml index 24e0f4f..9372eee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,12 @@ version: '3' services: app: + image: kylmakalle/tgvkbot:latest + container_name: tgvkbot logging: options: max-size: "10M" max-file: "10" - image: kylmakalle/tgvkbot:latest restart: always env_file: - env_file @@ -17,6 +18,7 @@ services: - db db: image: postgres:9-alpine + container_name: tgvkbot_db volumes: - "dbdata:/var/lib/postgresql/data" restart: always @@ -25,4 +27,4 @@ services: POSTGRES_PASSWORD: 'postgres' volumes: - dbdata: \ No newline at end of file + dbdata: diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..a2804cf --- /dev/null +++ b/install.sh @@ -0,0 +1,40 @@ +sudo true + +if [ ! `which docker` ]; then + echo "🔨 Устанавливаем docker..." + # Alternatively you can use the official docker install script + wget -qO- https://get.docker.com/ | sh +fi + +if [ ! `which docker-compose` ]; then + echo "🔨 Устанавливаем docker-compose..." + # Install docker-compose + COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oE "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort --version-sort | tail -n 1` + sudo sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose" + sudo chmod +x /usr/local/bin/docker-compose + sudo sh -c "curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose" +fi + + +echo "⚙️ Настраиваем переменные окружения..." +python3 set_env.py + +if [ ! "$(docker ps -a | grep )" ]; then + echo "🔄 Поднимаем систему обновлений..." + docker run -d \ + --name watchtower \ + --restart always \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -e TZ='Europe/Moscow' \ + -e WATCHTOWER_CLEANUP='true' \ + -e WATCHTOWER_INCLUDE_STOPPED='true' \ + -e WATCHTOWER_MONITOR_ONLY='false' \ + -e WATCHTOWER_LABEL_ENABLE='true' \ + containrrr/watchtower:latest +fi + +echo "🚀 Запускаем бота..." +docker-compose up -d + +echo "✅ Готово" + diff --git a/setenv.py b/setenv.py index 3fc7823..b3ebde2 100644 --- a/setenv.py +++ b/setenv.py @@ -1,7 +1,8 @@ -from config import API_VERSION, VK_APP_ID -from urllib.request import urlopen, Request from urllib.error import HTTPError from urllib.parse import urlencode +from urllib.request import urlopen, Request + +from config import API_VERSION, VK_APP_ID ENV_FILE_TEMPLATE = """ POSTGRES_DB=tgvkbot @@ -56,9 +57,10 @@ def set_env(): break except HTTPError: print('❌ VK APP ID неверный, попробуйте снова!') - + with open('env_file', 'w') as env_file: - env_file.write(ENV_FILE_TEMPLATE % {'tg_token': tg_token, 'vk_app_id': vk_app_id or VK_APP_ID}, 'allowed_user_ids': '') + env_file.write(s + ENV_FILE_TEMPLATE % {'tg_token': tg_token, 'vk_app_id': vk_app_id or VK_APP_ID, 'allowed_user_ids': ''}) print('✅ Успешно!')