66 lines
2.5 KiB
Docker
66 lines
2.5 KiB
Docker
# syntax=docker/dockerfile:1
|
|
FROM node:26-alpine AS base
|
|
WORKDIR /m
|
|
|
|
# Keep pnpm installs/builds non-interactive in every build stage (dev + builder).
|
|
ENV CI=true
|
|
|
|
# pnpm keeps its store, cache and config under $HOME. In dev the container runs
|
|
# as the host uid (compose `user:`), not root, so $HOME=/root would be
|
|
# unwritable and pnpm fails with EACCES. Point everything at one world-writable
|
|
# dir baked into the image so the same image works for any uid. store-dir is
|
|
# pinned so the BuildKit cache mount on fetch/install lands on a stable path
|
|
# (pnpm's same-drive heuristic would otherwise move it off the mount).
|
|
ENV HOME=/home/app \
|
|
PNPM_HOME=/home/app/.pnpm \
|
|
XDG_DATA_HOME=/home/app/.local/share \
|
|
XDG_CACHE_HOME=/home/app/.cache \
|
|
XDG_CONFIG_HOME=/home/app/.config
|
|
RUN npm install -g pnpm@11.9.0 \
|
|
&& mkdir -p /home/app/store \
|
|
&& printf 'store-dir=/home/app/store\n' > /home/app/.npmrc \
|
|
&& chmod -R 777 /home/app
|
|
|
|
FROM base AS dev
|
|
|
|
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN --mount=type=cache,id=pnpm-store,target=/home/app/store pnpm fetch
|
|
COPY . .
|
|
RUN --mount=type=cache,id=pnpm-store,target=/home/app/store pnpm install --frozen-lockfile
|
|
# `vite dev` writes .svelte-kit and node_modules/.vite as the host uid; only
|
|
# those parents need to be writable (recursing node_modules is slow and
|
|
# pointless). Drop the root-owned .svelte-kit left by the install-time `prepare`
|
|
# (svelte-kit sync) so `vite dev` regenerates it. No build:packages — @when/* run
|
|
# from source via the dev vite.config (development condition + noExternal).
|
|
RUN mkdir -p /m/apps/web/data /m/apps/web/.svelte-kit /m/apps/web/node_modules/.vite /m/apps/web/node_modules/.vite-temp \
|
|
&& chmod -R 777 /m/apps/web
|
|
WORKDIR /m/apps/web
|
|
EXPOSE 5173
|
|
CMD ["pnpm", "run", "dev", "--host", "0.0.0.0"]
|
|
|
|
FROM base AS builder
|
|
|
|
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN --mount=type=cache,id=pnpm-store,target=/home/app/store pnpm fetch
|
|
COPY . .
|
|
RUN --mount=type=cache,id=pnpm-store,target=/home/app/store pnpm install --frozen-lockfile
|
|
RUN pnpm --filter "@when/web..." build
|
|
|
|
FROM builder AS pruner
|
|
|
|
RUN pnpm --filter @when/web --prod deploy --legacy /pruned
|
|
|
|
FROM node:26-alpine AS prod
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOST=0.0.0.0
|
|
COPY --from=pruner /pruned/build /app/build
|
|
COPY --from=pruner /pruned/node_modules /app/node_modules
|
|
COPY --from=pruner /pruned/package.json /app/package.json
|
|
RUN mkdir -p /app/data && chown -R node:node /app/data
|
|
USER node
|
|
EXPOSE 3000
|
|
CMD ["node", "/app/build/index.js"]
|