Skip to main content

Deployment & Build

Docker image, Vite/Rollup externalization gotchas, staging deploy workflow.

Deep-dive doc split out of .claude/rules/architecture.md (which is now an index). Append new findings about this area here, not to the index.

Docker image​

Dockerfile is minimal: FROM node:24-alpine, COPY . ., RUN npm ci, RUN npm run build, CMD npm run start. Two consequences:

  • npm ci does NOT use --omit=dev — devDependencies (tsx, prisma, vitest, etc.) ship in the production image. This is what makes tsx scripts/...ts work from the DO console without further changes. If the image is ever slimmed via --omit=dev, all tsx-based scripts will break unless tsx is moved to dependencies.
  • COPY . . copies the entire working tree, including scripts/ and src/. So scripts that import from ../src/... continue to resolve at runtime; nothing is pruned.

Vite/Rollup Build — dependencies Are Externalized by Bare Specifier Only (INFRA-611)​

vite.config.ts's rollupOptions.external array externalizes third-party packages so npm run build (vite build, emitting dist/index.js as pure ESM per build.lib.formats: ['es']) doesn't bundle them — mostly via ...Object.keys(dependencies) (every package.json dependencies entry, by exact bare specifier), plus a few explicit extra strings/regexes ('express', /^node:/, etc.). A regex entry is required, not the bare-string form, for any package whose code is imported via a deep subpath (e.g. 'nodemailer/lib/mail-composer', not 'nodemailer') — Object.keys(dependencies) only ever contributes exact bare package-name strings, and Rollup's external matching is exact-string (or regex/function) against the full imported specifier, so a subpath import silently falls through and gets bundled even though the bare package name is nominally "external". This was already hit once before and fixed for @shopify/shopify-api/adapters/node-style subpaths via a dedicated /^@shopify\/shopify-api.*$/ regex entry (predates INFRA-611, comment explains the original tree-shaking/dynamic-import symptom).

INFRA-611 gotcha, found live in Staging after INFRA-578 merged: src/clients/gmailClient.ts added import MailComposer from 'nodemailer/lib/mail-composer'; (deep subpath) for the new Gmail-notification client. Since only the bare 'nodemailer' string was externalized (via the dependencies spread), Rollup bundled nodemailer's internal lib/base64 submodule — which does class Base64Encoder extends Transform against Node's stream built-in — and something in Rollup's bundling of that nested CJS chain broke the Transform reference, producing TypeError: Class extends value undefined is not a constructor or null at module-load time, i.e. before Express ever calls app.listen(). The container therefore never binds to its port, which is why DigitalOcean's automated deploy-failure diagnosis reported a "Port binding issue" — a real symptom, but a red herring for the actual root cause. The GMAIL_* env vars being present/absent in DO was a plausible-looking but incorrect first hypothesis; the crash reproduces identically even with all required env vars correctly set, since it happens at import-time, before any env-dependent code runs.

Fix requires two changes together (verified by checking out the merged commit in an isolated git worktree, running the real npm run build + node dist/index.js, and reproducing then resolving the exact stack trace):

  1. Add a regex externalizing the whole package's subpaths — /^nodemailer/ — alongside the existing /^@shopify\/shopify-api.*$/ entry, so Rollup stops bundling any of nodemailer's internals.
  2. Change the import to the fully-specified file path: 'nodemailer/lib/mail-composer/index.js'. This is necessary in addition to (1) — once truly externalized, the specifier is left as-is in the ESM output and Node's native ESM resolver (unlike CJS require) does not auto-resolve directory imports; without the explicit /index.js, boot instead fails with ERR_UNSUPPORTED_DIR_IMPORT.

Rule of thumb: any time a new dependency is consumed via a deep subpath import (rather than the package's main entry), check whether it needs its own regex external entry — the blanket Object.keys(dependencies) spread does not cover this case, and the failure mode (crash at container boot, before the port binds) is easy to misattribute to something else since it only manifests in the real vite build output, not in tsx/dev-mode runs (which don't bundle node_modules at all, so the bug is invisible locally under npm run dev).

Staging Deploy Workflow (.github/workflows/deploy-staging.yml)​

Push-to-main: biome→tsc→test→build (migrate DB, build/push image, rotate tags candidate→staging, prior :staging digest→:previous for rollback; registry ops via DO REST API not doctl, which mishandles multi-registry)→deploy. GC gotcha (INFRA-503): manual doctl registry garbage-collection start step is commented out — DO automated GC now enabled on manufacturing-admin-staging, manual call 412s (manual GC not available while automated GC enabled) and failed build (last step). Left commented (not deleted) for possible revert; don't re-enable while automated GC on. Prod workflow has no GC step.

