Skip to content

Commit e759051

Browse files
committed
Implement a 'Use Last Successful Prebuild' workspace creation mode
1 parent da89e67 commit e759051

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

components/dashboard/src/start/CreateWorkspace.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
269269
return (
270270
<RunningPrebuildView
271271
runningPrebuild={result.runningWorkspacePrebuild}
272+
onUseLastSuccessfulPrebuild={() =>
273+
this.createWorkspace(CreateWorkspaceMode.UseLastSuccessfulPrebuild)
274+
}
272275
onIgnorePrebuild={() => this.createWorkspace(CreateWorkspaceMode.ForceNew)}
273276
onPrebuildSucceeded={() => this.createWorkspace(CreateWorkspaceMode.UsePrebuild)}
274277
/>
@@ -531,6 +534,7 @@ interface RunningPrebuildViewProps {
531534
starting: RunningWorkspacePrebuildStarting;
532535
sameCluster: boolean;
533536
};
537+
onUseLastSuccessfulPrebuild: () => void;
534538
onIgnorePrebuild: () => void;
535539
onPrebuildSucceeded: () => void;
536540
}
@@ -565,6 +569,12 @@ function RunningPrebuildView(props: RunningPrebuildViewProps) {
565569
{/* TODO(gpl) Copied around in Start-/CreateWorkspace. This should properly go somewhere central. */}
566570
<div className="h-full mt-6 w-11/12 lg:w-3/5">
567571
<PrebuildLogs workspaceId={workspaceId} onIgnorePrebuild={props.onIgnorePrebuild}>
572+
<button
573+
className="secondary"
574+
onClick={() => props.onUseLastSuccessfulPrebuild && props.onUseLastSuccessfulPrebuild()}
575+
>
576+
Use Last Successful Prebuild
577+
</button>
568578
<button className="secondary" onClick={() => props.onIgnorePrebuild && props.onIgnorePrebuild()}>
569579
Skip Prebuild
570580
</button>

components/gitpod-protocol/src/protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,8 @@ export enum CreateWorkspaceMode {
13721372
UsePrebuild = "use-prebuild",
13731373
// SelectIfRunning returns a list of currently running workspaces for the context URL if there are any, otherwise falls back to Default mode
13741374
SelectIfRunning = "select-if-running",
1375+
// UseLastSuccessfulPrebuild returns ...
1376+
UseLastSuccessfulPrebuild = "use-last-successful-prebuild",
13751377
}
13761378

13771379
export namespace WorkspaceCreationResult {

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,32 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
963963

964964
const logCtx: LogContext = { userId: user.id };
965965
const cloneUrl = context.repository.cloneUrl;
966+
if (mode === CreateWorkspaceMode.UseLastSuccessfulPrebuild) {
967+
const maxDepth = this.config.incrementalPrebuilds.commitHistory;
968+
const hostContext = this.hostContextProvider.get(context.repository.host);
969+
const repoProvider = hostContext?.services?.repositoryProvider;
970+
if (repoProvider) {
971+
const commitHistory = await repoProvider.getCommitHistory(
972+
user,
973+
context.repository.owner,
974+
context.repository.name,
975+
context.revision,
976+
maxDepth,
977+
);
978+
log.info("findPrebuiltWorkspace: incremental workspace", { commitHistory });
979+
for (const commit of commitHistory) {
980+
const possiblePrebuild = await this.workspaceDb
981+
.trace(ctx)
982+
.findPrebuiltWorkspaceByCommit(cloneUrl, commit);
983+
if (possiblePrebuild) {
984+
log.info("findPrebuiltWorkspace: incremental workspace", { possiblePrebuild });
985+
}
986+
}
987+
// {"component":"server","severity":"INFO","time":"2022-10-12T12:57:06.447Z","message":"findPrebuiltWorkspace: incremental workspace","payload":{"commitHistory":["95b666410f37b5237bf416feb748fb1e8aab8fd4","ab01b49c669ce41e0fef1cb306b1ba648ff4ea6a","b3d8f3ada8e729a99b334f75b45eacf240350afa","71d1a3cae0121b2fea14a69b97bcdddce44809ac","218dd0667a7eff7ed657f27b570431919cd87be7","feb2d8b057f751ccd13a7aec07ecfd85757cbb09","9270c10e3b1c23f0a65253cd516aae55120550e9","a70117ff7ae75de4de6c922ab9953e299c711046","24c9dcb64f582ae696797dc617b9af1352a6f01a","6f2aff3ebf94cf40a0c96e87bfd00b2917fc7adb","98b4bfb6190a3bb9fb0f513ffc2bce4009177960","35c9687543411e9e1ced865a9fcd69e1003fe3ed","61d913686e3f5ac17bcd490774097dc6302c92bf","f93921910f80c085fafc5157f6d6b7205b19a4fa"]}}
988+
// TODO(janx): if (context.additionalRepositoryCheckoutInfo?.length > 0) { additionalRepositoryCommitHistories ? }
989+
// TODO(janx): walk back commit history to find a successful prebuild
990+
}
991+
}
966992
const prebuiltWorkspace = await this.workspaceDb
967993
.trace(ctx)
968994
.findPrebuiltWorkspaceByCommit(cloneUrl, commitSHAs);

0 commit comments

Comments
 (0)