Give each lane its own container
Use this when a branch needs its own version of a database, or runs migrations that would break the other lanes: each lane gets a container and a volume of its own.
::example{slug="infra-postgres-per-lane"}
Write the service in the Compose file
Section titled “Write the service in the Compose file”The image creates the database POSTGRES_DB names, and each lane has a pgdata volume of its own.
services: postgres: image: postgres:17.11-alpine environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: myapp ports: ["127.0.0.1::5432"] volumes: [pgdata:/var/lib/postgresql/data] healthcheck: test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U postgres -d myapp"] interval: 2s retries: 30
volumes: pgdata:List it as per lane
Section titled “List it as per lane”A service under infra.per_lane runs once for each lane, on a port from that lane’s block of ports. The URL reads that port, so it differs in each lane. This needs Compose 2.24.4 or newer.
infra: compose: docker-compose.yml per_lane: [postgres]
global_env: DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ infra.postgres.port }}/myappinfraContainers the lanes depend on (databases, brokers, object stores), started and waited on before setup, tasks and services, plus the commands that create and remove each lane's data in them.
Config referenceinfra.composeCompose file, or a list of files merged like repeated -f, relative to the project. Its services are shared by every lane unless listed in per_lane; the shared project runs from the primary worktree with the .env next to the project file there as --env-file.
infra.per_laneCompose services run once per lane instead of shared, each in its own Compose project with ports from the lane's block and its own named volumes, removed by devlanes lane clean. Needs Compose 2.24.4 or newer.
global_envVariables for every service and task of the lane, above devlanes' own variables (PORT, DEVLANES_*) and below each unit's env and the profile's env. Use it for values many units share, such as a database URL built from ${{ infra.postgres.port }}. An entry without a value, such as one that reads a container a profile with infra: false left stopped, fails every service and task of the lane, so a value only some services need belongs in their env. devlanes exec leaves such an entry out and names it. Never set PORT here: it would replace every service's own port.
global_env.<name>Variables for every service and task of the lane, above devlanes' own variables (PORT, DEVLANES_*) and below each unit's env and the profile's env. Use it for values many units share, such as a database URL built from ${{ infra.postgres.port }}. An entry without a value, such as one that reads a container a profile with infra: false left stopped, fails every service and task of the lane, so a value only some services need belongs in their env. devlanes exec leaves such an entry out and names it. Never set PORT here: it would replace every service's own port.
A plain docker compose in a setup entry reaches the shared containers. To run a command in the lane’s own container, name its Compose project with -p "$DEVLANES_COMPOSE_LANE_PROJECT".
Start and clean the lane
Section titled “Start and clean the lane”Each start brings up the lane’s container. Stopping the lane leaves the container running; cleaning the lane removes the container and its volume, so its data is gone.
$ devlanes start$ devlanes lane clean 1 --yesIf you replace the container
Section titled “If you replace the container”A start into a running lane does not recreate a container you removed, for example to use a newly pulled image. Bring it back in the lane’s worktree:
$ devlanes infra upIf the container is not in a Compose file
Section titled “If the container is not in a Compose file”Set infra.containers.<name>.per_lane, as in Run containers without Compose.