Skip to content

Commit 4ee00a0

Browse files
nprev-devclaude
andcommitted
Package as rack-dashboard, add installer and cross-platform tests
- The Python package is now rack_dashboard, with the page inside it, a rack-dashboard command, and its state kept in the user's data folder. - install.sh installs it with uv and registers a systemd user service. - A workflow runs the tests and starts the dashboard on Linux, Windows and macOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0e8067b commit 4ee00a0

53 files changed

Lines changed: 761 additions & 102 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/tests.yml‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Runs the tests, and the dashboard itself, on Linux, Windows and macOS.
2+
name: tests
3+
4+
on:
5+
push:
6+
branches: [main, "ci/**"]
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
unit:
14+
name: tests, ${{ matrix.os }}, Python ${{ matrix.python }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os: [ubuntu-latest, windows-latest, macos-latest]
20+
# The oldest Python the package claims to support, and the newest.
21+
python: ["3.10", "3.14"]
22+
steps:
23+
- uses: actions/checkout@v7
24+
- uses: actions/setup-python@v7
25+
with:
26+
python-version: ${{ matrix.python }}
27+
- run: python -m pip install -e ".[dev]"
28+
- run: python -m pytest -q
29+
30+
run:
31+
name: start it, ${{ matrix.os }}
32+
runs-on: ${{ matrix.os }}
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
os: [ubuntu-latest, windows-latest, macos-latest]
37+
steps:
38+
- uses: actions/checkout@v7
39+
- uses: actions/setup-python@v7
40+
with:
41+
python-version: "3.12"
42+
# Installed the way a user gets it, not run from the source folder.
43+
- run: python -m pip install .
44+
- name: Start the dashboard and ask it for a reading
45+
shell: bash
46+
run: |
47+
cd "$RUNNER_TEMP"
48+
rack-dashboard --version
49+
rack-dashboard --port 8787 > server.log 2>&1 &
50+
python "$GITHUB_WORKSPACE/tests/smoke.py" http://127.0.0.1:8787 || { echo "--- server log"; cat server.log; exit 1; }
51+
52+
install:
53+
name: install script, ubuntu-latest
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v7
57+
# From GitHub, exactly as the readme says, but at the commit being tested.
58+
- run: sh install.sh --no-service --ref "$GITHUB_SHA"
59+
- name: Start what was installed and ask it for a reading
60+
run: |
61+
cd "$RUNNER_TEMP"
62+
~/.local/bin/rack-dashboard --version
63+
~/.local/bin/rack-dashboard --port 8787 > server.log 2>&1 &
64+
python3 "$GITHUB_WORKSPACE/tests/smoke.py" http://127.0.0.1:8787 || { echo "--- server log"; cat server.log; exit 1; }

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ data/
66
__pycache__/
77
*.py[cod]
88
.pytest_cache/
9+
dist/
10+
build/
11+
*.egg-info/
912

1013
# Personal and per-machine files: assistant instructions, local settings, editor folders.
1114
CLAUDE.md

‎backend/__main__.py‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎backend/collectors/__init__.py‎

Whitespace-only changes.

‎install.sh‎

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
#!/bin/sh
2+
# Installs Rack Dashboard for the person running this script. It needs no root and puts nothing
3+
# outside that person's home folder.
4+
#
5+
# curl -fsSL https://raw.githubusercontent.com/nprev-dev/Docker-UI-app/main/install.sh | sh
6+
#
7+
# To pass options, put them after "sh -s --":
8+
#
9+
# --lan let other machines on the network open the page (the default is this machine only)
10+
# --port N listen on port N (default 8787)
11+
# --no-service install the command only; do not set it up to start at boot
12+
# --uninstall remove the service and the command (settings and saved data stay)
13+
# --ref NAME install a branch, tag or commit other than main
14+
#
15+
# What it does: fetches uv (https://docs.astral.sh/uv/) if it is not there, which brings its own
16+
# Python; has uv install the dashboard from GitHub; and, on Linux with systemd, registers a service
17+
# for this user so that the dashboard starts when the machine does.
18+
19+
set -eu
20+
21+
REPO="https://github.com/nprev-dev/Docker-UI-app"
22+
NAME="rack-dashboard"
23+
24+
say() { printf '%s\n' "$*"; }
25+
fail() { printf 'install.sh: %s\n' "$*" >&2; exit 1; }
26+
27+
usage() {
28+
cat <<EOF
29+
Installs Rack Dashboard for the person running it. No root needed.
30+
31+
--lan let other machines on the network open the page (default: this machine only)
32+
--port N listen on port N (default 8787)
33+
--no-service install the command only; do not set it up to start at boot
34+
--uninstall remove the service and the command (settings and saved data stay)
35+
--ref NAME install a branch, tag or commit other than main
36+
EOF
37+
}
38+
39+
# Sets a KEY=value line in the settings file, replacing an earlier one for the same key.
40+
set_setting() {
41+
key="$1"; value="$2"; file="$3"
42+
if grep -q "^$key=" "$file" 2>/dev/null; then
43+
scratch="$file.tmp"
44+
sed "s|^$key=.*|$key=$value|" "$file" > "$scratch" && mv "$scratch" "$file"
45+
else
46+
printf '%s=%s\n' "$key" "$value" >> "$file"
47+
fi
48+
}
49+
50+
find_uv() {
51+
if command -v uv >/dev/null 2>&1; then
52+
command -v uv
53+
elif [ -x "$HOME/.local/bin/uv" ]; then
54+
printf '%s\n' "$HOME/.local/bin/uv"
55+
else
56+
return 1
57+
fi
58+
}
59+
60+
fetch() {
61+
if command -v curl >/dev/null 2>&1; then
62+
curl -LsSf "$1"
63+
elif command -v wget >/dev/null 2>&1; then
64+
wget -qO- "$1"
65+
else
66+
fail "need curl or wget to download things"
67+
fi
68+
}
69+
70+
have_user_services() {
71+
[ "$(uname -s)" = "Linux" ] && command -v systemctl >/dev/null 2>&1 && systemctl --user show-environment >/dev/null 2>&1
72+
}
73+
74+
uninstall() {
75+
config="${XDG_CONFIG_HOME:-$HOME/.config}"
76+
unit="$config/systemd/user/$NAME.service"
77+
if have_user_services && [ -f "$unit" ]; then
78+
systemctl --user disable --now "$NAME.service" >/dev/null 2>&1 || true
79+
rm -f "$unit"
80+
systemctl --user daemon-reload || true
81+
say "Removed the service."
82+
fi
83+
# Starting at boot without anyone logged in was switched on by this script; switch it back off.
84+
if [ -f "$config/$NAME/.linger-set-by-installer" ]; then
85+
loginctl disable-linger "$(id -un)" >/dev/null 2>&1 || true
86+
rm -f "$config/$NAME/.linger-set-by-installer"
87+
fi
88+
if uv_bin="$(find_uv)"; then
89+
"$uv_bin" tool uninstall "$NAME" >/dev/null 2>&1 && say "Removed the $NAME command." || say "The $NAME command was not installed."
90+
fi
91+
say "Settings in $config/$NAME and saved data in ${XDG_DATA_HOME:-$HOME/.local/share}/$NAME were left alone."
92+
}
93+
94+
main() {
95+
lan=0; port=""; service=1; ref="main"; source=""; remove=0
96+
while [ $# -gt 0 ]; do
97+
case "$1" in
98+
--lan) lan=1 ;;
99+
--port) [ $# -ge 2 ] || fail "--port needs a number"; port="$2"; shift ;;
100+
--no-service) service=0 ;;
101+
--uninstall) remove=1 ;;
102+
--ref) [ $# -ge 2 ] || fail "--ref needs a name"; ref="$2"; shift ;;
103+
# For trying out a copy that is not on GitHub: a folder, a built package or an address.
104+
--source) [ $# -ge 2 ] || fail "--source needs a path or address"; source="$2"; shift ;;
105+
-h|--help) usage; exit 0 ;;
106+
*) fail "unknown option: $1 (see --help)" ;;
107+
esac
108+
shift
109+
done
110+
case "$port" in
111+
""|*[!0-9]*) [ -z "$port" ] || fail "--port needs a number from 1 to 65535" ;;
112+
esac
113+
if [ -n "$port" ] && { [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; }; then
114+
fail "--port needs a number from 1 to 65535"
115+
fi
116+
117+
system="$(uname -s)"
118+
case "$system" in
119+
Linux|Darwin) ;;
120+
*) fail "this script is for Linux and macOS; on Windows use install.ps1 (see the readme)" ;;
121+
esac
122+
[ -n "${HOME:-}" ] || fail "HOME is not set"
123+
124+
if [ "$remove" -eq 1 ]; then
125+
uninstall
126+
exit 0
127+
fi
128+
129+
# 1. uv, which installs the dashboard into its own corner and supplies Python if need be.
130+
if ! uv_bin="$(find_uv)"; then
131+
say "Fetching uv (the installer tool) from astral.sh ..."
132+
scratch="$(mktemp)"
133+
fetch https://astral.sh/uv/install.sh > "$scratch" || { rm -f "$scratch"; fail "could not download uv from astral.sh"; }
134+
sh "$scratch" >/dev/null 2>&1 || { rm -f "$scratch"; fail "could not install uv; see https://docs.astral.sh/uv/getting-started/installation/"; }
135+
rm -f "$scratch"
136+
uv_bin="$(find_uv)" || fail "uv was installed but cannot be found; open a new terminal and run this again"
137+
fi
138+
139+
# 2. The dashboard itself.
140+
[ -n "$source" ] || source="$NAME @ $REPO/archive/$ref.tar.gz"
141+
say "Installing $NAME ..."
142+
"$uv_bin" tool install --force --quiet "$source" || fail "could not install $NAME"
143+
bin_dir="$("$uv_bin" tool dir --bin)"
144+
command_path="$bin_dir/$NAME"
145+
[ -x "$command_path" ] || fail "the $NAME command did not appear in $bin_dir"
146+
say "Installed $("$command_path" --version) in $bin_dir"
147+
148+
# 3. Settings: one file of KEY=value lines, read by the service. An earlier one is kept.
149+
config="${XDG_CONFIG_HOME:-$HOME/.config}"
150+
settings="$config/$NAME/env"
151+
mkdir -p "$config/$NAME"
152+
if [ ! -f "$settings" ]; then
153+
cat > "$settings" <<EOF
154+
# Settings for Rack Dashboard, one KEY=value per line. The readme lists them all.
155+
# After a change: systemctl --user restart $NAME
156+
EOF
157+
fi
158+
[ "$lan" -eq 0 ] || set_setting DASH_HOST 0.0.0.0 "$settings"
159+
[ -z "$port" ] || set_setting DASH_PORT "$port" "$settings"
160+
listening_port="$(sed -n 's/^DASH_PORT=//p' "$settings" | tail -n 1)"
161+
listening_port="${listening_port:-8787}"
162+
163+
if [ "$service" -eq 0 ]; then
164+
say "Not set up as a service. Start it with: $command_path"
165+
say "(In a new terminal, plain \"$NAME\" works too.)"
166+
exit 0
167+
fi
168+
if ! have_user_services; then
169+
say "This system has no systemd user services, so it was not set up to start at boot."
170+
say "Start it with: $command_path"
171+
exit 0
172+
fi
173+
174+
# 4. A service for this user.
175+
unit_dir="$config/systemd/user"
176+
mkdir -p "$unit_dir"
177+
cat > "$unit_dir/$NAME.service" <<EOF
178+
[Unit]
179+
Description=Rack Dashboard
180+
Documentation=$REPO
181+
182+
[Service]
183+
ExecStart="$command_path"
184+
EnvironmentFile=-$settings
185+
# The dashboard calls a few system tools (ss, nvidia-smi, upower); make sure they are found.
186+
Environment=PATH=$bin_dir:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
187+
Restart=on-failure
188+
RestartSec=5
189+
190+
[Install]
191+
WantedBy=default.target
192+
EOF
193+
systemctl --user daemon-reload
194+
systemctl --user enable "$NAME.service" >/dev/null 2>&1 || fail "could not enable the service"
195+
systemctl --user restart "$NAME.service" || fail "could not start the service; see: journalctl --user -u $NAME"
196+
197+
# Without this a user's services only run while that user is logged in.
198+
user="$(id -un)"
199+
if [ "$(loginctl show-user "$user" -p Linger 2>/dev/null)" != "Linger=yes" ]; then
200+
if loginctl enable-linger "$user" >/dev/null 2>&1; then
201+
: > "$config/$NAME/.linger-set-by-installer"
202+
else
203+
say "Note: it will start when you log in. To have it start at boot with nobody logged in, run:"
204+
say " sudo loginctl enable-linger $user"
205+
fi
206+
fi
207+
208+
# 5. Is it answering?
209+
tries=0
210+
until fetch "http://127.0.0.1:$listening_port/api/snapshot" >/dev/null 2>&1; do
211+
tries=$((tries + 1))
212+
if [ "$tries" -ge 20 ]; then
213+
if journalctl --user -u "$NAME" -n 20 --no-pager 2>/dev/null | grep -qi "address already in use"; then
214+
say "Port $listening_port is already used by another program. Choose another: run this again with --port N"
215+
else
216+
say "The service was started but is not answering. Look at: journalctl --user -u $NAME"
217+
fi
218+
exit 1
219+
fi
220+
sleep 1
221+
done
222+
say ""
223+
say "Rack Dashboard is running: http://127.0.0.1:$listening_port"
224+
if grep -q '^DASH_HOST=0\.0\.0\.0' "$settings"; then
225+
address="$(hostname -I 2>/dev/null | awk '{print $1}')"
226+
[ -z "$address" ] || say "From other machines: http://$address:$listening_port"
227+
else
228+
say "Only this machine can open it. Run the installer again with --lan to change that."
229+
fi
230+
say "Settings: $settings Logs: journalctl --user -u $NAME"
231+
if command -v docker >/dev/null 2>&1 && ! [ -r /var/run/docker.sock ] && ! [ -S "$HOME/.docker/desktop/docker.sock" ]; then
232+
say "Note: $user may not use Docker, so the containers section will be empty."
233+
say " The usual fix: sudo usermod -aG docker $user (then log out and back in)"
234+
fi
235+
}
236+
237+
# Everything runs from here, so that a download cut short runs nothing at all.
238+
main "$@"

