Calio/Dockerfile
Elijah 80fc48b9f1
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m2s
Add barcode and nutrition label scanning
Barcode scanning
- Scan barcode in the food sheet reads UPC-A/E and EAN-13/8 live from
  the camera with ZXing WebAssembly (bundled, precached, CSP allows
  wasm), with photo and typed-digit fallbacks
- Lookups check saved foods first (offline), then local copies of USDA
  FoodData Central Branded Foods and Open Food Facts, then the live
  Open Food Facts API; API answers and misses are cached
- Server imports refresh in a low-priority child process: USDA when a
  new archive is published, Open Food Facts weekly by streaming its CSV
  export; each import builds a new table and swaps it in atomically
- Every available nutrient is kept: foods and entries gain optional
  barcode (GTIN-14) and extra nutrients, shown under More nutrients and
  included in JSON exports
- Settings shows the size, date and any error for each product copy

Label scanning
- Scan label sends a downscaled photo to the server, read with
  PaddleOCR PP-OCRv5 (server detection, English recognition) on ONNX
  Runtime CPU, about 1.3 s median
- Parser handles US/Canadian, linear, Spanish and EU per-100 g panels,
  tilted photos, OCR misspellings and %DV cross-checks
- Models are pinned and checksum-verified at image build time

Container
- Runtime moves to Debian slim for ONNX Runtime's glibc build; other
  platforms' binaries are pruned
- Smoke tests now read a fixture label inside the container
- README and Unraid docs cover disk use, network access and refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:41:44 -07:00

42 lines
1.8 KiB
Docker

# Debian rather than Alpine: ONNX Runtime (label OCR) ships glibc binaries.
FROM node:24-bookworm-slim AS build
ENV ONNXRUNTIME_NODE_INSTALL=skip
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY tsconfig.json vite.config.ts index.html ./
COPY src ./src
COPY shared ./shared
COPY public ./public
COPY scripts/build-sw.js ./scripts/build-sw.js
RUN npm run build
# Pinned PP-OCRv5 models, verified by SHA-256.
FROM node:24-bookworm-slim AS models
WORKDIR /app
COPY scripts/fetch-models.js ./scripts/fetch-models.js
RUN node scripts/fetch-models.js /models
FROM node:24-bookworm-slim AS runtime
LABEL org.opencontainers.image.title="Calio" \
org.opencontainers.image.description="Personal offline-first nutrition and weight journal" \
org.opencontainers.image.source="https://git.elijahkuntz.com/Elijah/Calio"
ENV NODE_ENV=production PORT=3000 DATA_DIR=/data MODELS_DIR=/app/models \
ONNXRUNTIME_NODE_INSTALL=skip
WORKDIR /app
COPY package.json package-lock.json ./
# Keep only this platform's ONNX Runtime library (the package bundles all).
RUN npm ci --omit=dev --no-audit --no-fund && npm cache clean --force \
&& arch="$(node -p process.arch)" \
&& find node_modules/onnxruntime-node/bin -mindepth 2 -maxdepth 2 ! -path "*/linux" -exec rm -rf {} + \
&& find node_modules/onnxruntime-node/bin -mindepth 3 -maxdepth 3 ! -name "$arch" -exec rm -rf {} + \
&& mkdir /data && chown node:node /data
COPY --from=models /models ./models
COPY --from=build /app/dist ./dist
COPY server ./server
COPY shared ./shared
USER node
VOLUME /data
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s CMD node -e "fetch('http://127.0.0.1:3000/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node", "server/index.js"]