-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[prebuild] Support opening a specfic prebuild #13768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
PrebuiltWorkspace, | ||
WorkspaceConfig, | ||
WorkspaceImageSource, | ||
OpenPrebuildContext, | ||
} from "@gitpod/gitpod-protocol"; | ||
import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | ||
import { LicenseEvaluator } from "@gitpod/licensor/lib"; | ||
|
@@ -371,6 +372,18 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { | |
config._featureFlags = (config._featureFlags || []).concat(["persistent_volume_claim"]); | ||
} | ||
|
||
if (OpenPrebuildContext.is(context.originalContext)) { | ||
// Because of incremental prebuilds, createForContext will take over the original context. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// To ensure we get the right commit when forcing a prebuild, we force the context here. | ||
context.originalContext = buildWorkspace.context; | ||
|
||
if (CommitContext.is(context.originalContext)) { | ||
// We force the checkout of the revision rather than the ref/branch. | ||
// Otherwise we'd the correct prebuild with the "wrong" Git status. | ||
delete context.originalContext.ref; | ||
} | ||
} | ||
|
||
const id = await this.generateWorkspaceID(context); | ||
const newWs: Workspace = { | ||
id, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
components/server/src/workspace/open-prebuild-prefix-context-parser.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { User, WorkspaceContext } from "@gitpod/gitpod-protocol"; | ||
import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | ||
import { OpenPrebuildContext } from "@gitpod/gitpod-protocol/src/protocol"; | ||
import { inject, injectable } from "inversify"; | ||
import { Config } from "../config"; | ||
import { IPrefixContextParser } from "./context-parser"; | ||
|
||
@injectable() | ||
export class OpenPrebuildPrefixContextParser implements IPrefixContextParser { | ||
@inject(Config) protected readonly config: Config; | ||
static PREFIX = /^\/?open-prebuild\/([^\/]*)\//; | ||
|
||
findPrefix(user: User, context: string): string | undefined { | ||
const result = OpenPrebuildPrefixContextParser.PREFIX.exec(context); | ||
if (!result) { | ||
return undefined; | ||
} | ||
return result[0]; | ||
} | ||
|
||
public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> { | ||
const match = OpenPrebuildPrefixContextParser.PREFIX.exec(prefix); | ||
if (!match) { | ||
log.error("Could not parse prefix " + prefix); | ||
return context; | ||
} | ||
|
||
(context as OpenPrebuildContext).openPrebuildID = match[1]; | ||
return context; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm not super-fond of adding a ContextParser for this I understand that currently, it's the only accessible way that make things like this work.
Also, removing it later should not be too hard. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use the commit context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See related discussion: #13706 (comment)