Skip to content

MountVolume

Source: src/Fly/MountVolume.ts

Create a per-replica Fly Volume and mount it into a Service.

There is no standalone Volume resource. From a Machine, pass mounts: [{ path, sizeGb }] instead.

Yield MountVolume inside init. App and region come from the parent Service. Provide MountVolumeLive. At runtime you get disk.path.

A Volume attaches to one Machine. count: 3 creates three Volumes in one name-group, one per replica.

export default class Api extends Fly.Service<Api>()(
"Api",
{ app: Site, main: import.meta.url, region: "iad", count: 3, port: 3000 },
Effect.gen(function* () {
const disk = yield* Fly.MountVolume({ path: "/data", sizeGb: 1 });
const fs = yield* FileSystem.FileSystem;
return {
fetch: Effect.gen(function* () {
const text = yield* fs.readFileString(`${disk.path}/hello.txt`);
return HttpServerResponse.text(text);
}),
};
}).pipe(Effect.provide(Fly.MountVolumeLive)),
) {}

sizeGb can grow in place via extendVolume. Fly cannot shrink a Volume. Minimum size is 1 GB.

const disk = yield* Fly.MountVolume({ path: "/data", sizeGb: 10 });

encrypted encrypts the Volume at rest.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
encrypted: true,
});

fstype is the filesystem (ext4, …).

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
fstype: "ext4",
});

Scheduled snapshots default on (autoBackupEnabled). snapshotRetention is days and updates in place. An on-demand snapshot is VolumeSnapshot.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
autoBackupEnabled: true,
snapshotRetention: 5,
});

snapshotId restores into a new disk.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
snapshotId: Nightly.snapshotId,
});

sourceVolumeId forks from an existing Volume.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
sourceVolumeId: box.mounts[0].volumeId,
});

requireUniqueZone asks Fly to land the Volume in a unique zone.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
requireUniqueZone: true,
});

name is the Fly volume-group name. If omitted, a unique name is generated from the host’s logical ID and path.

const disk = yield* Fly.MountVolume({
path: "/data",
sizeGb: 1,
name: "api_data",
});