Launching TestFlows Machine: self-service deterministic simulation testing environment Read the post

Disks

A disk is what a machine boots, and machine disks build makes one. You give it exactly one source.

Source What it takes
--binary path a static x86_64 executable, wrapped in a scratch image
--from ref a public image, by name, with the files you add to it
--image ref a Docker image of your own, as a save tar or a name in your local Docker
--compose dir a Compose project directory and the images its services name

Everything that runs in a machine runs under Docker Compose, inside the machine. A Compose project is one container for each of its services. An image or a binary is a project of one service, and --entrypoint and the arguments after -- are that service’s entrypoint and command. A binary is no exception: --binary wraps the executable in a scratch image, one layer holding that file and nothing else, with no base image, no loader and no libraries, and the machine runs that image as its one service. machine writes this image itself, so --binary needs no Docker on your computer.

Docker and Compose

An image of your own needs Docker. A Compose project also needs Docker Compose. Two sources need neither. machine disks build --binary wraps a static executable and nothing else, so a program you compile needs no Docker. The executable has to be self-contained. The image has no loader and no libraries, so a dynamically linked program cannot run. --from names a public image, and the build pulls it for you.

1
2
machine disks build --image myapp:latest app
machine disks build --compose ./deploy stack

The name defaults to whatever the source is called. With client 20261120-0351 and earlier, a disk built with --binary or --from whose name has a capital letter fails to start its program, and the console says repository name must be lowercase. Upgrade the client, or name the disk in lowercase.

Use --entrypoint to choose the executable the service runs. The service’s own arguments go after a --. This one runs data-race with the argument 3:

1
machine disks build --binary ./data-race race -- 3

From Python, client.disks.build takes the same sources as keywords: binary=, from_=, image= or compose=, with command= for the arguments after --. The SDK’s Disks has the rest.

1
disk = client.disks.build("race", binary="./data-race", command=["3"])

Programs that need a runtime

A program that is not a static executable needs an image that already contains what it runs: an interpreter, a runtime, its libraries. Public images have those, so name one with --from and put your files in it with --add. It reads like a Dockerfile, FROM then ADD then the command, and you need no Docker for it. The build pulls the image itself, so only your files are uploaded.

An image you built yourself, or one from a private registry, goes in with --image from your local Docker.

An application of several services is a Compose project.

Python program

Save this as hello.py.

1
print("hello, world")
1
machine disks build --from python:3.12-slim --add hello.py hello-py -- python hello.py

It runs in a machine with the default 256MB of memory, and takes about five seconds from power-on to the program’s exit.

Node.js program

Save this as hello.js.

1
console.log("hello, world")
1
machine disks build --from node:22 --add hello.js hello-node -- node hello.js

ClickHouse queries

The ClickHouse® image has clickhouse local, which runs SQL with no server. Save this as queries.sql.

1
2
3
CREATE TABLE orders (id UInt32, customer String, amount UInt32) ENGINE = Memory;
INSERT INTO orders VALUES (1, 'ada', 30), (2, 'grace', 45), (3, 'ada', 25);
SELECT customer, sum(amount) AS total FROM orders GROUP BY customer ORDER BY customer;
1
2
machine disks build --from clickhouse/clickhouse-server:24.8 --add queries.sql \
--entrypoint clickhouse ch-sql -- local --queries-file queries.sql

The machine’s console shows the result, and the machine ends when the queries do.

1
2
3
app | ada	55
app | grace 45
=== app exited by itself: code 0 ===

PostgreSQL queries

The PostgreSQL image starts a server, and it needs a password before it will. --env sets a variable in the service’s environment. The disk holds each --env value as written, and a value is not changed on the way: a $ in it arrives as a $. The image runs every .sql file in /docker-entrypoint-initdb.d when the server first starts, so add the queries there. Save them as queries.sql.

1
2
3
CREATE TABLE orders (id int, customer text, amount numeric);
INSERT INTO orders VALUES (1, 'ada', 30), (2, 'grace', 45), (3, 'ada', 25);
SELECT customer, sum(amount) AS total FROM orders GROUP BY customer ORDER BY customer;
1
2
machine disks build --from postgres:17 --env POSTGRES_PASSWORD=secret \
--add queries.sql:/docker-entrypoint-initdb.d/ pg
1
2
3
4
5
6
7
8
9
app | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/queries.sql
app | CREATE TABLE
app | INSERT 0 3
app | customer | total
app | ----------+-------
app | ada | 55
app | grace | 45
app | (2 rows)
app | 2026-03-01 00:00:50.435 UTC [1] LOG: database system is ready to accept connections

The server keeps running after the queries, so this machine does not end by itself. To run queries and have the machine end, use the PostgreSQL project.

The ClickHouse and PostgreSQL examples both ran in a machine with 1024MB of memory. A server that other services connect to is a Compose project.

Where added files go

--add puts a file or a directory in the image, as one more layer on top of the public one. You can repeat it.

You write Path in the image
--add hello.py the image’s working directory, as hello.py
--add conf the working directory, as the directory conf
--add hello.py:/app/ /app/hello.py
--add hello.py:/app/main.py /app/main.py
--add conf:/etc/app/ /etc/app/conf, the directory inside /etc/app
--add conf:/etc/app /etc/app, the directory’s contents

