This commit is contained in:
root
2025-09-29 19:18:12 +00:00
parent 241a509a15
commit 38b96da4e7
2 changed files with 71 additions and 4 deletions
+20
View File
@@ -0,0 +1,20 @@
import { db } from './index.js';
const insertRedeployLogStmt = db.prepare(`
INSERT INTO redeploy_logs (stack_id, stack_name, status, message, endpoint)
VALUES (@stackId, @stackName, @status, @message, @endpoint)
`);
export function logRedeployEvent({ stackId, stackName, status, message = null, endpoint = null }) {
try {
insertRedeployLogStmt.run({
stackId: String(stackId),
stackName: stackName ?? 'Unknown',
status,
message,
endpoint
});
} catch (err) {
console.error('❌ Fehler beim Speichern des Redeploy-Logs:', err.message);
}
}
+51 -4
View File
@@ -7,6 +7,7 @@ import { Server } from 'socket.io';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { db } from './db/index.js'; import { db } from './db/index.js';
import { logRedeployEvent } from './db/redeployLogs.js';
dotenv.config(); dotenv.config();
@@ -155,16 +156,25 @@ app.put('/api/stacks/:id/redeploy', async (req, res) => {
const { id } = req.params; const { id } = req.params;
console.log(`🔄 PUT /api/stacks/${id}/redeploy: Redeploy gestartet`); console.log(`🔄 PUT /api/stacks/${id}/redeploy: Redeploy gestartet`);
let stack;
try { try {
broadcastRedeployStatus(id, true); broadcastRedeployStatus(id, true);
const stackRes = await axiosInstance.get(`/api/stacks/${id}`); const stackRes = await axiosInstance.get(`/api/stacks/${id}`);
const stack = stackRes.data; stack = stackRes.data;
if (stack.EndpointId !== ENDPOINT_ID) { if (stack.EndpointId !== ENDPOINT_ID) {
throw new Error(`Stack gehört nicht zum Endpoint ${ENDPOINT_ID}`); throw new Error(`Stack gehört nicht zum Endpoint ${ENDPOINT_ID}`);
} }
logRedeployEvent({
stackId: stack.Id || id,
stackName: stack.Name,
status: 'started',
message: 'Redeploy gestartet',
endpoint: stack.EndpointId
});
if (stack.Type === 1) { if (stack.Type === 1) {
console.log(`🔄 [Redeploy] Git Stack "${stack.Name}" (${id}) wird redeployed`); console.log(`🔄 [Redeploy] Git Stack "${stack.Name}" (${id}) wird redeployed`);
await axiosInstance.put(`/api/stacks/${id}/git/redeploy?endpointId=${stack.EndpointId}`); await axiosInstance.put(`/api/stacks/${id}/git/redeploy?endpointId=${stack.EndpointId}`);
@@ -195,12 +205,27 @@ app.put('/api/stacks/:id/redeploy', async (req, res) => {
} }
broadcastRedeployStatus(id, false); broadcastRedeployStatus(id, false);
logRedeployEvent({
stackId: stack.Id || id,
stackName: stack.Name,
status: 'success',
message: 'Redeploy erfolgreich abgeschlossen',
endpoint: stack.EndpointId
});
console.log(`✅ PUT /api/stacks/${id}/redeploy: Redeploy erfolgreich abgeschlossen`); console.log(`✅ PUT /api/stacks/${id}/redeploy: Redeploy erfolgreich abgeschlossen`);
res.json({ success: true, message: 'Stack redeployed' }); res.json({ success: true, message: 'Stack redeployed' });
} catch (err) { } catch (err) {
broadcastRedeployStatus(id, false); broadcastRedeployStatus(id, false);
console.error(`❌ Fehler beim Redeploy von Stack ${id}:`, err.message); const errorMessage = err.response?.data?.message || err.message;
res.status(500).json({ error: err.message }); logRedeployEvent({
stackId: stack?.Id || id,
stackName: stack?.Name || `Stack ${id}`,
status: 'error',
message: errorMessage,
endpoint: stack?.EndpointId || ENDPOINT_ID
});
console.error(`❌ Fehler beim Redeploy von Stack ${id}:`, errorMessage);
res.status(500).json({ error: errorMessage });
} }
}); });
@@ -218,6 +243,13 @@ app.put('/api/stacks/redeploy-all', async (req, res) => {
filteredStacks.forEach(async (stack) => { filteredStacks.forEach(async (stack) => {
try { try {
broadcastRedeployStatus(stack.Id, true); broadcastRedeployStatus(stack.Id, true);
logRedeployEvent({
stackId: stack.Id,
stackName: stack.Name,
status: 'started',
message: 'Redeploy über Redeploy ALL gestartet',
endpoint: stack.EndpointId
});
if (stack.Type === 1) { if (stack.Type === 1) {
console.log(`🔄 [Redeploy] Git Stack "${stack.Name}" (${stack.Id})`); console.log(`🔄 [Redeploy] Git Stack "${stack.Name}" (${stack.Id})`);
@@ -235,10 +267,25 @@ app.put('/api/stacks/redeploy-all', async (req, res) => {
} }
broadcastRedeployStatus(stack.Id, false); broadcastRedeployStatus(stack.Id, false);
logRedeployEvent({
stackId: stack.Id,
stackName: stack.Name,
status: 'success',
message: 'Redeploy über Redeploy ALL abgeschlossen',
endpoint: stack.EndpointId
});
console.log(`✅ Redeploy abgeschlossen: ${stack.Name}`); console.log(`✅ Redeploy abgeschlossen: ${stack.Name}`);
} catch (err) { } catch (err) {
broadcastRedeployStatus(stack.Id, false); broadcastRedeployStatus(stack.Id, false);
console.error(`❌ Fehler beim Redeploy von Stack ${stack.Name}:`, err.message); const errorMessage = err.response?.data?.message || err.message;
logRedeployEvent({
stackId: stack.Id,
stackName: stack.Name,
status: 'error',
message: errorMessage,
endpoint: stack.EndpointId
});
console.error(`❌ Fehler beim Redeploy von Stack ${stack.Name}:`, errorMessage);
} }
}); });