fix: use Dokploy API status check instead of HTTP health check

The portal container cannot reach deployed stacks via external URL.
Now checks applicationStatus via Dokploy API instead.
This commit is contained in:
Oussama Douhou
2026-01-10 11:56:15 +01:00
parent 9f2ee66f19
commit 7e95e9f310

View File

@@ -347,53 +347,32 @@ export class ProductionDeployer {
): Promise<void> {
state.phase = 'verifying_health';
state.progress = 95;
state.message = 'Verifying application health';
state.message = 'Verifying application status via Dokploy';
if (!state.url) {
throw new Error('Application URL not available');
if (!state.resources.applicationId) {
throw new Error('Application ID not available');
}
const timeout = config.healthCheckTimeout || 120000;
const interval = config.healthCheckInterval || 5000;
const timeout = config.healthCheckTimeout || 60000;
const interval = config.healthCheckInterval || 3000;
const startTime = Date.now();
const endpoints = ['/', '/health', '/api'];
while (Date.now() - startTime < timeout) {
for (const endpoint of endpoints) {
try {
const checkUrl = `${state.url}${endpoint}`;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const app = await this.client.getApplication(state.resources.applicationId);
const appStatus = app.applicationStatus;
console.log(`Application status: ${appStatus}`);
const response = await fetch(checkUrl, {
method: 'GET',
signal: controller.signal,
});
clearTimeout(timeoutId);
console.log(`Health check ${checkUrl} returned ${response.status}`);
state.message = 'Application is responding';
if (appStatus === 'done') {
state.message = 'Application deployed successfully';
return;
}
if (appStatus === 'error') {
throw new Error('Application deployment failed in Dokploy');
}
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
if (
errorMsg.includes('certificate') ||
errorMsg.includes('SSL') ||
errorMsg.includes('TLS') ||
errorMsg.includes('CERT') ||
errorMsg.includes('unable to verify') ||
errorMsg.includes('self signed') ||
errorMsg.includes('self-signed')
) {
console.log(`Health check SSL error (treating as alive): ${errorMsg}`);
state.message = 'Application is responding (SSL provisioning)';
return;
}
console.log(`Health check failed: ${errorMsg}`);
}
console.log(`Status check failed: ${error}`);
}
const elapsed = Math.round((Date.now() - startTime) / 1000);
@@ -403,7 +382,7 @@ export class ProductionDeployer {
await this.sleep(interval);
}
throw new Error('Health check timeout - application did not become healthy');
throw new Error('Health check timeout - application did not become ready');
}
private async rollback(state: DeploymentState): Promise<void> {