‎pyproject.toml‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "rack-dashboard"
7+
dynamic = ["version"]
8+
description = "A one-page status screen for a home server: containers, network, power and hardware."
9+
readme = "readme.md"
10+
license = "MIT"
11+
license-files = ["LICENSE", "rack_dashboard/frontend/fonts/LICENSE.txt"]
12+
requires-python = ">=3.10"
13+
keywords = ["homelab", "dashboard", "docker", "monitoring"]
14+
classifiers = [
15+
"Environment :: Web Environment",
16+
"Intended Audience :: System Administrators",
17+
"Operating System :: POSIX :: Linux",
18+
"Programming Language :: Python :: 3",
19+
"Topic :: System :: Monitoring",
20+
]
21+
dependencies = [
22+
"fastapi>=0.115",
23+
"uvicorn>=0.30",
24+
"docker>=7.1",
25+
]
26+
27+
[project.optional-dependencies]
28+
dev = ["pytest>=8"]
29+
30+
[project.scripts]
31+
rack-dashboard = "rack_dashboard.cli:main"
32+
33+
[project.urls]
34+
Homepage = "https://github.com/nprev-dev/Docker-UI-app"
35+
36+
[tool.hatch.version]
37+
path = "rack_dashboard/__init__.py"
38+
39+
[tool.hatch.build.targets.wheel]
40+
packages = ["rack_dashboard"]
41+
42+
[tool.hatch.build.targets.sdist]
43+
include = ["rack_dashboard", "tests", "readme.md", "LICENSE"]

‎rack_dashboard/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Rack Dashboard: a one-page status screen for a home server."""
2+
3+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)