Run a command with a lane's environment
Use this when a command that ends by itself, such as a database reset, needs the lane’s variables but not its services. A command that needs the services running goes through devlanes with, as Run tests against a lane shows.
Start the containers the command reads
Section titled “Start the containers the command reads”Neither way below starts a container. When the command reads a variable built from one, such as a database URL, start the containers first:
$ devlanes infra upDeclare a command you run often as a task
Section titled “Declare a command you run often as a task”A task without when runs only when you name it:
tasks: db-reset: run_script: file: package.json name: db:resettasksOne-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>.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.
$ devlanes run db-resetThe script runs with the variables of lane 1, starts no service, and the command exits with the script’s exit code. Run installs, migrations and seeds covers the rest of a task.
Run any other command with exec
Section titled “Run any other command with exec”Give the command a name and put it after the two dashes:
$ devlanes exec --name reset -- npx prisma migrate reset --force$ devlanes wait reset$ devlanes logs resetThe first command hands the reset to the daemon and returns at once. The second returns when the reset has ended, with exit code 0 when it succeeded and 1 when it did not. The third prints its output.
The command gets what global_env sets and a DEVLANES_PUBLIC_URL_<SERVICE> variable with the URL of each service. The settings of a single service do not reach it.
If you want the variables in your own terminal
Section titled “If you want the variables in your own terminal”$ devlanes env shellThis opens a shell with the lane’s variables, where you run the command yourself. exit leaves it.