Learning paths / Deploy on ComputeSphere / Deploy from a repository

Going further: monorepos, root directory and watch paths

Reading · 5 min · Module 3, lesson 5 of 610 min left in this module

Module 3 · Deploy from a repositoryLesson 5 of 6

Goal: Build one service from a subfolder of a repository that holds several apps.

Key idea

A monorepo keeps several apps in one repository, each in its own folder, and each folder becomes its own service. Set a service's Root directory to its folder and the build runs there, so your commands look like a single-app repository's.

This lesson is optional. Skip it if each of your apps has its own repository.

The repository behind these labs is a monorepo:

learn/
└── labs/
    ├── hello-web/     (a web page, port 8080)
    └── sample-api/    (a small API, port 8080)

Building from a subfolder

Open the service's Settings and choose Edit build source. Set Root directory to the service's folder, such as labs/hello-web; every path is from the repository root.

With a runtime build (Managed), your commands run inside that folder. For hello-web, a Go service:

  • Runtime: Go 1.23 or newer
  • Build command: go build -o /app/app .
  • Start command: ./app

The build command compiles and writes the program to /app, the folder the start command runs from. A Node.js app in apps/web would build with npm install && npm run build and start with npm start.

With a Dockerfile, put it in the same folder. A file named Dockerfile is read from the root directory, and the build runs in that folder:

FROM golang:1.23-alpine AS build
WORKDIR /src
COPY . .
RUN go build -o /out/app .

FROM alpine:3.21
COPY --from=build /out/app /app
EXPOSE 8080
CMD ["/app"]

Only that folder goes into the image, so a change elsewhere in the repository can't affect it.

Watch paths

Watch paths sit next to the root directory and say which changed files start a build on push, such as labs/hello-web/**. They're comma-separated patterns; with none set, every push builds. Builds you start yourself always run.

With watch paths set on both services, a push that only touches labs/sample-api/ rebuilds sample-api and leaves hello-web alone.

Shared code between services

If services share a folder, say libs/, include it in each service's watch paths: labs/hello-web/** and libs/**. Otherwise a fix to the shared code wouldn't rebuild the services that use it.

Root directory and watch paths are in the service's Settings: choose Edit build source.

Check yourself

Your Node.js app lives in apps/web, and its Root directory is set to apps/web. Which build command works?

In the docs