Skip to content

Commit bb9ed77

Browse files
committed
feat: dynamic env vars in docker-compose + GHCR image
docker-compose.yml: - Image now pulls from ghcr.io/b0bbywan/go-odio-api:latest - XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS read from host env with fallback to /run/user/${UID:-1000} derivation - HOME read from host env (PulseAudio cookie path stays consistent) - All XDG_RUNTIME_DIR-based volume paths use the variable instead of recalculating from UID .env.example: documents optional overrides for non-bash shells (fish, etc.) README: rewrite Docker section with quick-start steps, env var table, and volume table — no more hardcoded 1000 https://claude.ai/code/session_01GwPe5tCsib8gdiU7UNfH1N
1 parent 9881abb commit bb9ed77

3 files changed

Lines changed: 60 additions & 33 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These variables are read automatically from your shell environment (bash/zsh export them).
2+
# Uncomment and set only if `docker compose config` shows wrong values.
3+
#
4+
# UID=1000 # run `id -u`
5+
# XDG_RUNTIME_DIR=/run/user/1000 # run `echo $XDG_RUNTIME_DIR`

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -213,38 +213,60 @@ systemctl --user start odio-api.service
213213
This ensures the Pulseaudio/Pipewire, user D-Bus session and XDG_RUNTIME_DIR are available even without an active login session.
214214

215215
### Docker
216-
You can also run odio as a container!
217216

218-
#### Build
219-
Build the Go binary and Docker image
217+
A pre-built multi-arch image is available on GHCR (amd64, arm64, arm/v6, arm/v7):
218+
219+
```
220+
ghcr.io/b0bbywan/go-odio-api:latest
221+
```
222+
223+
To build locally instead:
220224
```bash
221-
docker build -t odio:latest .
225+
docker build -t odio-api .
226+
```
227+
228+
#### Quick start
229+
230+
```bash
231+
# 1. Prepare configuration (bind: all required for Docker)
232+
cp share/config.yaml config.yaml
233+
# Edit config.yaml: set bind: all
234+
235+
# 2. (Optional) Provide your PulseAudio cookie
236+
cp ~/.config/pulse/cookie ./cookie
237+
238+
# 3. (Optional) Only needed if docker compose config shows wrong paths
239+
cp .env.example .env
240+
241+
# 4. Start
242+
docker compose up -d
222243
```
223-
The Dockerfile uses a multi-stage build to compile the Go binary and copy it into a minimal runtime image.
224-
**Note**: the image includes DBus so that DBus-dependent functionality works correctly inside the container.
225244

226-
#### Run
227-
A docker-compose.yml is provided in the repository for the most common use cases. It runs the container as a non-root user (UID 1000) and mounts the necessary host directories for DBus, systemd, and PulseAudio. You can adapt it for more specific setups if needed
245+
The `docker-compose.yml` reads `UID`, `XDG_RUNTIME_DIR`, `HOME` and `DBUS_SESSION_BUS_ADDRESS`
246+
directly from your shell environment — no configuration needed for a standard Linux setup.
247+
See `.env.example` if your shell doesn't export these automatically (e.g. fish).
228248

229-
Environment variables:
230-
- XDG_RUNTIME_DIR=/run/user/1000 DBus and Pulse runtime directory
231-
- DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus user DBus session
232-
- HOME=/home/odio ensures `PulseAudio cookie` is found
249+
Environment variables passed to the container:
233250

234-
Volumes:
235-
- ./config.yaml (odio configuration) (read-only)
236-
- /run/user/1000/bus (user DBus session) (read-only)
237-
- /run/user/1000/systemd (user systemd folder) (read-only)
238-
- /run/utmp (user systemd monitoring) (read-only)
239-
- /var/run/dbus/system_bus_socket (system DBus socket) (read-only)
240-
- /run/user/1000/pulse (PulseAudio socket) (read-only)
241-
- ./cookie (`PulseAudio cookie`: $HOME/.config/pulse/cookie) (read-only)
251+
| Variable | Source | Purpose |
252+
|---|---|---|
253+
| `XDG_RUNTIME_DIR` | host env → fallback `/run/user/$UID` | D-Bus and PulseAudio runtime directory |
254+
| `DBUS_SESSION_BUS_ADDRESS` | host env → fallback derived from `XDG_RUNTIME_DIR` | User D-Bus session socket |
255+
| `HOME` | host env → fallback `/home/odio` | PulseAudio cookie lookup path |
242256

243-
The container exposes port 8018 by default and is configured to automatically restart unless stopped. With this configuration, audio and DBus-dependent functionality works seamlessly inside Docker.
257+
Volumes mounted (all read-only):
244258

245-
**Note:** `bind` should be set to `all` in `config.yaml` for remote access with docker. Zeroconf won't work in bridge network mode. It's strongly advised against using host network mode.
259+
| Volume | Purpose |
260+
|---|---|
261+
| `./config.yaml` | odio configuration |
262+
| `$XDG_RUNTIME_DIR/bus` | user D-Bus session socket |
263+
| `$XDG_RUNTIME_DIR/systemd` | user systemd folder (utmp unavailable) |
264+
| `/run/utmp` | user systemd monitoring (utmp available) |
265+
| `/var/run/dbus/system_bus_socket` | system D-Bus socket |
266+
| `$XDG_RUNTIME_DIR/pulse` | PulseAudio socket |
267+
| `./cookie` → `$HOME/.config/pulse/cookie` | PulseAudio cookie |
246268

247-
All mounts are read-only, minimizing the container’s ability to modify the host system.
269+
**Note:** `bind` must be set to `all` in `config.yaml` for Docker (bridge network). Zeroconf won't work in bridge network mode. Host network mode is strongly discouraged.
248270

249271
#### Command-line Flags
250272

docker-compose.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
services:
22
odio:
3-
image: odio:latest
3+
image: ghcr.io/b0bbywan/go-odio-api:latest
44
container_name: odio
55
ports:
66
- "8018:8018"
7-
user: "1000:1000"
7+
user: "${UID:-1000}:${UID:-1000}"
88
environment:
9-
XDG_RUNTIME_DIR: /run/user/1000
10-
DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus
11-
HOME: /home/odio
9+
XDG_RUNTIME_DIR: ${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}
10+
DBUS_SESSION_BUS_ADDRESS: ${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/${UID:-1000}/bus}
11+
HOME: ${HOME:-/home/odio}
1212
volumes:
13-
- /run/user/1000/bus:/run/user/1000/bus:ro # DBUS_SESSION_BUS_ADDRESS socket
14-
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro # system systemd socket
15-
- /run/user/1000/systemd:/run/user/1000/systemd:ro # user systemd folder if utmp unavailable
13+
- ${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/bus:${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/bus:ro # DBUS_SESSION_BUS_ADDRESS socket
14+
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro # system dbus socket
15+
- ${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/systemd:${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/systemd:ro # user systemd folder if utmp unavailable
1616
- /run/utmp:/run/utmp:ro # user systemd socket if utmp available
17-
- /run/user/1000/pulse:/run/user/1000/pulse:ro # pulse socket
18-
- ./cookie:/home/odio/.config/pulse/cookie:ro # pulse cookie
17+
- ${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/pulse:${XDG_RUNTIME_DIR:-/run/user/${UID:-1000}}/pulse:ro # pulse socket
18+
- ./cookie:${HOME:-/home/odio}/.config/pulse/cookie:ro # pulse cookie
1919
- ./config.yaml:/etc/odio-api/config.yml:ro # odio config
2020
restart: unless-stopped

0 commit comments

Comments
 (0)