Services the app depends on (compose.yaml)

in Japanese(日本語)

If the app under test needs a database, an API or a stub server, declare it in TestProjects/<project>/workspace/scripts/compose.yaml (next to run-setup.sh). fleetest starts the services for each run and stops them afterwards. It waits until they are up (the healthcheck) before run-setup.sh runs, and stops them after run-teardown.sh. If the file is not there, nothing happens.

It works with fleetest run, a run from the VSCode extension and the MCP tool ft_start_run. It does not start with ft_run_scenario (a single scenario) or --dry-run; to have the services up while you explore, use fleetest services up (Starting and stopping by hand). For a run sent to a runner machine, the services start on the runner machine (with that machine's runtime and settings).

Runtime

fleetest uses Docker (Rancher Desktop, Docker Desktop and so on, through the unix socket) or Apple Container (the container command). To fix the choice, set it in ~/.config/fleetest/config.json on this Mac:

{
  "services": { "runtime": "docker" }
}

runtime is "docker" or "apple". When it is not set, fleetest looks for Docker and then Apple Container, and uses the one that is usable only if exactly one is. When both are usable (Docker is running and Apple Container's system service is started too), it does not pick one silently: it stops and asks you to name one with runtime. It starts Apple's system service automatically only when Docker is not usable.

Example

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      # Apple Container's volumes have lost+found at their root, which initdb refuses; use a subdirectory
      PGDATA: /var/lib/postgresql/data/pgdata
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 2s
      retries: 30
    volumes:
      - dbdata:/var/lib/postgresql/data
  api:
    image: example/api:latest
    depends_on:
      db:
        condition: service_healthy
    ports: ["127.0.0.1:8080:8080"]
    environment:
      API_TOKEN: ${API_TOKEN}

volumes:
  dbdata:

The app and the scenarios reach api at 127.0.0.1:8080 (an app inside an Android Emulator uses 10.0.2.2:8080).

What you can write

The syntax is the same as compose.

Rules

Secrets

Put secrets in ~/.config/fleetest/secrets/<project>.env on this Mac, as KEY=value lines, and refer to them in the environment values of compose.yaml with ${NAME} (only the values of environment can refer to them). Only the names you refer to are also passed to run-setup.sh / run-teardown.sh as environment variables. The values are masked in fleetest's output (console and logs). Scenarios and scripts cannot read this file.

For substitutions that are not secret, write them in scripts/.env (same ${NAME} notation).

Physical devices

A run that includes a lane of a physical device (a real iPhone or Android phone) requires this in this Mac's settings:

{
  "services": { "publishForPhysicalDevices": "<this Mac's LAN IPv4 address>" }
}

Without it the run does not start, and the message says how to write it.

UDP

If ports has a /udp entry, fleetest checks the UDP path once after startup (an echo, 1 second, 3 times). If it does not arrive, the run stops before any scenario and says why (an app whose UDP never arrives would otherwise fail in ways that look like app bugs). When Rancher Desktop's port forwarding is SSH, UDP does not pass, and the message names that setting and how to switch it. Warnings that do not stop a run (a failed adb reverse) are recorded in its run.json as servicesWarnings.

Images on a machine without registry access

Images are pulled by the runtime when they are missing, so the first run needs access to the registry. To prepare ahead of time, or on a machine without that access:

Command What it does
fleetest services pull [--project <p>] [--profile <pf>] [--refresh] Pulls the images compose.yaml declares (and builds fleetest's relay image on first use) without starting anything. --refresh pulls them again even when they are present
fleetest services load <file> Loads images from a tar archive made with docker save or container image save into this Mac's runtime

Operating the containers from the scripts

The only way for run-setup.sh / run-teardown.sh to operate the containers is the relay command fleetest-services (it is on PATH). Only the services you declared are targeted.

fleetest-services exec db -- psql -U app < "$FT_WORKSPACE/data/seed.sql"   # standard input is passed too
fleetest-services logs api --tail 100
fleetest-services status
fleetest-services port api 8080            # prints the published host:port (/udp for UDP)
Command What it does
fleetest-services exec <service> -- <command…> Runs a command in the service's container
fleetest-services logs <service> [--tail N] Prints the log
fleetest-services status Prints the state of the services
fleetest-services port <service> <containerPort>[/udp] Prints the published host:port

The scripts themselves run in their own sandbox (Running scripts before and after a run).

Starting and stopping by hand

For exploring, Live Control and writing scenarios, a person can start the services before a run.

Command What it does
fleetest services up [--project <p>] [--profile <pf>] [--physical] [--serial <adb serial>…] Starts the services, waits until they are up, prints the published ports and returns. The services keep running afterwards (a resident owner process holds them; the log is .fleetest/services/<prefix>.log)
fleetest services down [--project <p>] [--profile <pf>] Stops them
fleetest services status [--project <p>] [--profile <pf>] Shows the record, the lock and the resources on the runtime, with the size of each named volume and of the images fleetest built (the build: images of this workspace and the relay image). Nothing is deleted automatically; use reset when they have grown
fleetest services reset [--project <p>] [--profile <pf>] [--force] Deletes this workspace's containers, networks, volumes and record. --force is needed while an up holds them (it stops that up first). While a run holds them, even --force deletes nothing (wait for the run to finish)

--profile is used only to find where the services live (the workspace). up, down, status and reset can omit --profile when every run profile uses the same workspace (any of them gives the same services); when the workspaces differ, they stop with --profile is required. Omitting --project picks project1.

Services started with up show on their machine's row of the run board in the VSCode extension's monitor as "Servers up".

A real run (fleetest run / ft_start_run) takes over services started with up: it prints a warning, stops them, starts them again itself and stops them itself (so that the result is reproducible). After stopping them, it starts services up again with the same options as before the run (the run does not wait for the services to be ready; check with fleetest services status). After an interrupted run it does not, so run fleetest services up again. While a run holds the services, services down is refused.

From MCP, ft_services does the same: action is up / down / status, profile can be omitted when every run profile uses the same workspace, and project, physical and androidSerials (an array of strings) are optional. Like ft_start_run, it asks for approval (MCP server).

When a run dies halfway

If a run dies without cleaning up (an ssh disconnection, SIGKILL), the next run on that machine or fleetest hooks reap removes the containers and networks using the IDs it recorded. On a runner machine, use fleetest remote clean.