The rule is the one cp -r follows: a destination that ends in / is a directory the path goes into, and any other destination is what the path becomes. A Dockerfile ADD of a directory copies its contents; the last row is how you write that here.

--add keeps a file’s executable bit, so a script that was executable on your computer is executable in the image. --add works with --binary too, for a program that reads a file beside it.

--add takes files, directories and links. When you name a link, the image holds what the link points to, and a link inside an added directory stays a link. A device, a FIFO or a socket in the directory is refused. Every added file belongs to root in the image, so the set-user-id and set-group-id bits are not kept: a bit that meant “run as this file’s owner” on your computer would mean “run as root” there. An image that needs one is built with Docker and named with --image.

The image is the one the name pointed at when you ran the build. The build records its digest and pulls exactly that, so a tag that moves later does not change your disk. You can name a digest yourself, as python@sha256:… or the python:3.12@sha256:… that docker pull prints.

The disk’s size defaults to what the image needs plus a gigabyte. Use --dry-run to see the numbers, and --size for more room.

--from takes public images of up to 5GB, measured as downloaded. For a private image, a larger one, or one you build yourself, use --image:

1
2
docker build --platform linux/amd64 -t myapp:latest .
machine disks build --image myapp:latest app

An image that needs more than one service, such as a database server with a client, is a Compose project.

Compose projects

The examples have Compose environments under compose/. Clone them, pull each image for linux/amd64 into the local Docker, then build the disk from the project directory. machine disks build --compose packs those images and the project. The machine runs the project and ends it when a service exits on its own, stopping the others, or when the project is taken down with docker compose down. A service that Machine stops, kills or crashes with machine containers does not end the project.

1
2
git clone https://github.com/testflows/Machine.git
cd Machine/examples

The same project can be run on this computer first, from its own directory, so you can fix it without waiting for a machine to boot. The build commands below are from the examples directory.

A two-service project

compose/two-services is a busybox server and a client that fetches a file from it by the service name server. Services in a project reach each other by name, on the network Compose gives the project.

depends_on only orders the start. The client retries, because nothing waits for the server to accept connections. A service that takes time to become ready should use a healthcheck, and depends_on with condition: service_healthy.

1
2
docker pull --platform linux/amd64 busybox:1.36
machine disks build --compose compose/two-services two

To run it on this computer first:

1
2
cd compose/two-services
docker compose up --abort-on-container-exit

ClickHouse project

compose/clickhouse is a ClickHouse server and a client that queries it. Both services use one image, so the disk carries that image once. The client waits until the server is healthy, prints its result, and exits, which ends the project.

The server takes time to start before it accepts a query, so the project uses a healthcheck rather than a sleep. config.xml in the project replaces the image’s config. It makes the server listen on IPv4 only, because the machine’s kernel has no IPv6, and it caps the background pools, because the image’s defaults hang startup in a small machine. CLICKHOUSE_SKIP_USER_SETUP stops the entrypoint from restricting the default user to loopback, which would refuse the client.

The config is mounted from ./config.xml, a path inside the project. A bind mount from outside the project directory is refused. A named volume or a tmpfs is created empty when the machine boots.

1
2
docker pull --platform linux/amd64 clickhouse/clickhouse-server:24.8.14.39-alpine
machine disks build --compose compose/clickhouse ch

PostgreSQL project

compose/postgres is a PostgreSQL server and a client that runs queries.sql against it. Both services use one image. The client prints the results and exits, which ends the project, so this is how to run queries against PostgreSQL and have the machine end.

The client waits until the server is healthy. The healthcheck asks over TCP, because the image first starts a temporary server on its Unix socket alone to set the database up, and a check on the socket would pass before the real server is listening. ON_ERROR_STOP makes a failed query the client’s exit code. queries.sql is mounted from the project directory.

1
2
docker pull --platform linux/amd64 postgres:17
machine disks build --compose compose/postgres pg
1
2
3
4
5
6
7
8
9
client | CREATE TABLE
client | INSERT 0 3
client | customer | total
client | ----------+-------
client | ada | 55
client | grace | 45
client | (2 rows)
client |
=== client exited by itself: code 0 ===

Carrying images

A service can start containers of its own, through the machine’s Docker. No service of the project names the images those containers use, and a machine reaches no registry, so an image the project does not name is not on the disk.

A service with scale: 0 names an image and starts no container. The build packs every image the project names, these included, and Compose starts none of them. compose/clickhouse-regression carries the images its suite starts this way. Each further image, such as ZooKeeper or MinIO, needs a service of its own.

1
2
3
4
5
6
7
8
9
10
services:
regression:
image: regression-runner:local
working_dir: /opt/compose
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./:/opt/compose
carried_server:
image: clickhouse/clickhouse-server:24.8.14.39-alpine
scale: 0

The socket is /var/run/docker.sock. /run/docker.sock is not the machine’s socket, and the build refuses it.