Third-Party Action Pins — Where Each Runs (INFRA-832)​

Third-party actions are pinned as owner/action@<40-char SHA> # vX.Y.Z (project P-SITE-319). Always resolve the SHA from the upstream repo's tag with gh api repos/<owner>/<action>/commits/<tag> --jq .sha; never copy one from elsewhere, because GitHub also resolves commits that exist only in a fork.

None of the enterprise-tier actions run on a PR, so a PR's checks never prove their pins:

  • digitalocean/action-doctl — deploy-staging.yml (push to main, 2 steps) and the production-only build-tag-production.yml (tag push), release-tag-production.yml / release-latest-production.yml (workflow_dispatch). Note action-doctl@v2 is a branch, not a tag (refs/heads/v2), so it was even easier to move than a tag; git ls-remote 'refs/tags/v2^{}' returns nothing — resolve it with gh api repos/digitalocean/action-doctl/commits/v2.
  • google-github-actions/auth + setup-gcloud — only in reusable-build-gcp-image.yml / reusable-deploy-cloud-run.yml, called by deploy-gcp-staging.yml (push to main) and build-gcp-production.yml / deploy-gcp-production.yml.
  • slackapi/slack-github-action (method: chat.postMessage) — only in the three production release workflows; first exercised by the next production release.

deploy-workflows.spec.ts matches doctl steps with line.includes('uses: digitalocean/action-doctl'), which still matches an @<sha> ref, so SHA-pinning doesn't break the INFRA-625 version guard.

When a pin takes effect depends on the trigger. GitHub reads a workflow file from a different commit per trigger: workflow_dispatch workflows (release-tag-production.yml, release-latest-production.yml, deploy-gcp-production.yml) use the file on the branch you dispatch from — main by default — even though their jobs checkout an older tag via ref:; so their pins apply as soon as the PR merges. Tag-push workflows (build-tag-production.yml, build-gcp-production.yml) use the file at the tagged commit, so pins only apply to tags cut from main after the merge — re-pushing or re-running an older tag still runs that tag's unpinned actions.

AdminJS Components Bundle — Build Pipeline & the "Bad Bundle" Failure Mode​

Pipeline. npm run build (vite build) runs the adminJSBundler() plugin (scripts/build/vite-plugin-adminjs.ts) in closeBundle, which spawns npx tsx scripts/build/bundle-components.ts. That script calls bundle({ componentLoader, destinationDir: 'dist/adminjs-bundles' }) from @adminjs/bundler, emitting four files: global.bundle.js, design-system.bundle.js, app.bundle.js (copied from node_modules) and components.bundle.js (our custom components). Because this runs inside RUN npm run build in the Dockerfile, the bundle is baked into the image — a DO restart or DO "Force rebuild and deploy" re-serves the same broken file; only re-running the GitHub build job regenerates it.

How the bundle registers components. components.bundle.js is one IIFE taking globals (React, AdminJS, PropTypes, ReactDOM, ReactRouterDOM, AdminJSDesignSystem, ReactRouter, ReactRedux). Vendored third-party code is inlined at the top; the AdminJS.UserComponents.X = ... assignments all happen in a single statement at the very end. So a throw anywhere during vendor-module initialization registers zero components, and every custom property/action renders "Component X has not been bundled". Object.keys(componentLoader.getComponents()) (both .add and .override entries — 48 + 15 = 63 as of INFRA-710) is exactly the set that should end up on window.AdminJS.UserComponents.

Observed failure (2026-07-29, 2026-09-28). CI builds that passed produced a components.bundle.js that throws TypeError: Object.defineProperty called on non-object from a lazily-initialized CJS-interop module (d3-interpolate-style var r0={}; function tk(){ ... Object.defineProperty(r0, ...) }, called before its var initializer ran). The file was not truncated — it contained all 63 registrations and was within ~30 bytes of a good build — and a clean rebuild of the identical commit was fine. Treat it as non-deterministic module ordering in that build, not a code regression in whatever PR just shipped.

