bytelyst-devops-tools/dashboard/backend/src/modules/system/routes.ts
root fbaaa71a66 feat(devops): adopt trading web deployment model with docker-compose
- Add docker-compose.yml following trading web pattern
- Update web Dockerfile to use multi-stage build with metadata
- Add build metadata (commit SHA, branch, timestamp, author, message)
- Rewrite deploy.sh to use docker compose with build metadata
- Add hotcopy deployment script for quick updates
- Add comprehensive backend API with deployment orchestration
- Add health checks, service management, and monitoring endpoints
- Add CI/CD workflow configuration
- Add deployment documentation and guides

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-05-11 03:24:11 +00:00

47 lines
1.6 KiB
TypeScript

import type { FastifyInstance } from 'fastify';
import { getSystemMetrics, getDockerStats, dockerCleanup } from './repository.js';
import { DockerCleanupParamsSchema } from './types.js';
import { requireAdmin } from '../../lib/auth.js';
export async function systemRoutes(fastify: FastifyInstance) {
// Get system metrics (admin only)
fastify.get('/system/metrics', {
preHandler: async (req) => requireAdmin(req),
}, async (req, reply) => {
try {
const metrics = await getSystemMetrics();
return reply.send(metrics);
} catch (error) {
fastify.log.error('Failed to get system metrics:', error);
return reply.code(500).send({ error: 'Failed to get system metrics' });
}
});
// Get Docker stats (admin only)
fastify.get('/docker/stats', {
preHandler: async (req) => requireAdmin(req),
}, async (req, reply) => {
try {
const stats = await getDockerStats();
return reply.send(stats);
} catch (error) {
fastify.log.error('Failed to get Docker stats:', error);
return reply.code(500).send({ error: 'Failed to get Docker stats' });
}
});
// Docker cleanup (admin only)
fastify.post('/docker/cleanup', {
preHandler: async (req) => requireAdmin(req),
}, async (req, reply) => {
try {
const params = DockerCleanupParamsSchema.parse(req.body);
const result = await dockerCleanup(params.type, params.force);
return reply.send(result);
} catch (error: any) {
fastify.log.error('Docker cleanup failed:', error);
return reply.code(500).send({ error: error.message || 'Docker cleanup failed' });
}
});
}