This commit is contained in:
jarek committed 2026-01-17 15:06:14 +01:00
1 parent 62636426bf
commit c185d00dc3
60 files changed
+2830 -918

No files matched your search

+61 -1
View File
@@ -5,9 +5,34 @@ import { isAuthEnabled, validateSession } from '$lib/server/auth';
import { setServerStartTime } from '$lib/server/uptime';
import { checkLicenseExpiry, getHostname } from '$lib/server/license';
import { initCryptoFallback } from '$lib/server/crypto-fallback';
import { detectHostDataDir } from '$lib/server/host-path';
import { listContainers, removeContainer } from '$lib/server/docker';
import { rmSync, readdirSync, existsSync } from 'fs';
import { join } from 'path';
import type { HandleServerError, Handle } from '@sveltejs/kit';
import { redirect } from '@sveltejs/kit';
// Cleanup orphaned scanner version containers from previous runs
async function cleanupOrphanedScannerContainers() {
try {
const containers = await listContainers(true);
const orphaned = containers.filter(c =>
c.name?.startsWith('dockhand-grype-version-') ||
c.name?.startsWith('dockhand-trivy-version-')
);
for (const c of orphaned) {
try {
await removeContainer(c.id, true);
} catch { /* ignore */ }
}
if (orphaned.length > 0) {
console.log(`[Startup] Cleaned up ${orphaned.length} orphaned scanner containers`);
}
} catch (error) {
// Silently ignore - Docker may not be available yet or no containers to clean
}
}
// License expiry check interval (24 hours)
const LICENSE_CHECK_INTERVAL = 86400000;
@@ -24,10 +49,46 @@ if (!initialized) {
// Initialize crypto fallback first (detects old kernels and logs status)
initCryptoFallback();
// Cleanup orphaned TLS temp directories from previous crashes
const dataDir = process.env.DATA_DIR || './data';
const tmpDir = join(dataDir, 'tmp');
if (existsSync(tmpDir)) {
try {
const entries = readdirSync(tmpDir);
for (const entry of entries) {
if (entry.startsWith('tls-')) {
const path = join(tmpDir, entry);
try {
rmSync(path, { recursive: true, force: true });
console.log(`[Startup] Cleaned orphaned TLS temp dir: ${entry}`);
} catch { /* ignore */ }
}
}
} catch { /* ignore */ }
}
setServerStartTime(); // Track when server started
initDatabase();
// Log hostname for license validation (set by entrypoint in Docker, or os.hostname() outside)
console.log('Hostname for license validation:', getHostname());
// Detect host data directory for path translation
// This allows Dockhand to translate container paths to host paths for compose volume mounts
detectHostDataDir().then(hostPath => {
if (hostPath) {
console.log(`[Startup] Host data directory detected: ${hostPath}`);
} else {
console.warn('[Startup] Could not detect host data path.');
console.warn('[Startup] Git stacks with relative volume paths may not work correctly.');
console.warn('[Startup] Consider setting HOST_DATA_DIR or using matching volume paths (-v /app/data:/app/data)');
}
}).catch(err => {
console.error('[Startup] Failed to detect host data directory:', err);
});
// Cleanup orphaned scanner containers from previous runs (non-blocking)
cleanupOrphanedScannerContainers().catch(err => {
console.error('Failed to cleanup orphaned scanner containers:', err);
});
// Start background subprocesses for metrics and event collection (isolated processes)
startSubprocesses().catch(err => {
console.error('Failed to start background subprocesses:', err);
@@ -174,4 +235,3 @@ export const handleError: HandleServerError = ({ error, event }) => {
code: 'INTERNAL_ERROR'
};
};
// CI trigger 1766327149