Skip to content

Deployment · By Rivtor · Updated

Deploy a Turborepo with shared packages and separate services

Deploy Turborepo consumers from a build context containing their workspace dependencies, build those dependencies in the correct order and start only the intended runtime artifacts. A service root identifies the app; it does not necessarily contain every file needed to build it.

See the Rivtor deployment workflow →

Trace imports before choosing the build context

Consider apps/web importing packages/ui and apps/api importing packages/shared. Both applications need the root workspace metadata and relevant packages at build time. Installing only apps/api can fail if the package manager cannot see the workspace root or if a shared package has not emitted its output.

Keep the lockfile and package-manager version committed. A local machine with old dist files can hide a missing build dependency. The acceptance test must begin from a clean checkout.

Separate build dependency from runtime service

PathTypical role
apps/webFrontend build and possibly a web runtime
apps/apiAPI build and runtime
packages/sharedBuild/runtime dependency, not a public service by itself
Root workspace metadataDependency resolution and build orchestration

Declare dependencies so the build graph knows shared must build before its consumer. Turborepo orchestrates tasks; it does not by itself host the output. A cached build is useful only if its declared inputs and outputs are correct.

Package the runtime deliberately

For Docker, the build context must include files referenced by COPY. A Dockerfile inside apps/api does not make sibling directories available if the context is only apps/api. Use a reviewed root context or a properly pruned workspace and inspect what reaches the final image.

Rivtor documents monorepo detection and service overrides. Verify the detected roots and install/build commands against the repository. Do not assume one generic override can represent every workspace graph.

Test shared changes and private configuration

Change a harmless shared constant in a disposable branch and confirm each dependent artifact rebuilds. Start web and API independently using the production commands. Check that imports resolve without development symlinks or missing generated output.

Keep server secrets out of shared modules imported into browser code. Public frontend configuration can be a build input; private API configuration belongs to the server. Exercise a synthetic cross-service request after release and record the source revision used by both services to avoid debugging mismatched artifacts.

References