Keep Redis, RabbitMQ, S3 and mail apart per lane
Use this when the lanes of a project share a store such as Redis or RabbitMQ: each lane gets a namespace of its own inside it, so one lane’s code does not see another lane’s keys, queues or files.
::example{slug="infra-multi-database"}
Name a namespace per lane
Section titled “Name a namespace per lane”One variable per store under lanes.vars. Setup creates the namespace, teardown removes it when you clean the lane, and the URL points into it. The stores are services in your Compose file, as in Share one database server between lanes.
lanes: vars: redis_db: "${{ lane.index }}" vhost: "myapp_${{ lane.name }}" # S3 bucket names allow no underscores. bucket: "myapp-${{ lane.name }}"lanesWhich worktrees get a lane, how many ports each lane reserves, and values computed per lane (lane.<name>).
lanes.varsValues computed for each lane and read as ${{ lane.<name> }}, such as a database name, vhost, bucket or Redis index per lane. Build names from ${{ lane.name }}, which is main in lane 0 and lane<N> in lane N whatever the branch, and numbers from ${{ lane.index }}. A var named domain replaces the default lane domain, and one named port fixes where the lane's port block starts. ${{ domain('pages') }} gives a name a site of its own in each lane, such as pages2.localhost in lane 2. Cannot be combined with matrix.
lanes.vars.<name>Values computed for each lane and read as ${{ lane.<name> }}, such as a database name, vhost, bucket or Redis index per lane. Build names from ${{ lane.name }}, which is main in lane 0 and lane<N> in lane N whatever the branch, and numbers from ${{ lane.index }}. A var named domain replaces the default lane domain, and one named port fixes where the lane's port block starts. ${{ domain('pages') }} gives a name a site of its own in each lane, such as pages2.localhost in lane 2. Cannot be combined with matrix.
Create it and pass its URL
Section titled “Create it and pass its URL”Redis
Each lane uses the numbered database that matches its lane number.
infra: teardown: redis: docker compose exec -T redis redis-cli -n ${{ lane.redis_db }} FLUSHDBglobal_env: REDIS_URL: redis://127.0.0.1:${{ infra.redis.port }}/${{ lane.redis_db }}infraContainers 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.teardownNamed commands that remove a lane's data when the lane is cleaned (devlanes lane clean), one after another; never on stop. A failure is reported and the cleanup goes on.
infra.teardown.<name>Command that prepares (setup) or removes (teardown) a lane's data: a command string or list, or a mapping with run and options such as container, ignore_errors and timeout. Task steps can run it as infra.setup.<name> or infra.teardown.<name>.
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.
RabbitMQ
A vhost per lane. The Compose service sets the user app and a fixed hostname, so a recreated container keeps its vhosts. container runs the entry again after RabbitMQ restarts.
infra: setup: rabbitmq: run: | docker compose exec -T rabbitmq rabbitmqctl add_vhost ${{ lane.vhost }} && docker compose exec -T rabbitmq rabbitmqctl set_permissions -p ${{ lane.vhost }} app '.*' '.*' '.*' container: rabbitmq teardown: rabbitmq: run: docker compose exec -T rabbitmq rabbitmqctl delete_vhost ${{ lane.vhost }} ignore_errors: trueglobal_env: AMQP_URL: amqp://app:app@127.0.0.1:${{ infra.rabbitmq.ports['5672'] }}/${{ lane.vhost }}infraContainers 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.setupNamed commands that prepare each lane's data, such as creating its database in a shared Postgres. They run once per lane after the containers are ready, all at the same time, and are recorded as done so later starts skip them; a failure stops the start unless the entry sets ignore_errors.
infra.setup.<name>Command that prepares (setup) or removes (teardown) a lane's data: a command string or list, or a mapping with run and options such as container, ignore_errors and timeout. Task steps can run it as infra.setup.<name> or infra.teardown.<name>.
infra.setup.<name>.runCommand to run: a string runs through /bin/sh -c, a list runs the program directly. Write the command you mean, such as docker compose exec -T postgres ...; devlanes runs it as written. Required. 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 }}.
infra.setup.<name>.containerRun this setup entry again whenever the named container has restarted since it last ran, for data that lives in the container and may be gone, such as a RabbitMQ vhost.
Config referenceinfra.teardownNamed commands that remove a lane's data when the lane is cleaned (devlanes lane clean), one after another; never on stop. A failure is reported and the cleanup goes on.
infra.teardown.<name>Command that prepares (setup) or removes (teardown) a lane's data: a command string or list, or a mapping with run and options such as container, ignore_errors and timeout. Task steps can run it as infra.setup.<name> or infra.teardown.<name>.
infra.teardown.<name>.runCommand to run: a string runs through /bin/sh -c, a list runs the program directly. Write the command you mean, such as docker compose exec -T postgres ...; devlanes runs it as written. Required. 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 }}.
infra.teardown.<name>.ignore_errorsCount a failed or timed-out command as done instead of failing the start, for commands whose "already exists" error is fine. Defaults to false.
Config referenceglobal_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.
S3
A bucket per lane, here in RustFS. The bucket commands run from an rc service in the Compose file that has profiles: [tools], so it does not start with the lanes.
infra: setup: s3: docker compose run --rm rc bucket create --ignore-existing --format human local/${{ lane.bucket }} teardown: s3: run: docker compose run --rm rc bucket remove --force --format human local/${{ lane.bucket }} ignore_errors: trueglobal_env: S3_URL: http://rustfsadmin:rustfsadmin@127.0.0.1:${{ infra.rustfs.ports['9000'] }}/${{ lane.bucket }}infraContainers 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.setupNamed commands that prepare each lane's data, such as creating its database in a shared Postgres. They run once per lane after the containers are ready, all at the same time, and are recorded as done so later starts skip them; a failure stops the start unless the entry sets ignore_errors.
infra.setup.<name>Command that prepares (setup) or removes (teardown) a lane's data: a command string or list, or a mapping with run and options such as container, ignore_errors and timeout. Task steps can run it as infra.setup.<name> or infra.teardown.<name>.
infra.teardownNamed commands that remove a lane's data when the lane is cleaned (devlanes lane clean), one after another; never on stop. A failure is reported and the cleanup goes on.
infra.teardown.<name>Command that prepares (setup) or removes (teardown) a lane's data: a command string or list, or a mapping with run and options such as container, ignore_errors and timeout. Task steps can run it as infra.setup.<name> or infra.teardown.<name>.
infra.teardown.<name>.runCommand to run: a string runs through /bin/sh -c, a list runs the program directly. Write the command you mean, such as docker compose exec -T postgres ...; devlanes runs it as written. Required. 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 }}.
infra.teardown.<name>.ignore_errorsCount a failed or timed-out command as done instead of failing the start, for commands whose "already exists" error is fine. Defaults to false.
Config referenceglobal_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 mail catcher has nothing to split, so each lane runs its own Mailpit (Give each lane its own container).
infra: per_lane: [mailpit]global_env: SMTP_URL: smtp://127.0.0.1:${{ infra.mailpit.ports['1025'] }}infraContainers 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.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.
Start each lane as usual, and its setup creates its namespaces.
$ devlanes startIf you want a store’s web UI
Section titled “If you want a store’s web UI”Route a hostname under the lane’s domain to the UI’s container port. A shared store shows every lane’s namespaces there.
infra: hosts: rabbitmq: { host: "rabbitmq.${{ lane.domain }}", port: "15672" } mailpit: { host: "mail.${{ lane.domain }}", port: "8025" }infraContainers 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.hostsHTTPS hostnames for containers, keyed by Compose service or plain container name, so a browser can open a container's web port: a MinIO console or presigned S3 URLs, Mailpit, a mock OIDC provider. A hostname routes to the container's first published port unless its route sets port; each key takes one hostname or route, or a list.
infra.hosts.<name>HTTPS hostnames the devlanes proxy routes to this unit, so a browser reaches it at https://<host>: one hostname or route mapping, or a list of them.
infra.hosts.<name>.hostHostname to route, evaluated for each lane. A leading *. makes a wildcard that matches any depth below it but not the name itself; quote it in YAML. Labels hold letters, digits and inner hyphens; case and a trailing dot are ignored.
infra.hosts.<name>.portSend this hostname to one of the unit's named ports instead of its main port. For a service it is a port name as in self.ports.<name>, and naming it here allocates that port; in infra.hosts it is the container port for Compose services, or the port's name for plain containers.
If you run more than 16 lanes on Redis
Section titled “If you run more than 16 lanes on Redis”Redis has 16 databases unless its databases setting raises the number.