Skip to content

Offline gym log for Android. No account, no ads, no internet.

Self-host: run containers as a normal user, clear startup errors

InlitX4e8be2c20830
diff --git a/Dockerfile b/Dockerfile
index c3b8644..dc5e770 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,15 +16,17 @@ COPY packages /src/packages
COPY server/pubspec.yaml server/pubspec.lock ./
RUN dart pub get
COPY server ./
-RUN mkdir -p /out && dart compile exe bin/server.dart -o /out/gymmane-server
+RUN mkdir -p /out /data && chown 1000:1000 /data && dart compile exe bin/server.dart -o /out/gymmane-server
FROM scratch
COPY --from=server /runtime/ /
COPY --from=server /out/gymmane-server /app/gymmane-server
COPY --from=web /src/build/web /app/web
+COPY --from=server --chown=1000:1000 /data /data
ENV GYMMANE_DATA=/data \
GYMMANE_WEB=/app/web \
GYMMANE_PORT=8080
+USER 1000:1000
VOLUME /data
EXPOSE 8080
HEALTHCHECK --interval=60s --timeout=5s --start-period=10s CMD ["/app/gymmane-server", "--health"]
diff --git a/SELFHOST.md b/SELFHOST.md
index e848d2a..1cd3e70 100644
--- a/SELFHOST.md
+++ b/SELFHOST.md
@@ -58,12 +58,16 @@ update or remove it.
## Docker by hand
```sh
-mkdir gymmane && cd gymmane
+mkdir -p gymmane/gymmane-data/sync && cd gymmane
curl -fsSLO https://raw.githubusercontent.com/InlitX/GymMane/main/compose.yaml
echo "GYMMANE_PASSWORD=pick-something-long" > .env
docker compose up -d gymmane
```
+GymMane runs as user `1000`, not root. If your user has another id (`id -u`), add `PUID=<id>` and
+`PGID=<group id>` to `.env`, and create `gymmane-data` yourself before the first start, as above,
+so it belongs to you.
+
Open `http://localhost:8080` (or `http://<server-ip>:8080` from any device on your network).
Everything you log is stored in `./gymmane-data`. Back up that folder and you have everything.
diff --git a/compose.yaml b/compose.yaml
index 3bfb0fe..9340b4a 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -3,6 +3,7 @@ services:
image: ghcr.io/inlitx/gymmane:latest
build: .
container_name: gymmane
+ user: "${PUID:-1000}:${PGID:-1000}"
restart: unless-stopped
ports:
- "${GYMMANE_PORT:-8080}:8080"
@@ -20,8 +21,8 @@ services:
profiles: ["sync"]
hostname: gymmane
environment:
- PUID: "0"
- PGID: "0"
+ PUID: ${PUID:-1000}
+ PGID: ${PGID:-1000}
ports:
- "8384:8384"
- "22000:22000/tcp"
diff --git a/server/bin/server.dart b/server/bin/server.dart
index 73333fd..63b5175 100644
--- a/server/bin/server.dart
+++ b/server/bin/server.dart
@@ -24,7 +24,17 @@ Environment:
}
final config = Config.fromEnvironment();
final server = GymManeServer(config);
- await server.start();
+ try {
+ await server.start();
+ } on FileSystemException catch (e) {
+ stderr.writeln('GymMane cannot write to ${e.path ?? config.dataDir}.');
+ stderr.writeln('Give the user that runs GymMane write access to that folder, or set GYMMANE_DATA to another one.');
+ exit(1);
+ } on SocketException catch (e) {
+ stderr.writeln('GymMane cannot listen on port ${config.port}: ${e.osError?.message ?? e.message}');
+ stderr.writeln('Another program may be using it. Set GYMMANE_PORT to another port.');
+ exit(1);
+ }
stdout.writeln('GymMane $serverVersion is running.');
stdout.writeln(' Open: http://localhost:${server.port}');
for (final ip in await _lanAddresses()) {