mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: docker volume prefix
This commit is contained in:
@@ -32,10 +32,10 @@ export const scalarDescriptor = Scalar({
|
||||
const driver = new Hono().use(honoLogger()).route("/", driverController);
|
||||
const app = new Hono()
|
||||
.use(honoLogger())
|
||||
.get("*", serveStatic({ root: "./assets/frontend" }))
|
||||
.get("healthcheck", (c) => c.json({ status: "ok" }))
|
||||
.basePath("/api/v1")
|
||||
.route("/volumes", volumeController);
|
||||
.get("/healthcheck", (c) => c.json({ status: "ok" }))
|
||||
.route("/api/v1/volumes", volumeController)
|
||||
.get("/assets/*", serveStatic({ root: "./assets/frontend" }))
|
||||
.get("*", serveStatic({ path: "./assets/frontend/index.html" }));
|
||||
|
||||
app.get("/openapi.json", generalDescriptor(app));
|
||||
app.get("/docs", scalarDescriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Hono } from "hono";
|
||||
import { VOLUME_MOUNT_BASE } from "~/core/constants";
|
||||
import { volumeService } from "../volumes/volume.service";
|
||||
import { config } from "../../core/config";
|
||||
|
||||
export const driverController = new Hono()
|
||||
.post("/VolumeDriver.Capabilities", (c) => {
|
||||
@@ -30,8 +30,9 @@ export const driverController = new Hono()
|
||||
return c.json({ Err: "Volume name is required" }, 400);
|
||||
}
|
||||
|
||||
const volumeRoot = config.volumeRootHost;
|
||||
const mountpoint = `${volumeRoot}/${body.Name}/_data`;
|
||||
const volumeName = body.Name.replace(/^im-/, "");
|
||||
|
||||
const mountpoint = `${VOLUME_MOUNT_BASE}/${volumeName}/_data`;
|
||||
|
||||
return c.json({
|
||||
Mountpoint: mountpoint,
|
||||
@@ -54,13 +55,12 @@ export const driverController = new Hono()
|
||||
return c.json({ Err: "Volume name is required" }, 400);
|
||||
}
|
||||
|
||||
const volumeRoot = config.volumeRootHost;
|
||||
const { volume } = await volumeService.getVolume(body.Name);
|
||||
const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, ""));
|
||||
|
||||
return c.json({
|
||||
Volume: {
|
||||
Name: volume.name,
|
||||
Mountpoint: `${volumeRoot}/${volume.name}/_data`,
|
||||
Name: `im-${volume.name}`,
|
||||
Mountpoint: `${VOLUME_MOUNT_BASE}/${volume.name}/_data`,
|
||||
Status: {},
|
||||
},
|
||||
Err: "",
|
||||
@@ -68,11 +68,10 @@ export const driverController = new Hono()
|
||||
})
|
||||
.post("/VolumeDriver.List", async (c) => {
|
||||
const volumes = await volumeService.listVolumes();
|
||||
const volumeRoot = config.volumeRootHost;
|
||||
|
||||
const res = volumes.map((volume) => ({
|
||||
Name: volume.name,
|
||||
Mountpoint: `${volumeRoot}/${volume.name}/_data`,
|
||||
Name: `im-${volume.name}`,
|
||||
Mountpoint: `${VOLUME_MOUNT_BASE}/${volume.name}/_data`,
|
||||
Status: {},
|
||||
}));
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import Docker from "dockerode";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
|
||||
import slugify from "slugify";
|
||||
import { config } from "../../core/config";
|
||||
import { VOLUME_MOUNT_BASE } from "../../core/constants";
|
||||
import { db } from "../../db/db";
|
||||
import { volumesTable } from "../../db/schema";
|
||||
@@ -32,14 +31,14 @@ const createVolume = async (name: string, backendConfig: BackendConfig) => {
|
||||
throw new ConflictError("Volume already exists");
|
||||
}
|
||||
|
||||
const volumePathHost = path.join(config.volumeRootHost);
|
||||
const volumePathHost = path.join(VOLUME_MOUNT_BASE);
|
||||
|
||||
const val = await db
|
||||
.insert(volumesTable)
|
||||
.values({
|
||||
name: slug,
|
||||
config: backendConfig,
|
||||
path: path.join(volumePathHost, slug),
|
||||
path: path.join(volumePathHost, slug, "_data"),
|
||||
type: backendConfig.backend,
|
||||
})
|
||||
.returning();
|
||||
@@ -210,7 +209,7 @@ const getContainersUsingVolume = async (name: string) => {
|
||||
const container = docker.getContainer(info.Id);
|
||||
const inspect = await container.inspect();
|
||||
const mounts = inspect.Mounts || [];
|
||||
const usesVolume = mounts.some((mount) => mount.Type === "volume" && mount.Name === name);
|
||||
const usesVolume = mounts.some((mount) => mount.Type === "volume" && mount.Name === `im-${volume.name}`);
|
||||
if (usesVolume) {
|
||||
usingContainers.push({
|
||||
id: inspect.Id,
|
||||
|
||||
Reference in New Issue
Block a user