diff --git a/Makefile b/Makefile index 14f40e4b1dc8d3707175f25862b4bf6fc010458b..18f0a0e660dbf447e9a7b61ce29bec123175a67e 100644 --- a/Makefile +++ b/Makefile @@ -23,11 +23,11 @@ _run_local: @docker-compose up -d ## Runs application. Builds, creates, starts, and attaches to containers for a service. | Common -run: _run_local service_wait migrate +run: _run_local service_wait @docker-compose logs -f -prod: service service_wait migrate +prod: service service_wait @docker-compose -f docker-compose.prod.yml logs -f ## Clean all containers @@ -61,7 +61,7 @@ migrations: ## Upgrades database. migrate: - @docker exec -i telegram_system_bot alembic upgrade head; + @docker exec -i telegram_system_bot alembic upgrade head ## Waits postgresql to be online wait_resources: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index aec3e5057c0c12f6d4f24a5d0836b9896c72e485..e0e1c50f1ba4a893ab8ee6172bc49f0875a459f9 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -7,6 +7,7 @@ networks: services: system_bot: + restart: always container_name: 'telegram_system_bot' build: . env_file: @@ -29,6 +30,7 @@ services: - system_bot_postgres system_bot_postgres: + restart: always container_name: 'system_bot_postgres' image: 'postgres:11.6-alpine' environment: diff --git a/src/actions/__init__.py b/src/actions/__init__.py index 4627ed13cecb69fab73a79d42a634c3d014c90ec..3d6bdce5688a4ff2836c1441435a57f872370597 100644 --- a/src/actions/__init__.py +++ b/src/actions/__init__.py @@ -1,3 +1,5 @@ +import os + from .basic_actions import * from .docker import * from .interactive_session import * @@ -10,6 +12,8 @@ from ..models.crud.server_crud import fn_get_all_chat_ids async def notify_about_updates(): + if not os.path.exists('app.info'): + return with open('app.info') as f: app_info = f.read() for chat_id in await fn_get_all_chat_ids(settings.engine): diff --git a/src/utils/wait_script.py b/src/utils/wait_script.py index 8672ea7c42d3f5506701fb9f0168628bd30e6b77..3f7a1793cd9495a9d6cae3c7dbbc466c913239ce 100644 --- a/src/utils/wait_script.py +++ b/src/utils/wait_script.py @@ -2,8 +2,12 @@ import random import socket import time +import alembic.config + from src.settings import settings +alembicArgs = ['--raiseerr', 'upgrade', 'head'] + if __name__ == "__main__": postgres_connected = "FAILED" while True: @@ -11,6 +15,7 @@ if __name__ == "__main__": with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((settings.postgres_host, settings.postgres_port)) print("[ OK ] Connect to postgres") + alembic.config.main(argv=alembicArgs) break except socket.error: print(f"[FAILED] Connect to postgres")