Reproducing / verifying without a browser. jsdom (already a dependency) reproduces the failure faithfully: evaluate the four bundles in order in a new JSDOM(..., { runScripts: 'outside-only' }) window via window.eval(...), then read window.AdminJS.UserComponents. Against the saved bad staging bundle this gives 0 components + the same TypeError in ~1s; against a good build, 63 + no errors. Chromium is not in the image (it would add ~821 MB — see work-order-pdf-export.md), so jsdom is the practical in-build check. To test a candidate bundle against real staging instead, Playwright page.route('**/admin/frontend/assets/components.bundle.js', ...) can swap in a locally served file on the unauthenticated /admin/login page (it loads all four bundles).

Post-build check (INFRA-710). scripts/build/bundle-components.ts now runs verifyComponentsBundle (scripts/build/verify-components-bundle.ts) right after bundle(): it loads the four bundles into jsdom and requires every name in componentLoader.getComponents() to be on window.AdminJS.UserComponents with no load errors, otherwise it process.exit(1)s — failing npm run build, and therefore docker build for DO staging, DO production and Dockerfile.gcpJobs, before any image is pushed. Adds ~0.5s. Deliberately no automatic retry: the root cause of the non-deterministic bad bundle is unknown, and a retry would hide how often it happens. If it fires on a commit that builds cleanly elsewhere, re-run the workflow; if it fires on every build, a component (or a new dependency it pulls in) throws at module-load time — the log names the error.

Never import utils/envConfig from anything config/componentLoader loads (INFRA-790). scripts/build/bundle-components.ts imports src/config/componentLoader, so its whole import graph runs during npm run build. envConfig runs envalid cleanEnv at import time and exits on the first missing required var — and the CI build job (and the Docker build) has no .env, so the build dies with Missing environment variables: … undefined followed by AdminJS bundling failed with code 1. It passes locally because your .env fills them in, so reproduce it by building in a clean worktree with env -i PATH="$PATH" HOME="$HOME" npm run build. src/config/makeComponentLoaderWithSelectiveLoad.ts therefore reads process.env directly after dotenv.config() (loads .env when present, never validates), mirroring envalid's bool() truthy set. Use the bare import dotenv from 'dotenv', never import 'dotenv/config' — the first version of this fix used the subpath, which is the INFRA-611 trap above: 'dotenv' is externalized by exact string, so dotenv/config + dotenv's main.js got bundled into dist/index.js, its require('path') interop broke, and the DO staging container crashed at boot with TypeError: t.resolve is not a function inside configDotenv (CI build and the AdminJS bundle check both passed — only node dist/index.js shows it). Verify with npm run build && grep -c configDotenv dist/index.js → must be 0.

Third-Party GitHub Action Pinning (INFRA-831)​

Scope (P-SITE-319). Every non-GitHub-owned uses: in .github/workflows/* is pinned to a commit SHA, tiered by maintainer risk: smaller orgs in INFRA-831 (biomejs/setup-biome), enterprise orgs in INFRA-832 (google-github-actions/*, digitalocean/action-doctl, slackapi/slack-github-action). Excluded: GitHub-owned actions/* / github/* and our own birdygrey/.github/...@main reusable workflows. Every third-party action here is published by the vendor of the tool it installs, so there are no community wrappers. Keep it that way when adding new actions.

Convention. owner/action@<40-char SHA> # vX.Y.Z — the trailing comment keeps the release readable. Verify a SHA before pinning with git ls-remote https://github.com/<owner>/<action> 'refs/tags/<tag>^{}' — use the peeled ^{} line, since annotated tags (setup-biome's are) otherwise return the tag object SHA, not the commit. Pin to the commit the floating major tag currently resolves to so behavior doesn't change. (gh api repos/<owner>/<action>/commits/<tag> --jq .sha — the form P-SITE-319 prescribes — peels automatically and gives the same answer.) Always derive the SHA from the upstream repo's tag, never copy one from a PR or blog post: GitHub resolves owner/action@<sha> for commits that exist only in a fork of that repo ("impostor commits"), so a SHA that merely looks right can run code the owner never published.

No Dependabot. The repo has no .github/dependabot.yml, so a SHA-pinned action never gets updated automatically — bumps are manual (re-run git ls-remote against the new tag and update SHA + comment together).

setup-biome takes no version input here — it auto-detects the Biome CLI version from the lockfile, then package.json (@biomejs/biome is pinned to 2.1.2), so pinning the action SHA doesn't change which Biome runs.

Spec-enforced pins. .github/workflows/deploy-workflows.spec.ts already guards digitalocean/action-doctl pinning (with: version:, INFRA-625) by scanning workflow text line-by-line for uses: digitalocean/action-doctl; changing other uses: lines doesn't affect it. It's the precedent if SHA-pin enforcement is ever wanted in CI.