diff --git a/docker/Dockerfile.dev.api b/docker/Dockerfile.dev.api index 5b3f12b70..76a323844 100644 --- a/docker/Dockerfile.dev.api +++ b/docker/Dockerfile.dev.api @@ -22,5 +22,6 @@ ENV PYTHONPATH="/app:${PYTHONPATH}" ENV PATH="/venv/bin:${PATH}" ENV VIRTUAL_ENV="/venv" +ENTRYPOINT ["/app/keep/entrypoint_backend.sh"] CMD ["gunicorn", "keep.api.api:get_app", "--bind" , "0.0.0.0:8080" , "--workers", "1" , "-k" , "uvicorn.workers.UvicornWorker", "-c", "./keep/api/config.py", "--reload"] diff --git a/keep/api/config.py b/keep/api/config.py index 474206812..c73222e31 100644 --- a/keep/api/config.py +++ b/keep/api/config.py @@ -57,12 +57,3 @@ def on_starting(server=None): os.environ["KEEP_API_URL"] = public_url logger.info("Keep server started") - - launch_uptime_reporting() - - if LIVE_DEMO_MODE: - logger.info("Launching Keep in demo mode.") - from keep.api.core.demo_mode_runner import launch_demo_mode - launch_demo_mode() - else: - logger.info("Not launching Keep in demo mode.") diff --git a/keep/api/core/demo_mode_runner.py b/keep/api/core/demo_mode_runner.py index 095c02f6c..b3edac446 100644 --- a/keep/api/core/demo_mode_runner.py +++ b/keep/api/core/demo_mode_runner.py @@ -17,18 +17,11 @@ from keep.api.tasks.process_topology_task import process_topology from keep.api.utils.tenant_utils import get_or_create_api_key from keep.providers.providers_factory import ProvidersFactory -# import json logging.config.dictConfig(CONFIG) logger = logging.getLogger(__name__) -# file_path = '/Users/matvey/Desktop/keep-oss/keep/pr.json' -# def read_json_file(file_path): -# with open(file_path, 'r') as file: -# return json.load(file) -# pr_json = read_json_file(file_path) - correlation_rules_to_create = [ { "sqlQuery": {"sql": "((name like :name_1))", "params": {"name_1": "%mq%"}}, @@ -353,7 +346,6 @@ def simulate_alerts( time.sleep(5) existing_installed_providers = get_existing_installed_providers(keep_api_key, keep_api_url) - # existing_installed_providers = pr_json['installed_providers'] logger.info(f"Existing installed providers: {existing_installed_providers}") existing_providers_to_their_ids = {} for existing_provider in existing_installed_providers: diff --git a/keep/cli/cli.py b/keep/cli/cli.py index e0c0ad87f..1a989e6f1 100644 --- a/keep/cli/cli.py +++ b/keep/cli/cli.py @@ -4,6 +4,7 @@ import os import sys import typing +import time import uuid from collections import OrderedDict from importlib import metadata @@ -1627,5 +1628,14 @@ def start(self): os._exit(0) +@cli.command() +@pass_info +def background_server_jobs(info: Info): + """Run background jobs, expected to be running in parallel with the server.""" + while True: + time.sleep(1) + logger.info("Background job running") + logger.info(os.environ) + if __name__ == "__main__": cli(auto_envvar_prefix="KEEP") diff --git a/keep/entrypoint_backend.sh b/keep/entrypoint_backend.sh new file mode 100755 index 000000000..65f4eef72 --- /dev/null +++ b/keep/entrypoint_backend.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Exit immediately if a command exits with a non-zero status +set -e + +# Print commands and their arguments as they are executed +set -x + +# Execute background taasks +poetry run python keep/cli/cli.py background-server-jobs & + +# Execute the CMD provided in the Dockerfile or as arguments +exec "$@" \ No newline at end of file