The lanes of all projects on a machine take their ports from one shared pool, so several projects, and several lanes of each, run at the same time without anyone keeping a list of ports. A service does not choose its port. devlanes hands it one and the service listens there.
Each lane takes a block from one pool
Section titled “Each lane takes a block from one pool”The pool runs from 20000 to 32767 by default, below the range Linux usually picks ports for outgoing connections from, so the system does not hand a lane’s port to another program. ports.range moves it.
A new lane takes the lowest free block of consecutive ports, and no two blocks overlap, whatever project they belong to. A block holds the ports the project needs with room to spare, at least ten, so adding a service usually fits in the block the lane already has.
A service has the same place in every lane
Section titled “A service has the same place in every lane”Inside the block each service has the same offset in every lane of the project. If the API is the first port of lane 0’s block, it is the first port of lane 1’s block too. devlanes stores these offsets, so a service keeps its port across restarts, edits of the project file and branch switches.
When the services you add no longer fit, the lane moves to a larger block the next time it restarts as a whole, and its ports change.
A service is handed its port
Section titled “A service is handed its port”devlanes passes each service its port in the PORT variable and the address to listen on in HOST. The proxy, the ready check and other services all reach the service there, so the one thing your code has to do is listen on that port. A dev server that takes its port as a flag gets it from an expression instead:
services: web: run: python -m http.server ${{ self.port }} --bind 127.0.0.1servicesLong-running processes of each lane, started together after infrastructure, setup and lane.start tasks. Each service gets its own port as PORT and, with hosts, HTTPS hostnames. A service that exits shows as failed and is not restarted.
services.<name>A long-running process started with the lane, such as a dev server or a worker. Each service gets its own port from the lane's block (PORT, ${{ self.port }}); devlanes stops it with the lane and never restarts it when it exits. A service needs run or run_script, directly or through extends.
services.<name>.runCommand that starts the service. A string runs with /bin/sh -c, so pipes, && and multi-line scripts work; a list is an argv run directly without a shell. It starts in the project file's directory unless cwd is set. devlanes runs it exactly as written, so it cannot be combined with preset; prefer run_script when the command is a script in a project file. Exactly one of run and run_script is required after templates are applied. In a list, an item that is one ${{ }} expression giving a number or true/false becomes its text, such as --port followed by ${{ self.port }}.
A service can have more ports
Section titled “A service can have more ports”A service that needs a second port, for a debugger or for metrics, names it in an expression, and devlanes gives it one in the same block, at the same place in every lane:
services: api: run: node --inspect=127.0.0.1:${{ self.ports.inspect }} server.mjsservicesLong-running processes of each lane, started together after infrastructure, setup and lane.start tasks. Each service gets its own port as PORT and, with hosts, HTTPS hostnames. A service that exits shows as failed and is not restarted.
services.<name>A long-running process started with the lane, such as a dev server or a worker. Each service gets its own port from the lane's block (PORT, ${{ self.port }}); devlanes stops it with the lane and never restarts it when it exits. A service needs run or run_script, directly or through extends.
services.<name>.runCommand that starts the service. A string runs with /bin/sh -c, so pipes, && and multi-line scripts work; a list is an argv run directly without a shell. It starts in the project file's directory unless cwd is set. devlanes runs it exactly as written, so it cannot be combined with preset; prefer run_script when the command is a script in a project file. Exactly one of run and run_script is required after templates are applied. In a list, an item that is one ${{ }} expression giving a number or true/false becomes its text, such as --port followed by ${{ self.port }}.
Give a service several ports and hostnames routes a hostname to such a port.
Ports differ between machines and hostnames do not
Section titled “Ports differ between machines and hostnames do not”Each machine has its own pool and its own lanes, so the ports of a lane depend on what else that machine runs. A colleague who clones myapp gets other port numbers than yours. Hostnames are built from the project name and the lane number, so api.myapp.localhost names lane 0’s API on both machines. Put hostnames, not ports, in a README, a bookmark or an OAuth callback.