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 <janx@gitpod.io>
  • Loading branch information
laushinka and jankeromnes committed Apr 4, 2022
1 parent d020cb2 commit a802b15
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 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,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 },
Expand All @@ -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) {
Expand Down Expand Up @@ -173,7 +185,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,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,
});
Expand All @@ -242,6 +258,8 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
});
return false;
}

return true;
}

protected async createForPrebuiltWorkspace(
Expand Down

0 comments on commit a802b15

Please sign in to comment.