No description
- Python 98.3%
- HTML 1.7%
| Templates | ||
| .gitignore | ||
| config.json.example | ||
| PortainerSync.py | ||
| README.md | ||
| requirements.txt | ||
Portainer to Trilium Sync
This script synchronizes Docker Stacks from a Portainer instance to Trilium Notes. It creates a structured hierarchy of notes for each stack, including the docker-compose.yml file, .env variables, and service details.
Features
- Automated Sync: Fetches all stacks from Portainer API.
- Trilium Integration: Creates/Updates notes in Trilium using the ETAPI.
- Templates: Applies "Docker Stack Template" and "Docker Container Template" to notes.
- Host Grouping: Automatically groups stacks under a note named after the current hostname.
- Metadata: Syncs metadata such as Last Updated, Portainer ID, and Ports.
- File Sync: Syncs
docker-compose.ymland.envfiles as code notes.
Configuration
The script uses config.json for configuration.
config.json
{
"trilium_url": "https://trilium.example.com",
"etapi_token": "YOUR_TRILIUM_ETAPI_TOKEN",
"parent_note_id": "YOUR_PARENT_NOTE_ID",
"portainer_url": "https://portainer.example.com",
"portainer_token": "YOUR_PORTAINER_ACCESS_TOKEN",
"sync_env_files": true
}
- trilium_url: The base URL of your Trilium instance.
- etapi_token: Your Trilium ETAPI token (Settings -> Options -> ETAPI).
- parent_note_id: The Note ID under which "Portainer Stacks" will be created.
- portainer_url: Base URL of your Portainer instance.
- portainer_token: Portainer Access Token (My account -> Access tokens).
- sync_env_files: Set to
trueto sync.envvariables from Portainer.
Setup & Requirements
-
Create and Install Virtual Environment:
The script relies on a Python virtual environment.
python3 -m venv venv ./venv/bin/pip install -r requirements.txt
Usage
- Ensure
config.jsonis configured. - Run the script using the virtual environment:
./venv/bin/python PortainerSync.py
Test Mode
You can run the script in test mode to append -portainer to the hostname (e.g., hostname-portainer). This allows you to verify the sync without modifying your production documentation tree.
./venv/bin/python PortainerSync.py --test
Migration from Old Script
This script replaces the file-system based Sync_Script.py. It uses the Portainer API directly instead of scanning a local directory of compose files.