Skip to content

Allow user select eap version of JetBrains IDE #7852

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 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ registry.{{ .Values.hostname }}
{{ template "gitpod.comp.imageRepo" . }}:{{- template "gitpod.comp.version" . -}}
{{- end -}}

{{- define "gitpod.comp.imageLatest" -}}
{{- $ := .root -}}
{{- $gp := .gp -}}
{{- $comp := .comp -}}
{{ template "gitpod.comp.imageRepo" . }}:latest
{{- end -}}

{{- define "gitpod.comp.configMap" -}}
{{- $comp := .comp -}}
{{ $comp.configMapName | default (printf "%s-config" $comp.name) }}
Expand Down
4 changes: 4 additions & 0 deletions chart/templates/server-ide-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,28 @@ options:
type: "desktop"
logo: "https://ide.{{ $.Values.hostname }}/image/ide-logo/intellijIdeaLogo.svg"
image: {{ (include "gitpod.comp.imageFull" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.intellij)) }}
latestImage: {{ (include "gitpod.comp.imageLatest" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.intellij)) }}
goland:
orderKey: "05"
title: "GoLand"
type: "desktop"
logo: "https://ide.{{ $.Values.hostname }}/image/ide-logo/golandLogo.svg"
image: {{ (include "gitpod.comp.imageFull" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.goland)) }}
latestImage: {{ (include "gitpod.comp.imageLatest" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.goland)) }}
pycharm:
orderKey: "06"
title: "PyCharm"
type: "desktop"
logo: "https://ide.{{ $.Values.hostname }}/image/ide-logo/pycharmLogo.svg"
image: {{ (include "gitpod.comp.imageFull" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.pycharm)) }}
latestImage: {{ (include "gitpod.comp.imageLatest" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.pycharm)) }}
phpstorm:
orderKey: "07"
title: "PhpStorm"
type: "desktop"
logo: "https://ide.{{ $.Values.hostname }}/image/ide-logo/phpstormLogo.svg"
image: {{ (include "gitpod.comp.imageFull" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.phpstorm)) }}
latestImage: {{ (include "gitpod.comp.imageLatest" (dict "root" $ "gp" $gp "comp" $gp.components.workspace.desktopIdeImages.phpstorm)) }}

defaultIde: "code"
defaultDesktopIde: "code-desktop"
Expand Down
24 changes: 19 additions & 5 deletions components/dashboard/src/settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UserContext } from "../user-context";
import settingsMenu from "./settings-menu";
import IDENone from '../icons/IDENone.svg';
import IDENoneDark from '../icons/IDENoneDark.svg';
import CheckBox from "../components/CheckBox";

type Theme = 'light' | 'dark' | 'system';

