CouchDB for BOSS¶
CouchDB is a document based database, which can provide JSON strings for BOSS devices.
To get started, install an instance of CouchDB, for example in a docker container.
After creating a database (in this example, we created a database my-boss) as described in the official CouchDB documentation, we can now create a CouchDB document with the following content:
{
"_id": "http-test",
"classname": "http.client.HTTPConnection",
"arguments": {
"host": "gitlab.com"
}
}
Hint
It is also possible to include multiple devices in a single document like:
{
"_id": "multi-devices",
"rows": [
{ "<device definition>" },
{ "<device definition>" },
]
}
This example launches a simple HTTP Connection to gitlab. You can simply use a different class in the classname entry to
use your device driver or any other arbitrary class you want to expose as HERO.
To use BOSS to start the HERO defined above, run
uv run boss -u http://<user>:<pw>@<couchdb_host>:5984/my-boss/http-test
Warning
Passing the password in the URL is insecure and should only be used for local test setups.
If you want to run all documents/devices in the database you can run
Note
This is not recommended in production. Use a view (see below) instead to avoid loading invalid documents and the ability to switch off/on devices quickly.
uv run boss -u http://<user>:<pw>@<couchdb_host>:5984/my-boss/_all_docs?include_docs=true
Using Views¶
To make a view which includes all active devices, add a Design Document view entry with the following map function:
function(doc) {
if(doc.active) {
emit()
}
}
With the following boss command, you can than start all devices that have the key active set to true in their json definition:
uv run boss -u http://<user>:<pw>@<couchdb_host>:5984/my-boss/_design/active/_view/active?include_docs=true
Hint
If you want to directly see if your settings worked, you can use our rudimentary GUI.
Passing Credentials¶
BOSS supports multiple secure ways to pass credentials to your CouchDB instance. For security reasons, avoid passing passwords directly in URLs as they may be visible in logs, shell history, or process listings.
Store your password in a file and reference it via the environment variables BOSS_SOURCE_PW_FILE_<username> and BOSS_SOURCE_PW_FILE. This is the most secure method.
Therefore create a password file with secure permissions:
echo "my_secure_password" > /path/to/password.txt
chmod 600 /path/to/password.txt
To use the file in docker compose, you can pass it as a secret as in the following example:
services:
boss:
image: registry.gitlab.com/atomiq-project/boss
restart: always
command: python -m boss.starter -u http://admin@couchdb:5984/my-boss/_design/active/_view/active?include_docs=true
environment:
- BOSS_SOURCE_PW_FILE_admin=/run/secrets/couchdb_password
secrets:
- couchdb_password
secrets:
couchdb_password:
file: ./couchdb_password.txt
export BOSS_SOURCE_PW_FILE=/path/to/password.txt
to use the password for all users if multiple urls with different users are given or
export BOSS_SOURCE_PW_FILE_<username>=/path/to/password.txt
to only provide the password for a specific user.
Run BOSS with the username in the URL:
uv run boss -u http://<username>@<couchdb_host>:5984/my-boss/_design/active/_view/active?include_docs=true
Store your password directly in the BOSS_SOURCE_PW_<username> and BOSS_SOURCE_PW environment variables.
This method is especially useful for production deployments using Podman:
Create the secret:
printf 'YOUR_PASSWORD' | podman secret create couchdb-password -
Create a container quadlet file (for example at
/etc/containers/systemd/boss.container):[Unit] Description=BOSS Service After=network-online.target Wants=network-online.target [Container] Image=registry.gitlab.com/atomiq-project/boss ContainerName=boss PublishPort=127.0.0.1:8000:8000 Secret=couchdb-password,type=env,target=BOSS_SOURCE_PW Command=python -m boss.starter -u http://admin@couchdb:5984/my-boss/_design/active/_view/active?include_docs=true [Service] Restart=always RestartSec=10 [Install] WantedBy=default.target
Manage the container:
systemctl daemon-reload systemctl start boss.service systemctl enable boss.service systemctl status boss.service
services:
boss:
image: registry.gitlab.com/atomiq-project/boss
restart: always
command: python -m boss.starter -u http://admin@couchdb:5984/my-boss/_design/active/_view/active?include_docs=true
environment:
- BOSS_SOURCE_PW_admin=my_secure_password
Set the environment variable:
export BOSS_SOURCE_PW_<username>="my_secure_password"
Run BOSS:
uv run boss -u http://<username>@<couchdb_host>:5984/my-boss/_design/active/_view/active?include_docs=true