BetterFrame/deploy/docker/Dockerfile.server
Mitchell R 7d81891b0e
fix(version): derive server version from git at Docker build time
Coolify pulls from GitHub and runs docker compose build — no guaranteed
env vars like SOURCE_COMMIT. Previous approach relied on ARG/ENV
passthrough that silently defaulted to "dev".

Fix: install git in the builder stage, COPY .git into context, run
git describe --tags --always to derive the version, write it to
/app/server/.bf-version. version.ts reads this file as a fallback
between env vars and the "dev" literal.

Chain: BF_SERVER_VERSION env → BF_BUILD_VERSION env → .bf-version file
→ COOLIFY_GIT_COMMIT env → SOURCE_COMMIT env → "dev".

Also: fix .gitignore for rauc-signing/ (was under wrong path).
2026-05-21 16:02:21 +02:00

66 lines
2.4 KiB
Docker

# BetterFrame server image — Node 24 + native deps for argon2/sqlite.
# Trixie base (Debian 13, latest stable) — matches the host distro we
# recommend in deploy/README.md.
FROM node:24-trixie-slim AS builder
WORKDIR /app
# Build deps for argon2 + bsb-plugin-cli + git for version stamping
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential python3 git \
&& rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json ./
COPY server/package.json ./server/
COPY tsconfig.base.json ./
RUN npm ci && npm rebuild argon2
COPY server ./server
# Run BSB build — extracts schemas + compiles TS + generates plugin manifests
WORKDIR /app/server
RUN npm run build
# Derive version from git. Coolify clones the repo with .git intact so
# git describe / rev-parse work. Falls back to package.json version if
# .git is missing (e.g. if a .dockerignore later excludes it).
COPY .git /app/.git
RUN cd /app && \
GIT_VER="$(git describe --tags --always --dirty 2>/dev/null || echo '')" && \
if [ -z "$GIT_VER" ]; then GIT_VER="$(git rev-parse --short HEAD 2>/dev/null || echo '')"; fi && \
if [ -z "$GIT_VER" ]; then GIT_VER="$(node -p 'require("./package.json").version' 2>/dev/null || echo 'dev')"; fi && \
echo "$GIT_VER" > /app/server/.bf-version && \
echo "Baked version: $GIT_VER"
# ---- Runtime image ----
FROM node:24-trixie-slim
# ffmpeg for camera snapshot capture (optional but needed for /admin/entities/:id/snapshot)
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates ffmpeg wget \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m -d /var/lib/betterframe -s /bin/false betterframe
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/server ./server
COPY --from=builder /app/tsconfig.base.json ./
COPY --from=builder /app/package.json ./
# Default sec-config baked into image. BF_* env vars in compose override at
# runtime (see shared/env-overrides.ts). No host bind mount needed.
COPY deploy/docker/sec-config.yaml /app/server/sec-config.yaml
RUN mkdir -p /var/lib/betterframe && chown betterframe:betterframe /var/lib/betterframe
VOLUME /var/lib/betterframe
EXPOSE 18080 18081 18082
USER betterframe
WORKDIR /app/server
ENV NODE_OPTIONS=--import=tsx
CMD ["node", "--import", "tsx", "/app/node_modules/@bsb/base/lib/scripts/bsb-plugin-cli.js", "start"]