From 2bd9452945171b57a3fa9b66cc6644991e22a810 Mon Sep 17 00:00:00 2001 From: Blai Peidro Date: Sat, 28 Nov 2026 20:45:51 +0100 Subject: [PATCH] feat: the RTE is the Go Runner, each job in a container of its own --- .env | 9 ++++++++ .github/workflows/ci.yml | 8 +++++++ .gitignore | 4 +++- README.md | 21 +++++++++++------ data/python/.gitkeep | 0 docker-compose.yml | 49 ++++++++++++++++++++++++---------------- 6 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 data/python/.gitkeep diff --git a/.env b/.env index 94ef547..456632f 100644 --- a/.env +++ b/.env @@ -291,6 +291,15 @@ RTE_TOKEN=AnsibleForms!RTE!Token!123 # with HOME_PATH. HOME_DIR=/home/node +# The RTE Runner starts each job in a container of its own, through the engine's socket: +# docker or podman, and the socket's path on this host +RTE_ENGINE=docker +ENGINE_SOCKET=/var/run/docker.sock +# the socket's group, which the Runner joins to use it: stat -c %g /var/run/docker.sock +ENGINE_SOCKET_GID=0 +# the user the Runner runs as: 1000 ; 0 with rootless Podman (its root is the user running Podman) +RTE_USER=1000 + # Home directory the app uses for its SSH key and git connections # Default: OS home directory (/home/node in the image) # HOME_PATH=/home/node diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a311f3..d2aaf72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,14 @@ jobs: - name: Give the containers the data folder run: sudo chown -R 1000:1000 data + # the Runner joins the socket's group to start the jobs' containers (README.md) + - name: Give the Runner the engine's socket + run: sed -i "s/^ENGINE_SOCKET_GID=.*/ENGINE_SOCKET_GID=$(stat -c %g /var/run/docker.sock)/" .env + + # the jobs' image, pulled before the first job rather than during it + - name: Pull the jobs' image + run: docker pull ghcr.io/ansibleforms/ansibleforms-rte-full:7 + - name: Start the stack run: docker compose up -d diff --git a/.gitignore b/.gitignore index 9177259..5c38ded 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,9 @@ data/form_backups/ data/forms_backups/ data/forms_staging/ data/uploads/ -data/python/ +# the libraries the pip install playbook adds (its folder kept, for the jobs' mount) +data/python/* +!data/python/.gitkeep # The RTE's job spool and the files cache of RTE_FILES=transfer (created in either mode) data/rte-spool/ data/rte-files/ diff --git a/README.md b/README.md index 892e15b..0d4ad37 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ of `.env`. While that is still the public default, `AnsibleForms!123`, the app f git clone https://github.com/ansibleforms/docker.git ansibleforms cd ansibleforms sudo chown -R 1000:1000 data +sed -i "s/^ENGINE_SOCKET_GID=.*/ENGINE_SOCKET_GID=$(stat -c %g /var/run/docker.sock)/" .env docker compose up -d ``` The app and the RTE run as the user `node` (uid 1000), so they need to own `data/`: that is what the `chown` is for. +The RTE starts each job's container through Docker's socket, so it joins the socket's group: that is what the `sed` is for. Coming from 6, whose container ran as root, run the same `chown` once before you start 7; MySQL takes its own folder back when it starts. ## What you get @@ -44,7 +46,7 @@ Everything under `data/` is mounted into the containers and survives a restart o - A demo `config.yaml` with categories, roles and constants, and sample forms - Sample maintenance playbooks and a `dummy.yaml` playbook - Sample custom JavaScript functions and jq definitions to extend AnsibleForms -- An RTE container that runs the playbooks, with ansible, Python 3 and a set of Galaxy collections +- An RTE Runner that runs each playbook in a container of its own, with ansible, Python 3 and a set of Galaxy collections - A config seed, `data/seed.yaml`, that registers the RTE as the default runner ## Database @@ -80,14 +82,19 @@ first start with 9.7, as MySQL supports moving to the next LTS, once these steps ## Running playbooks -AnsibleForms 7 runs no playbook in the app: the `rte` container runs them, from -`ghcr.io/ansibleforms/ansibleforms-rte-full:7`. The app dials it on `http://rte:8000` with `RTE_TOKEN` from `.env` and keeps -one WebSocket open (`RTE_MODE=inbound`): the RTE gets no database credentials, and is not published on the host. +AnsibleForms 7 runs no playbook in the app: the `rte` container, the [RTE Runner](https://github.com/ansibleforms/runner), +starts each job in a container of its own from `ghcr.io/ansibleforms/ansibleforms-rte-full:7` (`RTE_IMAGE`). The app dials it +on `http://rte:8000` with `RTE_TOKEN` from `.env` and keeps one WebSocket open (`RTE_MODE=inbound`): the RTE gets no database +credentials, and is not published on the host. + +It starts the jobs through the engine's socket (`ENGINE_SOCKET` in `.env`), which gives it that engine's full rights on this +host. With Podman, set `RTE_ENGINE=podman` and `ENGINE_SOCKET` to Podman's socket (`/run/podman/podman.sock`, or +`/run/user//podman/podman.sock` rootless, with `RTE_USER=0`). `data/seed.yaml` registers it as the default runner on every start, so it is read-only under Connections > Runners. -Ansible settings, roles and collections under `data/ansible/` are mounted into the RTE, not the app. When your -playbooks need more, build an image FROM `ansibleforms-rte-core` or `ansibleforms-rte-full` and point the `rte` service -at it: the app's [examples/rte](https://github.com/ansibleforms/ansibleforms/tree/main/examples/rte) shows how. +Ansible settings, roles and collections under `data/ansible/`, the SSH key and the libraries the pip install playbook adds +are mounted into every job (`RTE_JOB_MOUNTS`), not the app. When your playbooks need more, build an image FROM +`ansibleforms-rte-core` or `ansibleforms-rte-full` and set it as `RTE_IMAGE`: [ansibleforms/rte](https://github.com/ansibleforms/rte/tree/main/examples) shows how. ## Several nodes diff --git a/data/python/.gitkeep b/data/python/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml index 2568453..b43000b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,17 +77,24 @@ services: - ./data/functions/custom.js:/app/dist/src/functions/custom.js # custom JavaScript functions (fnc.*) - ./data/functions/jq.custom.definitions:/app/dist/src/functions/jq.custom.definitions # custom jq definitions # - ./data/assets/images:/app/dist/views/img # 6 custom images (login_background_%theme%.jpg and logo_%theme%.svg | 2 for each theme = light, dark and color) - # AnsibleForms RTE (runtime environment): runs the playbooks. AnsibleForms 7 runs none in - # the app itself, so this is where ansible, the Python libraries and the collections live. - # The app dials it on http://rte:8000 with RTE_TOKEN (RTE_MODE=inbound) and keeps one WebSocket - # open : the RTE holds no database credentials and is not published on the host. + # AnsibleForms RTE Runner: runs the playbooks. AnsibleForms 7 runs none in the app itself. + # The Runner (written in Go) starts each job in a container of its own, from RTE_IMAGE (python, + # ansible and the collections), through the engine's socket mounted below : that socket gives + # it the engine's full rights on this host. The app dials it on http://rte:8000 with RTE_TOKEN + # (RTE_MODE=inbound) and keeps one WebSocket open : it holds no database credentials and is not + # published on the host. rte: - image: ghcr.io/ansibleforms/ansibleforms-rte-full:7 + image: ghcr.io/ansibleforms/ansibleforms-rte-runner:7 container_name: af_rte restart: unless-stopped - # Healthy once the RTE takes connections on its port (its socket needs the token) + # uid 1000 in the engine socket's group (ENGINE_SOCKET_GID in .env) ; with rootless Podman, + # RTE_USER=0, the container's root being the user who runs Podman + user: "${RTE_USER:-1000}" + group_add: + - "${ENGINE_SOCKET_GID:-0}" + # Healthy once it takes connections on its port (its socket needs the token) healthcheck: - test: ["CMD", "node", "./healthcheck.js"] + test: ["CMD", "ansibleforms-rte-runner", "health"] interval: 10s timeout: 5s retries: 30 @@ -95,26 +102,28 @@ services: # Only what the RTE needs : not the .env, which holds the database's passwords environment: # The app dials it (data/seed.yaml declares its runner, rte_mode inbound) - - NODE_ENV=production - RTE_MODE=inbound - RTE_TOKEN=$RTE_TOKEN - # Its files are the app's own (./data, mounted below) : nothing to send with each job + # Its files are the app's own (./data, mounted below) : it hands each job its folders - RTE_FILES=local - PORT=8000 # Only the app calls it, inside the compose network - HTTPS=0 - LOG_LEVEL=$LOG_LEVEL - - LOG_CONSOLE_LEVEL=$LOG_CONSOLE_LEVEL - - LOG_TZ=${LOG_TZ:-UTC} - # The playbook output it stores per stream, in bytes (read by the RTE, not the app) + - TZ=${LOG_TZ:-UTC} + # The playbook output it stores per stream, in bytes - PROCESS_MAX_BUFFER=${PROCESS_MAX_BUFFER:-52428800} - # The libraries the ansibleforms_pip_install playbook installs into the persistent folder + # Where the jobs run : the engine and its socket (mounted below), and the image they run + - RTE_ENGINE=${RTE_ENGINE:-docker} + - RTE_ENGINE_SOCKET=/run/engine.sock + - RTE_IMAGE=ghcr.io/ansibleforms/ansibleforms-rte-full:7 + # What every job gets from ./data, as the playbooks had it in the RTE before : the ansible.cfg, + # roles and collections, the SSH key and the git settings, and the libraries the + # ansibleforms_pip_install playbook installs (PYTHONPATH) + - RTE_JOB_MOUNTS=/app/dist/persistent/ansible/ansible.cfg:/etc/ansible/ansible.cfg,/app/dist/persistent/ansible/roles:/etc/ansible/roles,/app/dist/persistent/ansible/collections:/etc/ansible/collections,/app/dist/persistent/ssh:/home/node/.ssh:rw,/app/dist/persistent/git/.gitconfig:/home/node/.gitconfig,/app/dist/persistent/python:/app/dist/persistent/python:rw - PYTHONPATH=/app/dist/persistent/python/lib volumes: - # The same folders as the app: playbooks, repositories, uploads and the SSH key - - ./data:/app/dist/persistent # persistent app data - - ./data/ssh:$HOME_DIR/.ssh # persistent ssh keys - - ./data/git/.gitconfig:$HOME_DIR/.gitconfig # custom git config - - ./data/ansible/ansible.cfg:/etc/ansible/ansible.cfg # custom ansible.cfg - - ./data/ansible/roles:/etc/ansible/roles # custom ansible roles - - ./data/ansible/collections:/etc/ansible/collections # custom ansible collections + # The app's folders : playbooks, repositories, uploads, the SSH key, the ansible settings + - ./data:/app/dist/persistent + # The engine's socket on this host (ENGINE_SOCKET in .env) + - ${ENGINE_SOCKET:-/var/run/docker.sock}:/run/engine.sock