Cloud.MountVolume
Mount a Better Stack Cloud volume into a Cloud.Service, the port of
@alchemy.run/hetzner’s MountVolume.
yield* BetterStack.Cloud.MountVolume(volume, { path: "/data" }) inside
a Service’s implementation registers { volumes: [{ volumeId, path }] }
on the Service. On deploy the Service attaches the volume to its server
through the Cloud API (detaching it from another server first), then over
SSH creates the directory, mounts the device and appends an /etc/fstab
line (defaults,nofail) so the mount survives reboots; the unit gets
RequiresMountsFor=<path>. Every step is idempotent, and two Services
mounting the same (volume, path) on one server share one attach and
one mount.
Mounts are reference-counted per unit: when a Service stops binding the
volume (the binding is removed or the Service is deleted) and no other
Service on the server uses that path, the volume is unmounted and its
/etc/fstab line removed. The volume stays attached: detaching it is the
Cloud.Volume’s business (serverId: null).
The volume needs a filesystem (format: "ext4" or "xfs"); an
unformatted one fails the deploy with MountVolumeError (reason: "unformatted"). A volume created with autoMount: true is mounted by the
server under /mnt first; the Service moves it to path. Give the
Cloud.Volume the Service’s serverId (or leave serverId out after
create) so the two don’t fight over the attachment.
Bound anywhere else than a Cloud.Service (no host, or a Cloud.Server
host) it only returns the path and device: Cloud.Server declares the
same binding contract but does not act on it.
Mounting volumes
Section titled “Mounting volumes”Share a volume between two Services
const volume = yield* BetterStack.Cloud.Volume("data", { serverId: server.id, sizeGb: 10, format: "ext4",});const mount = yield* BetterStack.Cloud.MountVolume(volume, { path: "/data" });// mount.path === "/data"// mount.device: the device mounted at /data, read on the server at runtime ("" at deploy)