Skip to content
Dashboard

Services and paths

Copy page
View as Markdown

A project holds one or more services. A service is one program that runs on its own, such as a web frontend or an API. Each service that takes requests from the internet answers at a path of the project’s address.

Grayspar reads the folder you deploy the way its own tools read it, so you don’t write a configuration file:

  • A folder that holds one app becomes one service, called app.
  • In a monorepo, each app the workspace lists becomes a service named after its folder. Shared libraries stay libraries.
  • A folder with a Dockerfile is built with its Dockerfile. Any other folder is built with Railpack, which recognises the common languages and frameworks.

The CLI shows what it found before it builds anything:

Terminal window
Found 2 services
SERVICE BUILT WITH
api Dockerfile
web Next.js

A Dockerfile meant to be built from the root of the repository, such as one kept in docker/, has to be named once:

Terminal window
grayspar deploy --dockerfile api=docker/api.Dockerfile

To deploy only some services and leave the others running, name them with --service:

Terminal window
grayspar deploy --service web

A project has one address, and each service answers at a path of it. With two services, one usually takes / and the other a path such as /api. The CLI asks for any path it can’t work out. To answer on the first deploy, pass the paths as flags:

Terminal window
grayspar deploy --path web=/ --path api=/api

The longest matching path wins. A request for /api/<route> goes to api, and every other request goes to web.

A request reaches the service exactly as the browser sent it, so a service at /api receives /api/<route> and has to serve its routes under /api. A frontend’s dev proxy often removes /api on your laptop, as Vite’s rewrite option does. Mount the backend’s routes under /api before you deploy, or every request to it answers 404.

To change a path later, run grayspar service set. The change applies at once, with no deploy:

Terminal window
grayspar service set api --path /v2

A background worker takes no requests from the internet. To give a new service no path, deploy it with --no-path:

Terminal window
grayspar deploy --no-path worker

For a service that already exists, run grayspar service set worker --no-path. The status table then shows internal in place of an address.

The services of a project reach each other by name. For example, your web service can call the api service at http://api:8080, using the port api listens on. Requests between services skip the login check and carry no identity headers. Services in other projects can’t reach them.

A name keeps one address across deploys. A program that looks a name up once, as nginx does in proxy_pass, keeps reaching the service after it redeploys. A call between services arrives from the project network’s gateway address rather than from the calling service’s own.

To rename a service, run grayspar service set with --name:

Terminal window
grayspar service set api --name backend