Skip to content

MountVolume

Source: src/Railway/MountVolume.ts

Mount a Railway.Volume into a Service or Railway.Function.

yield* Railway.MountVolume(volume, { path: "/data" }) inside a Service/Function impl registers { mounts: [{ volumeId, path }] } on the host. Reconcile attaches the volume via volumeInstanceUpdate.

Railway allows one volume per service. A second mount is Railway.MultipleVolumes. Railway does not give each replica its own disk.

Yield MountVolume inside init. Provide MountVolumeLive. At runtime you get disk.path.

export default class Api extends Railway.Service<Api>()(
"Api",
{ project: Site, main: import.meta.url },
Effect.gen(function* () {
const disk = yield* Railway.MountVolume(Data, { path: "/data" });
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(Railway.MountVolumeLive)),
) {}