feat: docker usage examples & statfs

This commit is contained in:
Nicolas Meienberger
2025-09-25 21:13:49 +02:00
parent 86f7ae8a89
commit c261590ea3
16 changed files with 339 additions and 121 deletions

View File

@@ -11,9 +11,9 @@ import {
testConnectionDto,
updateVolumeBody,
updateVolumeDto,
type VolumeDto,
mountVolumeDto,
unmountVolumeDto,
type GetVolumeResponseDto,
} from "./volume.dto";
import { volumeService } from "./volume.service";
@@ -55,11 +55,14 @@ export const volumeController = new Hono()
const res = await volumeService.getVolume(name);
const response = {
...res.volume,
createdAt: res.volume.createdAt.getTime(),
updatedAt: res.volume.updatedAt.getTime(),
lastHealthCheck: res.volume.lastHealthCheck.getTime(),
} satisfies VolumeDto;
...res,
volume: {
...res.volume,
createdAt: res.volume.createdAt.getTime(),
updatedAt: res.volume.updatedAt.getTime(),
lastHealthCheck: res.volume.lastHealthCheck.getTime(),
},
} satisfies GetVolumeResponseDto;
return c.json(response, 200);
})

View File

@@ -100,6 +100,16 @@ export const deleteVolumeDto = describeRoute({
},
});
const getVolumeResponse = type({
volume: volumeSchema,
statfs: type({
total: "number",
used: "number",
free: "number",
}),
});
export type GetVolumeResponseDto = typeof getVolumeResponse.infer;
/**
* Get a volume
*/
@@ -113,7 +123,7 @@ export const getVolumeDto = describeRoute({
description: "Volume details",
content: {
"application/json": {
schema: resolver(volumeSchema),
schema: resolver(getVolumeResponse),
},
},
},

View File

@@ -10,6 +10,8 @@ import { db } from "../../db/db";
import { volumesTable } from "../../db/schema";
import { createVolumeBackend } from "../backends/backend";
import { toMessage } from "../../utils/errors";
import { getStatFs } from "../../utils/mountinfo";
import { VOLUME_MOUNT_BASE } from "../../core/constants";
const listVolumes = async () => {
const volumes = await db.query.volumesTable.findMany({});
@@ -99,11 +101,13 @@ const getVolume = async (name: string) => {
where: eq(volumesTable.name, name),
});
const statfs = await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`);
if (!volume) {
throw new NotFoundError("Volume not found");
}
return { volume };
return { volume, statfs };
};
const updateVolume = async (name: string, backendConfig: BackendConfig) => {

View File

@@ -51,3 +51,13 @@ export async function getMountForPath(p: string): Promise<MountInfo | undefined>
}
return best;
}
export async function getStatFs(mountPoint: string) {
const stats = await fs.statfs(mountPoint);
const total = Number(stats.blocks) * Number(stats.bsize);
const free = Number(stats.bfree) * Number(stats.bsize);
const used = total - free;
return { total, used, free };
}