Expand All @@ -33,38 +34,47 @@ export default function Preferences() {
const { user } = useContext(UserContext);
const { setIsDark, isDark } = useContext(ThemeContext);

const updateUserIDEInfo = async (defaultDesktopIde: string, defaultIde: string) => {
const updateUserIDEInfo = async (defaultDesktopIde: string, defaultIde: string, useLatestVersion: boolean) => {
const useDesktopIde = defaultDesktopIde !== DesktopNoneId;
const desktopIde = useDesktopIde ? defaultDesktopIde : undefined;
const additionalData = user?.additionalData ?? {};
const settings = additionalData.ideSettings ?? {};
settings.useDesktopIde = useDesktopIde;
settings.defaultIde = defaultIde;
settings.defaultDesktopIde = desktopIde;
settings.useLatestVersion = useLatestVersion;
additionalData.ideSettings = settings;
getGitpodService().server.trackEvent({
event: "ide_configuration_changed",
properties: {
useDesktopIde,
defaultIde,
defaultDesktopIde: desktopIde
defaultDesktopIde: desktopIde,
useLatestVersion,
},
}).then().catch(console.error);
await getGitpodService().server.updateLoggedInUser({ additionalData });
}

const [defaultIde, setDefaultIde] = useState<string>(user?.additionalData?.ideSettings?.defaultIde || "");
const actuallySetDefaultIde = async (value: string) => {
await updateUserIDEInfo(defaultDesktopIde, value);
await updateUserIDEInfo(defaultDesktopIde, value, useLatestVersion);
setDefaultIde(value);
}

const [defaultDesktopIde, setDefaultDesktopIde] = useState<string>((user?.additionalData?.ideSettings?.useDesktopIde && user?.additionalData?.ideSettings?.defaultDesktopIde) || DesktopNoneId);
const actuallySetDefaultDesktopIde = async (value: string) => {
await updateUserIDEInfo(value, defaultIde);
await updateUserIDEInfo(value, defaultIde, useLatestVersion);
setDefaultDesktopIde(value);
}

const [useLatestVersion, setUseLatestVersion] = useState<boolean>(user?.additionalData?.ideSettings?.useLatestVersion ?? false);
const actuallySetUseLatestVersion = async (value: boolean) => {
await updateUserIDEInfo(defaultDesktopIde, defaultIde, value);
setUseLatestVersion(value);
}


const [ideOptions, setIdeOptions] = useState<IDEOptions | undefined>(undefined);
useEffect(() => {
(async () => {
Expand Down Expand Up @@ -124,7 +134,10 @@ export default function Preferences() {
}
</>}
{desktopIdeOptions && <>
<h3 className="mt-12">Desktop Editor <PillLabel type="warn" className="font-semibold mt-2 py-0.5 px-2 self-center">Beta</PillLabel></h3>
<h3 className="mt-12 flex">
Desktop Editor
<PillLabel type="warn" className="font-semibold py-0.5 px-2 self-center">Beta</PillLabel>
</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Optionally, choose the default desktop editor for opening workspaces.</p>
<div className="my-4 gap-4 flex flex-wrap max-w-2xl">
{
Expand All @@ -147,6 +160,7 @@ export default function Preferences() {
The <strong>JetBrains desktop IDEs</strong> are currently in beta. <a href="https://github.com/gitpod-io/gitpod/issues/6576" target="gitpod-feedback-issue" rel="noopener" className="gp-link">Send feedback</a> · <a href="https://www.gitpod.io/docs/integrations/jetbrains" target="_blank" rel="noopener noreferrer" className="gp-link">Documentation</a>
</p>
</>}
<CheckBox title="Latest Release" desc="Include the latest Early Access Program (EAP) version for each JetBrains IDE." checked={useLatestVersion} onChange={(e) => actuallySetUseLatestVersion(e.target.checked)}/>
</>}
<h3 className="mt-12">Theme</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Early bird or night owl? Choose your side.</p>
Expand Down
5 changes: 5 additions & 0 deletions components/gitpod-protocol/src/ide-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface IDEOption {
*/
image: string;

/**
* The latest image ref to the IDE image, this image ref always resolve to digest.
*/
latestImage?: string;

/**
* When this is `true`, the tag of this image is resolved to the latest
* image digest regularly.
Expand Down
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export type IDESettings = {
defaultIde?: string
useDesktopIde?: boolean
defaultDesktopIde?: string
useLatestVersion?: boolean
}

export interface UserPlatform {
Expand Down
15 changes: 15 additions & 0 deletions components/server/src/ide-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const scheme = {
"nodes": { "type": "array", "items": { "type": "string" } },
"hidden": { "type": "boolean" },
"image": { "type": "string" },
"latestImage": { "type": "string" },
"resolveImageDigest": { "type": "boolean" },
},
"required": [
Expand Down Expand Up @@ -190,6 +191,20 @@ export class IDEConfigService {
}
}

for (const [id, option] of Object.entries(newValue.ideOptions.options).filter(([_, x]) => x.latestImage)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this for loop is fairly complex, with many things happening in a single line - did you consider breaking it down a bit?

try {
value.ideOptions.options[id].latestImage = await this.resolveImageDigest(option.latestImage!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would find it a bit "cleaner" to use a boolean like option.useLatestImage, and if it's true, set option.latestImage (just like option.resolveImageDigest and option.image above).

Here, we seem to use option.latestImage both as a "boolean" (i.e. filter(([_, x]) => x.latestImage)) above) and a resolved value .latestImage = await .... This looks a little bit dangerous (e.g. we might accidentally resolve the same image multiple times, or maybe forget to resolve it elsewhere, etc).

However, not blocking the review due to this. Please feel free to address in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latestImage is a string not boolean, so filter(([_, x]) => x.latestImage) is equal than filter(([_, x]) => x.latestImage != null && x.latestImage !== '')
it no problem I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @iQQBot! Yes, I understand this, but my point was, I prefer something like this:

type Option = {
  resolveLatestImage: boolean;
  latestImage?: string;
}

if (option.resolveLatestImage) {
  option.latestImage = await resolve();
}

where the controlling condition is different from what's actually resolved.

Currently, the code seems to work like this:

type Option = {
  latestImage?: string;
}

if (option.latestImage) {
  option.latestImage = await resolve();
}

This makes it a bit unclear if an image has already been resolved or not, e.g.:

  • If the code is called multiple times, you might accidentally resolve this image multiple times
  • You cannot do if (!option.latestImage) { option.latestImage = await resolve(); }
  • Someone might accidentally "forget" to resolve the image in some cases (i.e. leave it as option.latestImage === "latest", because if (option.latestImage) looks "true")

log.info("ide config: successfully resolved latest image digest", {
ide: id,
latestImage: option.latestImage,
resolvedImage: value.ideOptions.options[id].latestImage,
trigger,
});
} catch (e) {
log.error('ide config: error while resolving latest image digest', e, { trigger });
}
}

const key = JSON.stringify(value);
if (key === this.state.key) {
return;
Expand Down
5 changes: 3 additions & 2 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ export class WorkspaceStarter {
}
}

const useLatest = !!user.additionalData?.ideSettings?.useLatestVersion;
const referrerIde = this.resolveReferrerIDE(workspace, user, ideConfig);
if (referrerIde) {
configuration.desktopIdeImage = referrerIde.option.image;
configuration.desktopIdeImage = useLatest ? (referrerIde.option.latestImage ?? referrerIde.option.image) : referrerIde.option.image
if (!user.additionalData?.ideSettings) {
// A user does not have IDE settings configured yet configure it with a referrer ide as default.
const additionalData = user?.additionalData || {};
Expand All @@ -356,7 +357,7 @@ export class WorkspaceStarter {
if (!!desktopIdeChoice) {
const mappedImage = ideConfig.ideOptions.options[desktopIdeChoice];
if (!!mappedImage && mappedImage.image) {
configuration.desktopIdeImage = mappedImage.image;
configuration.desktopIdeImage = useLatest ? (mappedImage.latestImage ?? mappedImage.image) : mappedImage.image
} else if (this.authService.hasPermission(user, "ide-settings")) {
// if the IDE choice isn't one of the preconfiured choices, we assume its the image name.
// For now, this feature requires special permissions.
Expand Down
44 changes: 24 additions & 20 deletions installer/pkg/components/server/ide/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,36 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
Image: common.ImageName(ctx.Config.Repository, ide.CodeDesktopInsidersIDEImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.CodeDesktopImageInsiders.Version),
},
intellij: {
OrderKey: pointer.String("04"),
Title: "IntelliJ IDEA",
Type: typeDesktop,
Logo: getIdeLogoPath("intellijIdeaLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.IntelliJDesktopIDEImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.IntelliJImage.Version),
OrderKey: pointer.String("04"),
Title: "IntelliJ IDEA",
Type: typeDesktop,
Logo: getIdeLogoPath("intellijIdeaLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.IntelliJDesktopIDEImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.IntelliJImage.Version),
LatestImage: common.ImageName(ctx.Config.Repository, ide.IntelliJDesktopIDEImage, "latest"),
},
goland: {
OrderKey: pointer.String("05"),
Title: "GoLand",
Type: typeDesktop,
Logo: getIdeLogoPath("golandLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.GoLandDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.GoLandImage.Version),
OrderKey: pointer.String("05"),
Title: "GoLand",
Type: typeDesktop,
Logo: getIdeLogoPath("golandLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.GoLandDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.GoLandImage.Version),
LatestImage: common.ImageName(ctx.Config.Repository, ide.GoLandDesktopIdeImage, "latest"),
},
pycharm: {
OrderKey: pointer.String("06"),
Title: "PyCharm",
Type: typeDesktop,
Logo: getIdeLogoPath("pycharmLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.PyCharmDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.PyCharmImage.Version),
OrderKey: pointer.String("06"),
Title: "PyCharm",
Type: typeDesktop,
Logo: getIdeLogoPath("pycharmLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.PyCharmDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.PyCharmImage.Version),
LatestImage: common.ImageName(ctx.Config.Repository, ide.PyCharmDesktopIdeImage, "latest"),
},
phpstorm: {
OrderKey: pointer.String("07"),
Title: "PhpStorm",
Type: typeDesktop,
Logo: getIdeLogoPath("phpstormLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.PhpStormDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.PhpStormImage.Version),
OrderKey: pointer.String("07"),
Title: "PhpStorm",
Type: typeDesktop,
Logo: getIdeLogoPath("phpstormLogo"),
Image: common.ImageName(ctx.Config.Repository, ide.PhpStormDesktopIdeImage, ctx.VersionManifest.Components.Workspace.DesktopIdeImages.PhpStormImage.Version),
LatestImage: common.ImageName(ctx.Config.Repository, ide.PhpStormDesktopIdeImage, "latest"),
},
},
DefaultIDE: "code",
Expand Down
1 change: 1 addition & 0 deletions installer/pkg/components/server/ide/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type IDEOption struct {
Notes []string `json:"notes,omitempty"`
Hidden *bool `json:"hidden,omitempty"`
Image string `json:"image"`
LatestImage string `json:"latestImage,omitempty"`
ResolveImageDigest *bool `json:"resolveImageDigest,omitempty"`
}

Expand Down