From e363e6be4a2fa68818056386d0b46060a2a34357 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Mon, 27 May 2024 10:26:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20=E2=80=94=20Document=20better=20?= =?UTF-8?q?how=20to=20deploy=20with=20gunicorn=20(fix=20#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/installation/getting-started.md | 43 +++++++++++++++++++++++++++- docs/installation/tl-dr.md | 7 +++-- pyproject.toml | 4 ++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/docs/installation/getting-started.md b/docs/installation/getting-started.md index 35a938f..abac017 100644 --- a/docs/installation/getting-started.md +++ b/docs/installation/getting-started.md @@ -14,12 +14,19 @@ pip install argos-monitoring ``` You may want to install Argos in a virtualenv: + ```bash python3 -m venv venv source venv/bin/activate pip install argos-monitoring ``` +For production, we recommend the use of [Gunicorn](https://gunicorn.org/), which you can install at the same time as Argos: + +```bash +pip install argos-monitoring[gunicorn] +``` + ## Install from sources Once you got the source locally, create a virtualenv and install the dependencies: @@ -78,7 +85,41 @@ Then you can start the server: argos server start ``` -The server reads the `yaml` file at startup, and populates the tasks queue with the checks defined in the configuration. +The server reads the `yaml` file at startup, and populates the tasks queue with the checks defined in the configuration. + +This way to start the server is not suitable for production, use it only for developing or testing. + +## Starting the server for production + +For production, you can use [Gunicorn](https://gunicorn.org/) to start the server. + +To install Gunicorn in the virtualenv, if you didn’t already install Argos that way: + +```bash +pip install argos-monitoring[gunicorn] +``` + +To start the server: + +```bash +gunicorn "argos.server.main:get_application()" -k uvicorn.workers.UvicornWorker +``` + +There is some gunicorn’s options that you should use: +- `-w INT, --workers INT`: the number of worker processes for handling requests. Default is `1`. +- `-b ADDRESS, --bind ADDRESS`: the socket to bind. Default is `127.0.0.1:8000`. +- `--forwarded-allow-ips STRING`: front-end's IPs from which allowed to handle set secure headers as a comma-separated list. Default is `127.0.0.1`. + +So, to start the server with 4 workers while listening to `127.0.0.1:8001`: + +```bash +gunicorn "argos.server.main:get_application()" -k uvicorn.workers.UvicornWorker -w 4 -b 127.0.0.1:8001 +``` + +Gunicorn has a lot of other options, have a look at `gunicorn --help`. + +Argos uses FastAPI, so you can use other ways to start the server. +See (but Gunicorn is recommended). ## Generating a token diff --git a/docs/installation/tl-dr.md b/docs/installation/tl-dr.md index 7a04f77..9fee33a 100644 --- a/docs/installation/tl-dr.md +++ b/docs/installation/tl-dr.md @@ -13,7 +13,7 @@ cd /tmp/argos python3 -m venv venv source venv/bin/activate pip install argos-monitoring -argos server generate-config > config.yaml +argos server generate-config > argos-config.yaml argos server migrate argos server generate-token ``` @@ -50,10 +50,11 @@ adduser --home /opt/argos --disabled-login --disabled-password --system argos cd /opt/argos python3 -m venv venv chown argos: -R venv -sudo -u argos bash -c "source venv/bin/activate && pip install argos-monitoring" +sudo -u argos bash -c "source venv/bin/activate && pip install argos-monitoring[gunicorn]" mkdir /etc/argos -wget https://framagit.org/framasoft/framaspace/argos/-/raw/main/conf/config-example.yaml -O /etc/argos/config.yaml +/opt/argos/venv/bin/argos server generate-config > /etc/argos/config.yaml + cat < /etc/default/argos-server ARGOS_YAML_FILE="/etc/argos/config.yaml" ARGOS_DATABASE_URL="postgresql://argos:THE_DB_PASSWORD@localhost/argos" diff --git a/pyproject.toml b/pyproject.toml index fa193fa..231886e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ dependencies = [ "alembic>=1.13.0,<1.14", "click>=8.1,<9", "fastapi>=0.103,<0.104", - "gunicorn>=21.2,<22", "httpx>=0.25,<1", "Jinja2>=3.0,<4", "psycopg2-binary>=2.9,<3", @@ -62,6 +61,9 @@ docs = [ "sphinx>=7,<8", "sphinxcontrib-mermaid>=0.9,<1", ] +gunicorn = [ + "gunicorn>=21.2,<22", +] [project.urls] homepage = "https://framasoft.frama.io/framaspace/argos/"