feat: show build logs alongside pod logs in app detail page
This commit is contained in:
@@ -18,9 +18,9 @@ export class BuildService {
|
||||
|
||||
/**
|
||||
* Builds a Docker image for the application using Kaniko inside K8s.
|
||||
* Returns the full image URI (registry/repo:tag).
|
||||
* Returns { imageUri, buildLog } — the full image URI and the build logs.
|
||||
*/
|
||||
async buildImage(app: Application): Promise<string> {
|
||||
async buildImage(app: Application): Promise<{ imageUri: string; buildLog: string }> {
|
||||
// Internal registry (used by Kaniko inside K8s for pushing)
|
||||
const internalRegistryUrl = this.configService.get<string>('registry.url') || 'registry.cloudhost-builds.svc.cluster.local:5000';
|
||||
// External registry URL (used by kubelet for pulling — NodePort or external)
|
||||
@@ -239,17 +239,26 @@ export class BuildService {
|
||||
// Wait for build to complete
|
||||
await this.waitForJobCompletion(batchApi, coreApi, buildPodName, buildNamespace!, 600);
|
||||
|
||||
// Capture build logs on success
|
||||
let buildLog = '';
|
||||
try {
|
||||
buildLog = await this.getBuildLogs(coreApi, buildPodName, buildNamespace!);
|
||||
} catch {}
|
||||
|
||||
this.logger.log(`Build completed successfully: ${pullImageUri}`);
|
||||
return pullImageUri;
|
||||
return { imageUri: pullImageUri, buildLog };
|
||||
} catch (error: any) {
|
||||
// Try to get build logs for debugging
|
||||
let buildLog = '';
|
||||
try {
|
||||
const logs = await this.getBuildLogs(coreApi, buildPodName, buildNamespace!);
|
||||
this.logger.error(`Build logs for ${buildPodName}:\n${logs}`);
|
||||
buildLog = await this.getBuildLogs(coreApi, buildPodName, buildNamespace!);
|
||||
this.logger.error(`Build logs for ${buildPodName}:\n${buildLog}`);
|
||||
} catch {}
|
||||
|
||||
this.logger.error(`Build failed for ${app.name}:`, error.body || error.message);
|
||||
throw new Error(`Image build failed: ${error.body?.message || error.message}`);
|
||||
const err = new Error(`Image build failed: ${error.body?.message || error.message}`);
|
||||
(err as any).buildLog = buildLog;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user