Skip to content

Commit

Permalink
Fix prebuild base selection
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Keromnes <[email protected]>
  • Loading branch information
2 people authored and roboquat committed Apr 4, 2022
1 parent d020cb2 commit 8ad398e
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions components/server/ee/src/workspace/workspace-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,33 @@ 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,
))
) {
log.info("Not using incremental prebuild base", {
candidatePrebuildId: recentPrebuild.prebuild.id,
context,
});
continue;
}

log.info("Using incremental prebuild base", {
basePrebuildId: recentPrebuild.prebuild.id,
context,
});

const incrementalPrebuildContext: PrebuiltWorkspaceContext = {
title: `Incremental prebuild of "${commitContext.title}"`,
originalContext: commitContext,
prebuiltWorkspace: match.prebuild,
prebuiltWorkspace: recentPrebuild.prebuild,
};
ws = await this.createForPrebuiltWorkspace(
{ span },
Expand All @@ -132,6 +151,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) {
Expand Down Expand Up @@ -173,7 +194,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
imageSource: WorkspaceImageSource,
candidatePrebuild: PrebuiltWorkspace,
candidate: Workspace,
) {
): Promise<boolean> {
if (!context.commitHistory || context.commitHistory.length === 0) {
return false;
}
Expand Down Expand Up @@ -214,7 +235,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
}
}

// ensure the image source hasn't changed
// ensure the image source hasn't changed (skips older images)
if (JSON.stringify(imageSource) !== JSON.stringify(candidate.imageSource)) {
log.debug(`Skipping parent prebuild: Outdated image`, {
imageSource,
Expand Down Expand Up @@ -242,6 +263,8 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
});
return false;
}

return true;
}

protected async createForPrebuiltWorkspace(
Expand Down

0 comments on commit 8ad398e

Please sign in to comment.