./ is mounted at /opt/compose, the path the machine runs the project from. Compose resolves a bind on the machine’s filesystem, not inside the container that asked for it, so the two paths have to be the same. The images still have to be in the local Docker, under those names, before the build.

Project rules

Every service names an image with a tag or a digest. An image with no tag is a different image tomorrow, and a service that only has build has nothing to pack. Build the image, then set image.

The images have to be linux/amd64 and already in the local Docker. A logging driver, if the project sets one, is json-file, local, or none.

Volumes a crash cuts

machine containers crash cuts a service’s data the way a power cut would. It cuts the volumes the project names in an x-machine block, each with the most it may hold:

1
2
3
4
5
6
7
8
9
10
11
services:
db:
image: postgres:16
environment:
PGDATA: /var/lib/postgresql/data/pgdata
volumes: [db-data:/var/lib/postgresql/data]
volumes:
db-data: {}
x-machine:
volumes:
db-data: 4G

Each becomes an ext4 filesystem of its own on the disk, which costs only what is written to it. Its root holds lost+found, so a program that wants an empty directory takes one inside it: postgres refuses a data directory that is not empty, hence PGDATA above. The disk is made big enough for every volume to fill, and --dry-run shows the room they take:

1
2
3
4
size
used 811MB
volumes 4096MB
capacity 6144MB

The capacity is what the disk holds, plus the volumes full, plus a gigabyte, rounded up to a whole GB.

A volume in x-machine is a plain Compose volume: no driver_opts, not external. A project names 8 at most. A volume two services mount can’t be crashed while both run. Each volume in x-machine has a journal, which is what recovers it after a crash, so an fsync on it takes about four times as long as on a volume the block doesn’t name. Name only the volumes whose crashes you want to test.

Building disks on an ARM machine

A machine is an x86_64 computer, so a disk holds linux/amd64 programs, whatever machine you build it on. On a Mac with Apple Silicon or on arm64 Linux, Docker builds and pulls arm64 images by default, and those cannot run in a machine. machine disks build checks every image and refuses one that is not linux/amd64 before uploading anything. Ask Docker for linux/amd64:

1
2
3
docker pull --platform linux/amd64 myapp:latest
docker build --platform linux/amd64 -t myapp:latest .
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker compose -f ./deploy/compose.yaml build

The last one builds a Compose project’s images for linux/amd64; setting platform: linux/amd64 on each service does the same. Docker builds them under emulation, which is slower than a native build but works. For --binary, compile for x86_64 Linux, for example GOOS=linux GOARCH=amd64 go build.

Images at boot

A disk boots with its images already loaded, so the project starts as soon as Docker does.

A disk built with --load-at-boot keeps the images as docker save tars instead, and Docker loads them each time the disk boots.

1
machine disks build --load-at-boot --image myapp:latest app

That boot is slower by the whole load, every time, and the disk holds each image twice: the tar, and what it unpacks to. Use it when a service runs docker save or docker push on one of the disk’s own images from inside the machine. Starting containers does not need it.

Machine does not read layers compressed with zstd, so save the image with gzip or uncompressed layers.

Disk size

By default Machine measures what the disk holds and adds a gigabyte, rounded up to a whole GB. Use --size to set the size you want, and --dry-run to see what the disk would hold without building it.

1
machine disks build --dry-run --from python:3.12-slim --add hello.py hello -- python hello.py
1
2
3
4
5
6
7
8
9
disk
name hello
content
rootfs 285MB
images 142MB
project 1MB
size
used 428MB
capacity 2048MB

rootfs is the platform every disk carries. images is the images unpacked, with a layer two images share counted once. used is what a smaller --size is refused against, and the rest of capacity is what the machine can write. With --load-at-boot there is one more row, images (tar).

To manage your disks:

1
2
3
4
machine disks list
machine disks show app
machine disks rename app app-v2
machine disks delete app-v2

machine disks list and machine disks show give two sizes. SIZE is the disk as the machine sees it. DATA is what the disk takes in your account’s storage, after deduplication and compression.

1
2
NAME   ID            SIZE   DATA   STATE  CREATED  LABELS
hello 4d13d6d911ee 2.1GB 148MB ready 1h ago

Disks share what they have in common: every disk carries the same platform, and two disks built from one image share its layers. Storage keeps one copy, and each disk’s DATA counts it, so the column adds up to more than your disks take together. machine storage has that figure, and it is the one your quota counts. A disk that shows — for DATA gets a figure from machine disks verify.

To check the copy of a disk in your account’s storage:

1
machine disks verify app
1
✔ Verified app (4d13d6d911ee)

machine disks verify reads the disk back and computes its ID again. It takes about as long as reading the disk, and a disk that does not read as it was stored is reported as damaged, in which case build it again.

Deleting a disk is permanent. Machine refuses to delete one that a run still boots. --force deletes it anyway; the runs that boot it remain, but they can no longer start.

machine disks transfers shows the transfers in progress, and machine disks cancel stops one. An account can have at most 2 transfers in progress at a time, counting the uploads and downloads of every disk. A build you start while 2 are running is refused with Too many transfers in progress (max 2), so start it again once one of them ends.

ClickHouse is a registered trademark of ClickHouse, Inc. See clickhouse.com.