Services and paths
Copy page
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.
How Grayspar finds services
Section titled “How Grayspar finds services”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:
Found 2 services
SERVICE BUILT WITHapi Dockerfileweb Next.jsA Dockerfile meant to be built from the root of the repository, such as one kept in docker/, has to be named once:
grayspar deploy --dockerfile api=docker/api.DockerfileTo deploy only some services and leave the others running, name them with --service:
grayspar deploy --service webChoose a path
Section titled “Choose a path”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:
grayspar deploy --path web=/ --path api=/apiThe 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:
grayspar service set api --path /v2Run a service with no path
Section titled “Run a service with no path”A background worker takes no requests from the internet. To give a new service no path, deploy it with --no-path:
grayspar deploy --no-path workerFor a service that already exists, run grayspar service set worker --no-path. The status table then shows internal in place of an address.
Reach another service
Section titled “Reach another service”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.
Rename a service
Section titled “Rename a service”To rename a service, run grayspar service set with --name:
grayspar service set api --name backend