diff --git a/CveXplore/cli.py b/CveXplore/cli.py index 2f623740..d6403d20 100644 --- a/CveXplore/cli.py +++ b/CveXplore/cli.py @@ -20,12 +20,16 @@ @click.group(invoke_without_command=True) @click.option("-v", "--version", is_flag=True, help="Show the current version and exit") +@click.option("-w", "--where", is_flag=True, help="Show the path where CveXplore is installed") @click.pass_context -def main(ctx, version): +def main(ctx, version, where): ctx.obj = {"data_source": CveXplore()} if version: click.echo(ctx.obj["data_source"].version) exit(0) + elif where: + click.echo(ctx.obj["data_source"].where()) + exit(0) if ctx.invoked_subcommand is None: click.echo(main.get_help(ctx)) diff --git a/CveXplore/main.py b/CveXplore/main.py index 9bfb0416..1f907bef 100644 --- a/CveXplore/main.py +++ b/CveXplore/main.py @@ -272,6 +272,16 @@ def version(self) -> str: """ return self.__version + @staticmethod + def where() -> str: + """ + Request the path where CveXplore is installed + + Returns: + Path where CveXplore is installed + """ + return os.path.dirname(__file__) + def get_single_store_entry( self, entry_type: str, dict_filter: dict = None ) -> CveXploreObject | None: diff --git a/backend/.docker/cvexplore-backend.service b/backend/.docker/cvexplore-backend.service new file mode 100644 index 00000000..b0c4c683 --- /dev/null +++ b/backend/.docker/cvexplore-backend.service @@ -0,0 +1,17 @@ +[Unit] +Description=CveXplore Backend service +Requires=docker.service +After=docker.service + +[Service] +Restart=always +WorkingDirectory=${HOME}/.cvexplore +# Shutdown container (if running) when unit is started +ExecStartPre=/usr/bin/docker-compose -f docker-compose.yml down +# Start container when unit is started +ExecStart=/usr/bin/docker-compose -f docker-compose.yml up +# Stop container when unit is stopped +ExecStop=/usr/bin/docker-compose -f docker-compose.yml down + +[Install] +WantedBy=multi-user.target diff --git a/backend/.docker/docker-compose_example.yml b/backend/.docker/docker-compose_example.yml new file mode 100644 index 00000000..dbdefa83 --- /dev/null +++ b/backend/.docker/docker-compose_example.yml @@ -0,0 +1,48 @@ +version: '3.5' + +services: + + redis: + image: cvexplore-redis + hostname: redis + restart: always + volumes: + - redis_data:/data + ports: + - "127.0.0.1:6379:6379" + + celery_daemon: + image: cvexplore-celery_daemon + depends_on: + - redis + env_file: + - ${HOME}/.cvexplore/.env + extra_hosts: + - "host.docker.internal:host-gateway" + deploy: + replicas: 2 + restart: always + environment: + - PYTHONUNBUFFERED=TRUE + volumes: + - celery_data:/app/data + + celery_beat: + image: cvexplore-celery_beat + depends_on: + - redis + env_file: + - ${HOME}/.cvexplore/.env + extra_hosts: + - "host.docker.internal:host-gateway" + restart: always + environment: + - PYTHONUNBUFFERED=TRUE + volumes: + - celery_data:/app/data + +volumes: + celery_data: + driver: local + redis_data: + driver: local diff --git a/docker-compose.yml b/docker-compose.yml index f0293e12..1c196ec4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,6 +42,8 @@ services: - redis env_file: - ${HOME}/.cvexplore/.env + extra_hosts: + - "host.docker.internal:host-gateway" restart: always environment: - PYTHONUNBUFFERED=TRUE diff --git a/docs/backend/general.rst b/docs/backend/general.rst index 3a48e7cd..fb58c295 100644 --- a/docs/backend/general.rst +++ b/docs/backend/general.rst @@ -1,3 +1,12 @@ General ------- +The backend as referred to in this documentation consists of a celery daemon with a redis broker. +This will give CveXplore the possibility to easily create and maintain background tasks for for instance database +maintenance and re-processing of updated database entries. + +The use of this backend is **optional** and CveXplore can function perfectly without one; the tasks it performs can well +be handled by another mechanism. It is, however, a nice addition to the functionalities CveXplore offers. + +Task handling (CRUD actions en status updates) are handled via a separate class and can be controlled via package or +CLI commands. diff --git a/docs/backend/installation.rst b/docs/backend/installation.rst index 8a4858aa..5b9ed9bb 100644 --- a/docs/backend/installation.rst +++ b/docs/backend/installation.rst @@ -1,5 +1,19 @@ Installation ------------ -The backend assumes that the CveXplore package is installed; check the package :ref:`installation ` -paragraph. \ No newline at end of file +The backend assumes that the CveXplore package is installed **first**; check the package :ref:`installation ` +paragraph. + +Docker +###### + +Please ensure that you have docker and docker-compose installed before processing with the rest of this paragraph. + + + +Systemd +####### + +The backend tasks are powered by celery; please follow +`these instructions `_ if you prefer +to use systemd instead of a docker deployment diff --git a/docs/backend/settings.rst b/docs/backend/settings.rst new file mode 100644 index 00000000..00117755 --- /dev/null +++ b/docs/backend/settings.rst @@ -0,0 +1,2 @@ +Settings +-------- diff --git a/docs/index.rst b/docs/index.rst index f97b43a6..b734117b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,3 +30,4 @@ Welcome to CveXplore's documentation! /backend/general /backend/installation + /backend/settings