Add Python Runner service and documentation

- Introduced a new internal utility service, python-runner, in docker-compose.yml to execute custom Python scripts within the Docker network.
- Added detailed documentation in n8n-installer-developer-guide.md and README.md on how to enable and use the python-runner service.
- Created main.py and requirements.txt files for user-defined Python code and dependencies.
- Updated scripts to include python-runner in the service selection wizard and final report for improved user guidance.
This commit is contained in:
Yury Kossakovsky
2025-08-15 16:35:13 -06:00
parent 7062697b96
commit 7037b203bb
7 changed files with 82 additions and 0 deletions

View File

@@ -141,6 +141,13 @@ After successful installation, your services are up and running! Here's how to g
- **Portainer:** `portainer.yourdomain.com` (Protected by Caddy basic auth; on first login, complete Portainer admin setup)
- **ComfyUI:** `comfyui.yourdomain.com` (Node-based Stable Diffusion UI)
### Optional Internal Utility: Python Runner
- **What it is**: An internal-only service to run your custom Python code inside the same Docker network as your other services (n8n, Postgres, Qdrant, etc.). No external ports are exposed, and it is not proxied by Caddy.
- **How to enable**: Select “Python Runner” in the Service Selection Wizard during install/update, or add the profile manually: `COMPOSE_PROFILES=...,python-runner`.
- **Where to put code**: Place your Python files in `python-runner/`. The default entry point is `python-runner/main.py`.
- **Dependencies**: Add them to `python-runner/requirements.txt`; they will be installed automatically on container start.
2. **Explore n8n:**
- Log in to your n8n instance. This is your central hub for workflow automation.

View File

@@ -609,3 +609,13 @@ services:
interval: 10s
timeout: 5s
retries: 5
python-runner:
image: python:3.11-slim
container_name: python-runner
profiles: ["python-runner"]
restart: unless-stopped
working_dir: /app
command: /bin/sh -c 'if [ -f /app/requirements.txt ]; then python -m pip install --no-cache-dir -r /app/requirements.txt; fi; python /app/main.py'
volumes:
- ./python-runner:/app

View File

@@ -305,6 +305,56 @@ volumes:
---
## 🐍 Internal Utility Service: python-runner (Optional)
**Purpose**: Lightweight internal container to run custom user Python scripts inside the compose network without exposing any ports.
- **Image**: `python:3.11-slim`
- **Profiles**: `python-runner` (disabled by default; enabled via wizard or `.env`)
- **Mount**: `./python-runner:/app`
- **Command**: Installs `requirements.txt` if present, then runs `python /app/main.py`.
- **Network**: Joins the default compose network (`localai_default`), so it can reach other services by their container names (e.g., `n8n`, `postgres`, `redis`, `qdrant`).
- **Security/Exposure**: No external ports, no reverse proxy, no domains. Internal-only.
### How to enable (Wizard)
- Run `sudo bash ./scripts/install.sh` (initial) or `sudo bash ./scripts/update.sh` (update) and select **Python Runner** in the wizard.
### How to enable (manually)
Add the profile to `.env` so it is managed by the normal startup flow:
```bash
COMPOSE_PROFILES="...,python-runner"
```
Or start on-demand from the CLI without changing `.env`:
```bash
docker compose -p localai --profile python-runner up -d python-runner
```
### Where to put your code
- Local path: `python-runner/`
- Entry file: `python-runner/main.py`
- Optional deps: `python-runner/requirements.txt` (installed automatically on container start)
### Developing and running your script
1) Edit `python-runner/main.py` with your logic. Example: connect to `postgres` using the hostname `postgres` and credentials from `.env`.
2) Add dependencies to `python-runner/requirements.txt` if needed.
3) Start or restart the service:
```bash
docker compose -p localai --profile python-runner up -d --force-recreate python-runner
```
4) View logs:
```bash
docker compose -p localai logs -f python-runner
```
This service is intentionally minimal to avoid conflicts and can be extended by users as needed.
---
## 🌐 Network Architecture
### **Caddyfile Configuration**

3
python-runner/main.py Normal file
View File

@@ -0,0 +1,3 @@
print("Python runner is up!")

View File

View File

@@ -66,6 +66,7 @@ base_services_data=(
"ragapp" "RAGApp (Open-source RAG UI + API)"
"open-webui" "Open WebUI (ChatGPT-like Interface)"
"searxng" "SearXNG (Private Metasearch Engine)"
"python-runner" "Python Runner (Run your custom Python code from ./python-runner)"
"ollama" "Ollama (Local LLM Runner - select hardware in next step)"
"comfyui" "ComfyUI (Node-based Stable Diffusion UI)"
)

View File

@@ -187,6 +187,17 @@ if is_profile_active "gotenberg"; then
echo " Office to PDF: POST /forms/libreoffice/convert"
fi
if is_profile_active "python-runner"; then
echo
echo "================================= Python Runner ========================"
echo
echo "Internal Container DNS: python-runner"
echo "Mounted Code Directory: ./python-runner (host) -> /app (container)"
echo "Entry File: /app/main.py"
echo "(Note: Internal-only service with no exposed ports; view output via logs)"
echo "Logs: docker compose -p localai logs -f python-runner"
fi
if is_profile_active "n8n" || is_profile_active "langfuse"; then
echo
echo "================================= Redis (Valkey) ======================"