Files
slopus--happy/Dockerfile.server
Kirill Dubovitskiy 16ea2acc73 Split self-host publishing out of the production server package
d2d2f730 renamed packages/happy-server to happy-server-self-host so the
self-host runtime could be published to npm, but that directory is also the
production backend, and the rename left /Dockerfile.server and /Dockerfile
running `pnpm --filter happy-server ...`. pnpm exits 0 on an unmatched filter,
so the production image's build step became a no-op and its CMD became a
container that prints one line and exits 0 instead of serving. Production has
not been redeployed since.

Actually split the two roles:

- packages/happy-server goes back to being private "happy-server", the
  production backend. It is never published, so npm's squatted bare name is
  irrelevant to it.
- packages/happy-server-self-host is a new publishing shell that keeps the
  published name and version. Its build bun-bundles the sibling's
  sources/standalone.ts into dist/ and copies prisma/ in, both of which must
  live inside the package because the runtime resolves migrations from cwd.
  It asserts its dependency list matches the sibling's, since the bundle
  externalizes every dependency and drift would otherwise fail at require time.

Fixing the Docker filters alone was not enough: `build` now also bundles the
npm runtime via bun, which neither image installs, and the full typecheck
includes machinesRoutes.spec.ts, which imports happy-app source that the
builder stage does not copy. Production therefore gets tsconfig.build.json,
which excludes specs, and `build` runs that typecheck only.

Every pnpm filter invocation gets --fail-if-no-match so a future rename fails
the build instead of silently doing nothing, and Dockerfile.server's CMD no
longer depends on the package name at all.

Add .github/workflows/server.yml: the server package had no CI coverage, which
is why this went unnoticed for 74 days. It typechecks and tests the package and
builds both images and boots them, asserting they serve — the only check that
catches a no-op CMD.

Also revert 450f29e9, a hardcoded voice grant for one account that was written
to deploy immediately and never shipped.
2026-08-03 03:15:33 -07:00

62 lines
2.1 KiB
Docker

# Stage 1: install dependencies with workspace context
FROM node:20 AS deps
# Install build dependencies
RUN apt-get update && apt-get install -y python3 ffmpeg make g++ build-essential && rm -rf /var/lib/apt/lists/*
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate
WORKDIR /repo
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
COPY scripts ./scripts
COPY patches ./patches
RUN mkdir -p packages/happy-app packages/happy-server packages/happy-cli packages/happy-wire
COPY packages/happy-app/package.json packages/happy-app/
COPY packages/happy-server/package.json packages/happy-server/
COPY packages/happy-cli/package.json packages/happy-cli/
COPY packages/happy-wire/package.json packages/happy-wire/
# Workspace postinstall requirements
COPY packages/happy-app/patches packages/happy-app/patches
COPY packages/happy-server/prisma packages/happy-server/prisma
COPY packages/happy-cli/scripts packages/happy-cli/scripts
COPY packages/happy-cli/tools packages/happy-cli/tools
RUN SKIP_HAPPY_WIRE_BUILD=1 pnpm install --frozen-lockfile
# Stage 2: build the server
FROM deps AS builder
COPY packages/happy-wire ./packages/happy-wire
COPY packages/happy-server ./packages/happy-server
RUN pnpm --filter @slopus/happy-wire --fail-if-no-match build
RUN pnpm --filter happy-server --fail-if-no-match build
# Stage 3: runtime
FROM node:20 AS runner
WORKDIR /repo
# Runtime dependencies
RUN apt-get update && apt-get install -y python3 ffmpeg && rm -rf /var/lib/apt/lists/*
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate
# Set environment to production
ENV NODE_ENV=production
# Copy necessary files from the builder stage
COPY --from=builder /repo/node_modules /repo/node_modules
COPY --from=builder /repo/packages/happy-wire /repo/packages/happy-wire
COPY --from=builder /repo/packages/happy-server /repo/packages/happy-server
# Expose the port the app will run on
EXPOSE 3000
# Command to run the application
COPY --from=builder /repo/package.json /repo/pnpm-workspace.yaml /repo/
WORKDIR /repo/packages/happy-server
CMD ["pnpm", "run", "start"]