diff --git a/components/server/ee/src/workspace/workspace-factory.ts b/components/server/ee/src/workspace/workspace-factory.ts index 792147c2af5ec2..cc39cf7d87760b 100644 --- a/components/server/ee/src/workspace/workspace-factory.ts +++ b/components/server/ee/src/workspace/workspace-factory.ts @@ -109,14 +109,24 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { const recentPrebuilds = await this.db .trace({ span }) .findPrebuildsWithWorkpace(commitContext.repository.cloneUrl); - const match = recentPrebuilds.find((pb) => - this.isGoodBaseforIncrementalPrebuild(context, config, imageSource, pb.prebuild, pb.workspace), - ); - if (match) { + + for (const recentPrebuild of recentPrebuilds) { + if ( + !(await this.isGoodBaseforIncrementalPrebuild( + context, + config, + imageSource, + recentPrebuild.prebuild, + recentPrebuild.workspace, + )) + ) { + continue; + } + const incrementalPrebuildContext: PrebuiltWorkspaceContext = { title: `Incremental prebuild of "${commitContext.title}"`, originalContext: commitContext, - prebuiltWorkspace: match.prebuild, + prebuiltWorkspace: recentPrebuild.prebuild, }; ws = await this.createForPrebuiltWorkspace( { span }, @@ -132,6 +142,8 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { // See also: https://github.com/gitpod-io/gitpod/issues/7475 //TODO(sven) doing side effects on objects back and forth is complicated and error-prone. We should rather make sure we pass in the config when creating the prebuiltWorkspace. ws.config = config; + + break; } } if (!ws) { @@ -173,7 +185,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { imageSource: WorkspaceImageSource, candidatePrebuild: PrebuiltWorkspace, candidate: Workspace, - ) { + ): Promise { if (!context.commitHistory || context.commitHistory.length === 0) { return false; } @@ -214,9 +226,13 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { } } + log.info(`image source >>>>>`, { imageSource, parentImageSource: candidate.imageSource }); + log.info(`context >>>>>`, { context }); + // ensure the image source hasn't changed if (JSON.stringify(imageSource) !== JSON.stringify(candidate.imageSource)) { - log.debug(`Skipping parent prebuild: Outdated image`, { + // skips older image + log.info(`Skipping parent prebuild: Outdated image`, { imageSource, parentImageSource: candidate.imageSource, }); @@ -242,6 +258,8 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { }); return false; } + + return true; } protected async createForPrebuiltWorkspace(