feat: add Docker service for container management and image pulls

This commit is contained in:
plenarius
2026-04-20 18:29:09 -04:00
parent ee7a0783ea
commit ec8aaf64a3
3 changed files with 210 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
import { Router } from "express";
import {
listForgeContainers,
pullImage,
startContainer,
stopContainer,
restartContainer,
getContainerLogs,
} from "../services/docker.service.js";
const router = Router();
router.get("/containers", async (_req, res) => {
try {
const containers = await listForgeContainers();
res.json(containers);
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.post("/pull", async (req, res) => {
const { image } = req.body;
if (!image) return res.status(400).json({ error: "image required" });
try {
await pullImage(image);
res.json({ ok: true });
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.post("/containers/:name/start", async (req, res) => {
try {
await startContainer(req.params.name);
res.json({ ok: true });
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.post("/containers/:name/stop", async (req, res) => {
try {
await stopContainer(req.params.name);
res.json({ ok: true });
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.post("/containers/:name/restart", async (req, res) => {
try {
await restartContainer(req.params.name);
res.json({ ok: true });
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.get("/containers/:name/logs", async (req, res) => {
const tail = parseInt(req.query.tail as string) || 100;
try {
const logs = await getContainerLogs(req.params.name, tail);
res.json({ logs });
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
export default router;