Skip to content

Commit c0396c8

Browse files
authored
Revert "Revert "[server] remove definitely-gp (#18278)" (#18306)"
This reverts commit 4824121.
1 parent be3d71d commit c0396c8

File tree

4 files changed

+22
-241
lines changed

4 files changed

+22
-241
lines changed

components/gitpod-protocol/go/gitpod-service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,6 @@ type WorkspaceConfig struct {
17021702
// Where the config object originates from.
17031703
//
17041704
// repo - from the repository
1705-
// definitely-gp - from github.com/gitpod-io/definitely-gp
17061705
// derived - computed based on analyzing the repository
17071706
// default - our static catch-all default config
17081707
Origin string `json:"_origin,omitempty"`

components/gitpod-protocol/src/protocol.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,11 @@ export interface WorkspaceConfig {
970970
* Where the config object originates from.
971971
*
972972
* repo - from the repository
973-
* definitly-gp - from github.com/gitpod-io/definitely-gp
974973
* derived - computed based on analyzing the repository
975974
* additional-content - config comes from additional content, usually provided through the project's configuration
976975
* default - our static catch-all default config
977976
*/
978-
_origin?: "repo" | "definitely-gp" | "derived" | "additional-content" | "default";
977+
_origin?: "repo" | "derived" | "additional-content" | "default";
979978

980979
/**
981980
* Set of automatically infered feature flags. That's not something the user can set, but
@@ -1170,14 +1169,6 @@ export namespace ImageConfigFile {
11701169
return typeof config === "object" && "file" in config;
11711170
}
11721171
}
1173-
export interface ExternalImageConfigFile extends ImageConfigFile {
1174-
externalSource: Commit;
1175-
}
1176-
export namespace ExternalImageConfigFile {
1177-
export function is(config: any | undefined): config is ExternalImageConfigFile {
1178-
return typeof config === "object" && "file" in config && "externalSource" in config;
1179-
}
1180-
}
11811172

11821173
export interface WorkspaceContext {
11831174
title: string;

components/server/src/workspace/config-provider.ts

Lines changed: 18 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,38 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7+
import * as crypto from "crypto";
78
import { inject, injectable } from "inversify";
8-
import fetch from "node-fetch";
99
import * as path from "path";
10-
import * as crypto from "crypto";
1110

12-
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";
1311
import {
14-
User,
15-
WorkspaceConfig,
12+
AdditionalContentContext,
1613
CommitContext,
17-
Repository,
1814
ImageConfigString,
19-
ExternalImageConfigFile,
20-
ImageConfigFile,
21-
Commit,
2215
NamedWorkspaceFeatureFlag,
23-
AdditionalContentContext,
24-
WithDefaultConfig,
2516
ProjectConfig,
17+
User,
18+
WithDefaultConfig,
19+
WorkspaceConfig,
2620
} from "@gitpod/gitpod-protocol";
2721
import { GitpodFileParser } from "@gitpod/gitpod-protocol/lib/gitpod-file-parser";
22+
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";
2823

29-
import { MaybeContent } from "../repohost/file-provider";
30-
import { ConfigurationService } from "../config/configuration-service";
31-
import { HostContextProvider } from "../auth/host-context-provider";
32-
import { AuthorizationService } from "../user/authorization-service";
3324
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
25+
import { HostContextProvider } from "../auth/host-context-provider";
3426
import { Config } from "../config";
35-
import { EntitlementService } from "../billing/entitlement-service";
36-
import { TeamDB } from "@gitpod/gitpod-db/lib";
27+
import { ConfigurationService } from "../config/configuration-service";
3728

3829
const POD_PATH_WORKSPACE_BASE = "/workspace";
3930

4031
@injectable()
4132
export class ConfigProvider {
42-
static readonly DEFINITELY_GP_REPO: Repository = {
43-
host: "github.com",
44-
owner: "gitpod-io",
45-
name: "definitely-gp",
46-
cloneUrl: "https://github.com/gitpod-io/definitely-gp",
47-
};
48-
49-
@inject(GitpodFileParser) protected readonly gitpodParser: GitpodFileParser;
50-
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
51-
@inject(AuthorizationService) protected readonly authService: AuthorizationService;
52-
@inject(Config) protected readonly config: Config;
53-
@inject(ConfigurationService) protected readonly configurationService: ConfigurationService;
54-
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;
55-
@inject(TeamDB) protected readonly teamDB: TeamDB;
33+
constructor(
34+
@inject(GitpodFileParser) private readonly gitpodParser: GitpodFileParser,
35+
@inject(HostContextProvider) private readonly hostContextProvider: HostContextProvider,
36+
@inject(Config) private readonly config: Config,
37+
@inject(ConfigurationService) private readonly configurationService: ConfigurationService,
38+
) {}
5639

5740
public async fetchConfig(
5841
ctx: TraceContext,
@@ -64,7 +47,6 @@ export class ConfigProvider {
6447
commit,
6548
});
6649
const logContext: LogContext = { userId: user.id };
67-
let configBasePath = "";
6850
try {
6951
let customConfig: WorkspaceConfig | undefined;
7052
let literalConfig: ProjectConfig | undefined;
@@ -73,7 +55,6 @@ export class ConfigProvider {
7355
const cc = await this.fetchCustomConfig(ctx, user, commit);
7456
if (!!cc) {
7557
customConfig = cc.customConfig;
76-
configBasePath = cc.configBasePath;
7758
literalConfig = cc.literalConfig;
7859
}
7960
}
@@ -94,29 +75,6 @@ export class ConfigProvider {
9475
const config = customConfig;
9576
if (!config.image) {
9677
config.image = this.config.workspaceDefaults.workspaceImage;
97-
} else if (ImageConfigFile.is(config.image)) {
98-
const dockerfilePath = [configBasePath, config.image.file].filter((s) => !!s).join("/");
99-
let repo = commit.repository;
100-
let rev = commit.revision;
101-
const image = config.image!;
102-
103-
if (config._origin === "definitely-gp") {
104-
repo = ConfigProvider.DEFINITELY_GP_REPO;
105-
rev = "master";
106-
image.file = dockerfilePath;
107-
}
108-
if (!(AdditionalContentContext.is(commit) && commit.additionalFiles[dockerfilePath])) {
109-
config.image = <ExternalImageConfigFile>{
110-
...image,
111-
externalSource: await this.fetchWorkspaceImageSourceDocker(
112-
{ span },
113-
repo,
114-
rev,
115-
user,
116-
dockerfilePath,
117-
),
118-
};
119-
}
12078
}
12179

12280
config.vscode = {
@@ -143,7 +101,7 @@ export class ConfigProvider {
143101
}
144102
}
145103

146-
protected async fetchCustomConfig(
104+
private async fetchCustomConfig(
147105
ctx: TraceContext,
148106
user: User,
149107
commit: CommitContext,
@@ -154,7 +112,7 @@ export class ConfigProvider {
154112

155113
try {
156114
let customConfig: WorkspaceConfig | undefined;
157-
let configBasePath = "";
115+
const configBasePath = "";
158116
if (AdditionalContentContext.is(commit) && commit.additionalFiles[".gitpod.yml"]) {
159117
customConfigString = commit.additionalFiles[".gitpod.yml"];
160118
const parseResult = this.gitpodParser.parse(customConfigString);
@@ -183,21 +141,6 @@ export class ConfigProvider {
183141
customConfigString = await contextRepoConfig;
184142
let origin: WorkspaceConfig["_origin"] = "repo";
185143

186-
if (!customConfigString) {
187-
/* We haven't found a Gitpod configuration file in the context repo - check definitely-gp.
188-
*
189-
* In case we had found a config file here, we'd still be checking the definitely GP repo, just to save some time.
190-
* While all those checks will be in vain, they should not leak memory either as they'll simply
191-
* be resolved and garbage collected.
192-
*/
193-
const definitelyGpConfig = this.fetchExternalGitpodFileContent({ span }, commit.repository);
194-
const { content, basePath } = await definitelyGpConfig;
195-
customConfigString = content;
196-
// We do not only care about the config itself but also where we got it from
197-
configBasePath = basePath;
198-
origin = "definitely-gp";
199-
}
200-
201144
if (!customConfigString) {
202145
const inferredConfig = this.configurationService.guessRepositoryConfiguration(
203146
{ span },
@@ -248,140 +191,7 @@ export class ConfigProvider {
248191
};
249192
}
250193

251-
protected async fetchWorkspaceImageSourceDocker(
252-
ctx: TraceContext,
253-
repository: Repository,
254-
revisionOrTagOrBranch: string,
255-
user: User,
256-
dockerFilePath: string,
257-
): Promise<Commit> {
258-
const span = TraceContext.startSpan("fetchWorkspaceImageSourceDocker", ctx);
259-
span.addTags({
260-
repository,
261-
revisionOrTagOrBranch,
262-
dockerFilePath,
263-
});
264-
265-
try {
266-
const host = repository.host;
267-
const hostContext = this.hostContextProvider.get(host);
268-
if (!hostContext || !hostContext.services) {
269-
throw new Error(`Cannot fetch workspace image source for host: ${host}`);
270-
}
271-
const repoHost = hostContext.services;
272-
const lastDockerFileSha = await repoHost.fileProvider.getLastChangeRevision(
273-
repository,
274-
revisionOrTagOrBranch,
275-
user,
276-
dockerFilePath,
277-
);
278-
return {
279-
repository,
280-
revision: lastDockerFileSha,
281-
};
282-
} catch (e) {
283-
TraceContext.setError({ span }, e);
284-
throw e;
285-
} finally {
286-
span.finish();
287-
}
288-
}
289-
290-
protected async fillInDefaultLocations(
291-
cfg: WorkspaceConfig | undefined,
292-
inferredConfig: Promise<WorkspaceConfig | undefined>,
293-
): Promise<void> {
294-
if (!cfg) {
295-
// there is no config - return
296-
return;
297-
}
298-
299-
if (!cfg.checkoutLocation) {
300-
const inferredCfg = await inferredConfig;
301-
if (inferredCfg) {
302-
cfg.checkoutLocation = inferredCfg.checkoutLocation;
303-
}
304-
}
305-
if (!cfg.workspaceLocation) {
306-
const inferredCfg = await inferredConfig;
307-
if (inferredCfg) {
308-
cfg.workspaceLocation = inferredCfg.workspaceLocation;
309-
}
310-
}
311-
}
312-
313-
protected async fetchExternalGitpodFileContent(
314-
ctx: TraceContext,
315-
repository: Repository,
316-
): Promise<{ content: MaybeContent; basePath: string }> {
317-
const span = TraceContext.startSpan("fetchExternalGitpodFileContent", ctx);
318-
span.setTag("repo", `${repository.owner}/${repository.name}`);
319-
320-
if (this.config.definitelyGpDisabled) {
321-
span.finish();
322-
return {
323-
content: undefined,
324-
basePath: `${repository.name}`,
325-
};
326-
}
327-
328-
try {
329-
const ownerConfigBasePath = `${repository.name}/${repository.owner}`;
330-
const baseConfigBasePath = `${repository.name}`;
331-
332-
const possibleConfigs = [
333-
[this.fetchDefinitelyGpContent({ span }, `${ownerConfigBasePath}/.gitpod.yml`), ownerConfigBasePath],
334-
[this.fetchDefinitelyGpContent({ span }, `${ownerConfigBasePath}/.gitpod`), ownerConfigBasePath],
335-
[this.fetchDefinitelyGpContent({ span }, `${baseConfigBasePath}/.gitpod.yml`), baseConfigBasePath],
336-
[this.fetchDefinitelyGpContent({ span }, `${baseConfigBasePath}/.gitpod`), baseConfigBasePath],
337-
];
338-
for (const [configPromise, basePath] of possibleConfigs) {
339-
const ownerConfig = await configPromise;
340-
if (ownerConfig !== undefined) {
341-
return {
342-
content: ownerConfig,
343-
basePath: basePath as string,
344-
};
345-
}
346-
}
347-
return {
348-
content: undefined,
349-
basePath: baseConfigBasePath,
350-
};
351-
} catch (e) {
352-
TraceContext.setError({ span }, e);
353-
throw e;
354-
} finally {
355-
span.finish();
356-
}
357-
}
358-
359-
protected async fetchDefinitelyGpContent(ctx: TraceContext, filePath: string) {
360-
const span = TraceContext.startSpan("fetchDefinitelyGpContent", ctx);
361-
span.setTag("filePath", filePath);
362-
363-
try {
364-
const url = `https://raw.githubusercontent.com/gitpod-io/definitely-gp/master/${filePath}`;
365-
const response = await fetch(url, {
366-
timeout: 10000,
367-
method: "GET",
368-
});
369-
let content;
370-
if (response.ok) {
371-
try {
372-
content = await response.text();
373-
} catch {}
374-
}
375-
return content;
376-
} catch (e) {
377-
TraceContext.setError({ span }, e);
378-
throw e;
379-
} finally {
380-
span.finish();
381-
}
382-
}
383-
384-
protected async validateConfig(config: WorkspaceConfig, user: User): Promise<void> {
194+
private async validateConfig(config: WorkspaceConfig, user: User): Promise<void> {
385195
// Make sure the projectRoot does not leave POD_PATH_WORKSPACE_BASE as that's a common
386196
// assumption throughout the code (e.g. ws-daemon)
387197
const checkoutLocation = config.checkoutLocation;
@@ -407,7 +217,7 @@ export class ConfigProvider {
407217
}
408218
}
409219

410-
protected leavesWorkspaceBase(normalizedPath: string) {
220+
private leavesWorkspaceBase(normalizedPath: string) {
411221
const pathSegments = normalizedPath.split(path.sep);
412222
return normalizedPath.includes("..") || pathSegments.slice(0, 2).join("/") != POD_PATH_WORKSPACE_BASE;
413223
}

components/server/src/workspace/image-source-provider.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import {
1414
WorkspaceImageSourceReference,
1515
WorkspaceImageSourceDocker,
1616
ImageConfigFile,
17-
ExternalImageConfigFile,
1817
User,
1918
AdditionalContentContext,
2019
} from "@gitpod/gitpod-protocol";
2120
import { createHash } from "crypto";
2221

2322
@injectable()
2423
export class ImageSourceProvider {
25-
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
24+
constructor(@inject(HostContextProvider) private readonly hostContextProvider: HostContextProvider) {}
2625

2726
public async getImageSource(
2827
ctx: TraceContext,
@@ -36,25 +35,7 @@ export class ImageSourceProvider {
3635
let result: WorkspaceImageSource;
3736

3837
const imgcfg = config.image;
39-
if (ExternalImageConfigFile.is(imgcfg)) {
40-
// we're asked to pull the Dockerfile from a repo possibly different than the one we're opening a workspace for (e.g. definitely-gp).
41-
const repository = imgcfg.externalSource.repository;
42-
const hostContext = this.hostContextProvider.get(repository.host);
43-
if (!hostContext || !hostContext.services) {
44-
throw new Error(`Cannot fetch workspace image source for host: ${repository.host}`);
45-
}
46-
const lastDockerFileSha = await hostContext.services.fileProvider.getLastChangeRevision(
47-
repository,
48-
imgcfg.externalSource.revision,
49-
user,
50-
imgcfg.file,
51-
);
52-
result = <WorkspaceImageSourceDocker>{
53-
dockerFilePath: imgcfg.file,
54-
dockerFileSource: imgcfg.externalSource,
55-
dockerFileHash: lastDockerFileSha,
56-
};
57-
} else if (ImageConfigFile.is(imgcfg)) {
38+
if (ImageConfigFile.is(imgcfg)) {
5839
// if a dockerfile sits in the additional content we use its contents sha
5940
if (
6041
AdditionalContentContext.is(context) &&
@@ -100,7 +81,7 @@ export class ImageSourceProvider {
10081
}
10182
}
10283

103-
protected getContentSHA(contents: string): string {
84+
private getContentSHA(contents: string): string {
10485
return createHash("sha256").update(contents).digest("hex");
10586
}
10687
}

0 commit comments

Comments
 (0)