Skip to content

Commit 9f52ac1

Browse files
committed
Incremental workspaces
1 parent ec73a64 commit 9f52ac1

File tree

11 files changed

+94
-280
lines changed

11 files changed

+94
-280
lines changed

components/dashboard/src/projects/Project.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,7 @@ export default function () {
378378
)}
379379
</a>
380380
<span className="flex-grow" />
381-
<a
382-
href={
383-
prebuild
384-
? gitpodHostUrl
385-
.withContext(
386-
`open-prebuild/${prebuild.info.id}/${prebuild.info.changeUrl}`,
387-
)
388-
.toString()
389-
: gitpodHostUrl.withContext(`${branch.url}`).toString()
390-
}
391-
>
381+
<a href={gitpodHostUrl.withContext(`${branch.url}`).toString()}>
392382
<button
393383
className={`primary mr-2 py-2 opacity-0 group-hover:opacity-100`}
394384
>

components/dashboard/src/projects/ProjectSettings.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ export default function () {
9090
checked={!project.settings?.keepOutdatedPrebuildsRunning}
9191
onChange={({ target }) => updateProjectSettings({ keepOutdatedPrebuildsRunning: !target.checked })}
9292
/>
93+
<h3>Workspace Starts</h3>
94+
<CheckBox
95+
title={<span>Start on old prebuilds</span>}
96+
desc={
97+
<span>
98+
Whether new workspaces can be started based on prebuilds that ran on older Git commits and get
99+
incrementally updated.
100+
</span>
101+
}
102+
checked={!!project.settings?.allowUsingPreviousPrebuilds}
103+
onChange={({ target }) => updateProjectSettings({ allowUsingPreviousPrebuilds: !target.checked })}
104+
/>
93105
{showPersistentVolumeClaimUI && (
94106
<>
95107
<br></br>

components/dashboard/src/start/CreateWorkspace.tsx

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
*/
66

77
import React, { useEffect, useContext, useState } from "react";
8-
import {
9-
CreateWorkspaceMode,
10-
WorkspaceCreationResult,
11-
RunningWorkspacePrebuildStarting,
12-
ContextURL,
13-
DisposableCollection,
14-
Team,
15-
} from "@gitpod/gitpod-protocol";
8+
import { WorkspaceCreationResult, ContextURL, Team, GitpodServer } from "@gitpod/gitpod-protocol";
169
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
1710
import Modal from "../components/Modal";
1811
import { getGitpodService, gitpodHostUrl } from "../service/service";
@@ -22,14 +15,12 @@ import StartWorkspace, { parseProps } from "./StartWorkspace";
2215
import { openAuthorizeWindow } from "../provider-utils";
2316
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
2417
import { SelectAccountModal } from "../settings/SelectAccountModal";
25-
import PrebuildLogs from "../components/PrebuildLogs";
2618
import FeedbackComponent from "../feedback-form/FeedbackComponent";
2719
import { isGitpodIo } from "../utils";
2820
import { BillingAccountSelector } from "../components/BillingAccountSelector";
2921
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
3022
import { TeamsContext } from "../teams/teams-context";
3123
import Alert from "../components/Alert";
32-
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
3324

3425
export interface CreateWorkspaceProps {
3526
contextUrl: string;
@@ -48,22 +39,22 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
4839
this.state = { stillParsing: true };
4940
}
5041

42+
static contextType = UserContext;
43+
5144
componentDidMount() {
5245
this.createWorkspace();
5346
}
5447

55-
async createWorkspace(mode = CreateWorkspaceMode.SelectIfRunning, forceDefaultConfig = false) {
48+
async createWorkspace(opts?: Omit<GitpodServer.CreateWorkspaceOptions, "contextUrl">) {
5649
// Invalidate any previous result.
5750
this.setState({ result: undefined, stillParsing: true });
58-
5951
// We assume anything longer than 3 seconds is no longer just parsing the context URL (i.e. it's now creating a workspace).
6052
let timeout = setTimeout(() => this.setState({ stillParsing: false }), 3000);
61-
6253
try {
6354
const result = await getGitpodService().server.createWorkspace({
6455
contextUrl: this.props.contextUrl,
65-
mode,
66-
forceDefaultConfig,
56+
ignoreRunningWorkspaceOnSameCommit: false,
57+
...opts,
6758
});
6859
if (result.workspaceURL) {
6960
window.location.href = result.workspaceURL;
@@ -148,7 +139,7 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
148139
<button
149140
className=""
150141
onClick={() => {
151-
this.createWorkspace(CreateWorkspaceMode.Default, true);
142+
this.createWorkspace({ forceDefaultConfig: true });
152143
}}
153144
>
154145
Continue with default configuration
@@ -262,21 +253,12 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
262253
</>
263254
</div>
264255
<div className="flex justify-end mt-6">
265-
<button onClick={() => this.createWorkspace(CreateWorkspaceMode.Default)}>New Workspace</button>
256+
<button onClick={() => this.createWorkspace({ ignoreRunningWorkspaceOnSameCommit: true })}>
257+
New Workspace
258+
</button>
266259
</div>
267260
</Modal>
268261
);
269-
} else if (result?.runningWorkspacePrebuild) {
270-
return (
271-
<RunningPrebuildView
272-
runningPrebuild={result.runningWorkspacePrebuild}
273-
onUseLastSuccessfulPrebuild={() =>
274-
this.createWorkspace(CreateWorkspaceMode.UseLastSuccessfulPrebuild)
275-
}
276-
onIgnorePrebuild={() => this.createWorkspace(CreateWorkspaceMode.ForceNew)}
277-
onPrebuildSucceeded={() => this.createWorkspace(CreateWorkspaceMode.UsePrebuild)}
278-
/>
279-
);
280262
}
281263

282264
return (
@@ -526,64 +508,3 @@ function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {
526508
</StartPage>
527509
);
528510
}
529-
530-
interface RunningPrebuildViewProps {
531-
runningPrebuild: {
532-
prebuildID: string;
533-
workspaceID: string;
534-
instanceID: string;
535-
starting: RunningWorkspacePrebuildStarting;
536-
sameCluster: boolean;
537-
};
538-
onUseLastSuccessfulPrebuild: () => void;
539-
onIgnorePrebuild: () => void;
540-
onPrebuildSucceeded: () => void;
541-
}
542-
543-
function RunningPrebuildView(props: RunningPrebuildViewProps) {
544-
const workspaceId = props.runningPrebuild.workspaceID;
545-
const { showUseLastSuccessfulPrebuild } = useContext(FeatureFlagContext);
546-
547-
useEffect(() => {
548-
const disposables = new DisposableCollection();
549-
550-
disposables.push(
551-
getGitpodService().registerClient({
552-
onInstanceUpdate: (update) => {
553-
if (update.workspaceId !== workspaceId) {
554-
return;
555-
}
556-
if (update.status.phase === "stopped") {
557-
props.onPrebuildSucceeded();
558-
}
559-
},
560-
}),
561-
);
562-
563-
return function cleanup() {
564-
disposables.dispose();
565-
};
566-
// eslint-disable-next-line
567-
}, [workspaceId]);
568-
569-
return (
570-
<StartPage title="Prebuild in Progress">
571-
{/* TODO(gpl) Copied around in Start-/CreateWorkspace. This should properly go somewhere central. */}
572-
<div className="h-full mt-6 w-11/12 lg:w-3/5">
573-
<PrebuildLogs workspaceId={workspaceId} onIgnorePrebuild={props.onIgnorePrebuild}>
574-
{showUseLastSuccessfulPrebuild && (
575-
<button
576-
className="secondary"
577-
onClick={() => props.onUseLastSuccessfulPrebuild && props.onUseLastSuccessfulPrebuild()}
578-
>
579-
Use Last Successful Prebuild
580-
</button>
581-
)}
582-
<button className="secondary" onClick={() => props.onIgnorePrebuild && props.onIgnorePrebuild()}>
583-
Skip Prebuild
584-
</button>
585-
</PrebuildLogs>
586-
</div>
587-
</StartPage>
588-
);
589-
}

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
WhitelistedRepository,
1313
WorkspaceImageBuild,
1414
AuthProviderInfo,
15-
CreateWorkspaceMode,
1615
Token,
1716
UserEnvVarValue,
1817
Terms,
@@ -422,7 +421,8 @@ export namespace GitpodServer {
422421
}
423422
export interface CreateWorkspaceOptions {
424423
contextUrl: string;
425-
mode?: CreateWorkspaceMode;
424+
// whether running workspaces on the same context should be ignored. If false (default) users will be asked.
425+
ignoreRunningWorkspaceOnSameCommit?: boolean;
426426
forceDefaultConfig?: boolean;
427427
}
428428
export interface StartWorkspaceOptions {

components/gitpod-protocol/src/protocol.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,14 +1370,6 @@ export interface WorkspaceCreationResult {
13701370
createdWorkspaceId?: string;
13711371
workspaceURL?: string;
13721372
existingWorkspaces?: WorkspaceInfo[];
1373-
runningWorkspacePrebuild?: {
1374-
prebuildID: string;
1375-
workspaceID: string;
1376-
instanceID: string;
1377-
starting: RunningWorkspacePrebuildStarting;
1378-
sameCluster: boolean;
1379-
};
1380-
runningPrebuildWorkspaceID?: string;
13811373
}
13821374
export type RunningWorkspacePrebuildStarting = "queued" | "starting" | "running";
13831375

components/gitpod-protocol/src/teams-projects-protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface ProjectSettings {
1717
useIncrementalPrebuilds?: boolean;
1818
usePersistentVolumeClaim?: boolean;
1919
keepOutdatedPrebuildsRunning?: boolean;
20+
// whether new workspaces can start on older prebuilds and incrementally update
21+
allowUsingPreviousPrebuilds?: boolean;
2022
}
2123

2224
export interface Project {

components/server/ee/src/prebuilds/prebuild-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class PrebuildManager {
191191
const workspace = await this.workspaceFactory.createForContext(
192192
{ span },
193193
user,
194+
project,
194195
prebuildContext,
195196
context.normalizedContextURL!,
196197
);

0 commit comments

Comments
 (0)