Zaroz
Git builds

Monorepos

A monorepo holds several apps in one repository, for example apps/web and apps/api. In Zaroz each app is its own service, with its own builds, its own secrets and its own deploys. They all connect to the same repository.

Add the services

When you connect a repository, Zaroz looks in the folders up to two levels deep for apps. It recognises a folder that has a Dockerfile or a language file, such as package.json or go.mod. It skips hidden folders, node_modules and vendor.

If it finds more than one, it offers to create a service for each. You can create them all, or only one of them. You can add the others later.

Each service has a root directory, the folder of its app. Zaroz detects how to build the app from that folder. See How builds are detected.

Root directory and build context

These two are different:

  • The root directory is where the app is, for example apps/api. The Dockerfile path is relative to it.
  • The build context is the set of files the build can use. By default it is the root directory.

If your Dockerfile copies code from outside its own folder, for example packages/db, the context has to be bigger. Set the context to the repository root:

Code
[services.api] root = "apps/api" build.dockerfile = "Dockerfile" # apps/api/Dockerfile build.context = "." # the repository root

Only build when something changed

By default, a service builds only when a file under its root directory changes. A service with the root / builds on every push.

Add watch paths for code that lives elsewhere, such as a shared package. Watch paths do not apply to an Other git URL: Zaroz sees only the branch head there, so every push to the branch builds. In zaroz.toml:

Code
[services.web] root = "apps/web" build.watch = ["apps/web/**", "packages/ui/**"]

Watch paths are globs from the repository root. * matches within one folder name and ** matches across folders, so packages/ui/** is everything under packages/ui.

When a push changes none of the watched paths, Zaroz does not build. The push shows in the history as Skipped, with the paths that were checked, so you can see why. If Zaroz cannot tell which files changed, for example when the push is very large, it builds anyway. A build you did not need is better than one you missed.

One file for all the services

One zaroz.toml can describe all the services, with a [services.<name>] table for each:

Code
#:schema https://docs.zaroz.cloud/schemas/zaroz.toml/v1.json version = 1 [services.web] root = "apps/web" build.command = "pnpm --filter web build" build.watch = ["apps/web/**", "packages/ui/**"] deploy.start = "pnpm --filter web start" [services.api] root = "apps/api" build.builder = "dockerfile" build.dockerfile = "Dockerfile" build.context = "." build.watch = ["apps/api/**", "packages/db/**"] deploy.pre_deploy = "./bin/migrate up" deploy.health_check = { path = "/health" }

Each Zaroz service uses one entry, by name. The name is Entry in zaroz.toml. By default it is the service's slug, and Zaroz fills it in from the file when the repository is connected. You can see and change it in Source, When it builds and deploys.

If a service has no entry with its name, the build fails with config_no_entry.

You can also keep one small file in each app's folder. Zaroz looks for zaroz.toml in the service's root directory first, and in the repository root second.

Secrets

Build secrets belong to a service. If two services need the same token, add it to each. See Build secrets.

Last modified on