Run installs, migrations and seeds
A command that runs and ends, such as an install, a migration or a seed, is a task: devlanes runs it at the lane event you choose, or when you name it.
::example{slug="infra-postgres-shared"}
Add the tasks
Section titled “Add the tasks”tasks: install: run: [npm, install] when: lane.create migrate: run_script: file: package.json name: db:migrate when: lane.start seed: run_script: file: package.json name: db:seed when: lane.create after: servicestasksOne-shot commands such as installs, migrations and seeds, run by hand with devlanes run <name> or automatically at a lane event set with when. Tasks of the same event run in declaration order.
tasks.<name>A one-shot command, run by hand with devlanes run <name> or automatically at a lane event set with when. Anything that ends by itself belongs here, not in services, where an exit counts as a failure.
tasks.<name>.runCommand to run: a string runs through /bin/sh -c (pipes and multi-line scripts work), a list runs the program directly with those arguments. Use exactly one of run, run_script or steps. 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 }}.
tasks.<name>.whenLane event that runs this task automatically. Without it the task runs only by hand with devlanes run <name> or as a step of another task.
tasks.<name>.run_scriptScript to run from a project file, as { file, name }, such as { file: apps/api/package.json, name: migrate }. It runs with that file's tool (the project's package manager for package.json) in the file's directory, and a missing script fails before anything starts. Prefer it to run for scripts that live in a file. Use exactly one of run, run_script or steps.
tasks.<name>.run_script.fileFile that defines the script, relative to the project file's directory, such as apps/api/package.json. The script runs in this file's directory. Required unless an override or extends child keeps the inherited file.
tasks.<name>.run_script.nameScript, target, recipe, task, binary or package name in that file. For go.mod, a bare name such as api means ./cmd/api, and . or a path with / is relative to go.mod. For pom.xml and Gradle files it is the arguments as typed after mvn or gradle, such as -pl web -am spring-boot:run or :web:bootRun; quote an argument that contains spaces, as in a shell. It must name at least one goal or task. Required unless an override or extends child keeps the inherited name.
tasks.<name>.afterSet to services to run a lane.create or lane.start task after the started services are ready instead of before them, for work that goes through the running app, such as seeding through its API.
The install runs on a new lane’s first start, until it succeeds once, and again after you change its entry. The migration runs each time the lane comes up, before its services, so the migration tool has to skip what it already applied. The seed runs once the services are ready, for work that goes through the running app. Start order and readiness has the whole order.
Run a task by hand
Section titled “Run a task by hand”A task without an event runs only when you name it, and any task can be run that way:
$ devlanes run migrateIf a task is destructive
Section titled “If a task is destructive”Give it a question, which the run asks before it starts; scripts and agents pass --yes instead:
tasks: reset-db: steps: [infra.teardown.database, infra.setup.database, migrate, seed] confirm: Drop the database of ${{ lane.name }} and seed it again?tasksOne-shot commands such as installs, migrations and seeds, run by hand with devlanes run <name> or automatically at a lane event set with when. Tasks of the same event run in declaration order.
tasks.<name>A one-shot command, run by hand with devlanes run <name> or automatically at a lane event set with when. Anything that ends by itself belongs here, not in services, where an exit counts as a failure.
tasks.<name>.stepsRun these tasks and infra.setup.<name> or infra.teardown.<name> entries in order, stopping at the first failure, for jobs such as resetting a database. Each step runs whatever its own when says, and setup entries run again even when already done. Use instead of run or run_script.
tasks.<name>.confirmQuestion asked before the task runs, for destructive tasks. Scripts and agents without a terminal must pass --yes to run it.
The steps run in order, here the entries that drop and create the lane’s database from Share one database server between lanes, then two tasks.
If something must run at stop or clean
Section titled “If something must run at stop or clean”Tasks on lane.stop run when you stop the whole lane or the daemon, and tasks on lane.clean when you clean the lane. A logout or a shutdown of the machine skips stop tasks, so a dump that has to happen goes in a task you run yourself.