Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
An iOS automation in Health Auto Export POSTs Apple Health to /api/vitals/ingest, and the new Salud tab (next to Plan) draws whatever arrived: steps, heart rate, sleep, weight, oxygen, workouts and every other metric HAE can export, grouped into cards with a trend, a sparkline and a 7/30/90/365-day range. Nothing on that screen is an input, and the watch's workouts stay out of the history on purpose — they carry no sets and no weights, so folding them into progression, PRs and the recovery model would be inventing data. The interesting part is duplicates. A five-minute automation re-sends overlapping windows: with Date Range "Today", appending would count a day of steps again on every run, and with "Since Last Sync", replacing would throw away everything but the last five minutes. So the endpoint decides per payload instead. Datapoints that sit on midnight are HAE's own day grouping, i.e. a *total*, and a day total replaces the day it names — re-sending the same day all afternoon converges on that day's total. Anything else is a real sample, identified by its instant plus its numbers and stored once, which is right for overlapping and disjoint windows alike. Every sync answers with a receipt (received / duplicates / stored), so a misconfigured automation is visible rather than silent, and day keys come from the date the phone wrote — never the server's clock, or every evening's steps would land on tomorrow. Per profile and private by construction. Each profile mints its own ingest key (Salud → ⚙), which is write-only: it can add to that one profile's health file and cannot read a single number back, so a key leaking out of a phone is a nuisance rather than a disclosure. It is its own credential, so rotating it disconnects a phone without signing anybody out anywhere. The data lives in data/vitals-<uid>.json, outside the synced state document, so a year of heart rate never round-trips through localStorage on every device, and it is bounded on write: 400 days per metric, a 72 h dedupe ledger, the newest 300 workouts. Two traps that only exist in production, both fixed here and both of which would have shipped broken. api/Dockerfile copies the modules server.js imports by name, and vitals.js was not on that list — a container that boots straight into ERR_MODULE_NOT_FOUND. And the web container's nginx capped every /api body at 5 MB, which a health export with Summarize Data off exceeds; that one route now gets the API's own 32 MB while every other path keeps 5 MB, with the shared proxy settings hoisted to server level so the two locations cannot drift apart. Coverage: vitals.js (13 tests — overlapping, disjoint, day-grouped, raw, heart rate, sleep, blood pressure, pruning, timezones), the routes against a real server (4 — isolation between profiles, a key that cannot read, ten re-sends changing nothing), the card model (18) and the screen (4). docs/HEALTH.md has the Health Auto Export settings and the merge table; the five endpoints are in api/openapi.yaml under the health tag, and website/api.html is rebuilt from it.
100 lines
5.3 KiB
Docker
100 lines
5.3 KiB
Docker
# Two targets from one file.
|
|
#
|
|
# default (built when no --target is given) — what every instance has always got. No AI
|
|
# runtime, no AI dependency: `npm ci --omit=optional` skips the Agent SDK and its
|
|
# platform runtime entirely, so an owner who never wanted the Coach carries none of it.
|
|
# coach — the same image plus the Claude Agent SDK.
|
|
#
|
|
# Build the opt-in one with: docker build --target coach ./api
|
|
# or through compose with: API_TARGET=coach docker compose up --build
|
|
#
|
|
# The stage order matters: Docker builds the *last* stage when none is named, so `default` is
|
|
# deliberately last and `coach` sits above it.
|
|
|
|
FROM node:22-alpine AS base
|
|
|
|
# Declared on the base stage so both targets inherit the labels and the healthcheck.
|
|
ARG VERSION=dev
|
|
ARG VCS_REF=dev
|
|
ARG BUILD_DATE=unknown
|
|
|
|
LABEL maintainer="Duarte Santos https://gitlab.com/DuarteSantos8" \
|
|
org.opencontainers.image.title="kuentagym-api" \
|
|
org.opencontainers.image.description="Backend for Self-hosted gym & body-weight tracker — plan routines, log workouts (supersets & cardio too), track your weight and progress, passkey login. Your data, your server." \
|
|
org.opencontainers.image.source="https://git.dploy.lol/dsantillan/kuentagym" \
|
|
org.opencontainers.image.url="https://git.dploy.lol/dsantillan/kuentagym/packages" \
|
|
org.opencontainers.image.documentation="https://git.dploy.lol/dsantillan/kuentagym#readme" \
|
|
org.opencontainers.image.licenses="AGPL-3.0-or-later" \
|
|
org.opencontainers.image.version=$VERSION \
|
|
org.opencontainers.image.revision=$VCS_REF \
|
|
org.opencontainers.image.created=$BUILD_DATE
|
|
|
|
WORKDIR /app
|
|
|
|
# The base image is rebuilt on node's schedule, not alpine's: between two node releases the
|
|
# alpine packages it ships (openssl above all) fall behind their fixes. Taking the upgrades at
|
|
# build time keeps the published image at alpine's current state without waiting for node.
|
|
RUN apk upgrade --no-cache
|
|
|
|
# The unprivileged user Coach jobs drop to. Its uid cannot read /data, which is the control that
|
|
# keeps a provider runtime away from users, passkeys and the session secret.
|
|
#
|
|
# Not optional, and not only for the real providers: canDropPrivileges() fails closed on Linux,
|
|
# so in an image without this user *every* job is refused with "no `coach` user exists in this
|
|
# image" — including the fixture provider that exists precisely so the loop can be walked before
|
|
# an account is connected. It costs one line and no bytes worth measuring.
|
|
RUN adduser -D -H -s /sbin/nologin coach
|
|
|
|
COPY package.json package-lock.json* ./
|
|
# `npm ci` rather than `npm install`: the lockfile is the point of committing one, and the SDK's
|
|
# per-platform runtime is resolved from it (musl on this base) rather than from whatever the
|
|
# build host happened to be.
|
|
RUN npm ci --omit=dev --omit=optional && npm cache clean --force
|
|
|
|
# Every local module server.js imports, listed rather than `COPY . .` so a stray file in api/
|
|
# (a test, a script, a stray JSON) cannot reach the published image. vitals.js joined the list
|
|
# with the Apple Health ingest — an import of a file that is not copied here is a container that
|
|
# boots straight into ERR_MODULE_NOT_FOUND, which is exactly what the first health build would
|
|
# have done.
|
|
COPY server.js push-messages.js verify-error.js vitals.js ./
|
|
COPY coach ./coach
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
EXPOSE 3000
|
|
CMD ["node", "server.js"]
|
|
|
|
HEALTHCHECK --interval=5m \
|
|
--timeout=5s \
|
|
--retries=3 \
|
|
CMD wget --spider -q "http://127.0.0.1:${PORT}/api/health" || exit 1
|
|
|
|
# ---------------------------------------------------------------------------------------------
|
|
# The opt-in target. Dropping --omit=optional is the whole difference: it pulls in
|
|
# @anthropic-ai/claude-agent-sdk together with the one platform runtime this base needs
|
|
# (linux-*-musl), both pinned by the lockfile.
|
|
FROM base AS coach
|
|
RUN npm ci --omit=dev && npm cache clean --force
|
|
|
|
# Codex ships as a CLI rather than a library, so it is installed rather than resolved, and
|
|
# bubblewrap is its sandbox — a Codex requirement, which is why neither appears in the default
|
|
# target or anywhere in this tree until now.
|
|
RUN apk add --no-cache bubblewrap \
|
|
&& npm install -g @openai/codex \
|
|
&& npm cache clean --force
|
|
|
|
# Where Codex keeps its refreshable login cache. Deliberately a sibling of /data rather than a
|
|
# path inside it: docs/SELF_HOSTING tells owners to back up with `tar czf … data/`, and a live
|
|
# refresh token has no business riding along in every archive that instruction produces. Owned
|
|
# by `coach` because the job that writes it has already dropped to that user.
|
|
RUN mkdir -p /coach-auth && chown coach:coach /coach-auth && chmod 700 /coach-auth
|
|
VOLUME ["/coach-auth"]
|
|
|
|
# ---------------------------------------------------------------------------------------------
|
|
# Last, so that a plain `docker build ./api` keeps producing the runtime-free image.
|
|
FROM base AS default
|
|
# npm itself is only a build-time tool here: the server is started with `node server.js` and
|
|
# nothing in it spawns npm. Its bundled dependency tree (tar, brace-expansion, ...) is where
|
|
# every vulnerability the image scan ever reported lived — none of them was in a package the
|
|
# app uses. Gone from the published image; the coach target keeps npm for the Codex CLI.
|
|
RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx
|