Skip to content

Commit d22e969

Browse files
committed
[gp-cli] support gp validate with default image
1 parent 7652208 commit d22e969

File tree

10 files changed

+338
-59
lines changed

10 files changed

+338
-59
lines changed

components/gitpod-cli/cmd/validate.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
"github.com/gitpod-io/gitpod/common-go/log"
21+
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
2122
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
2223
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
2324
"github.com/sirupsen/logrus"
@@ -88,8 +89,11 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
8889
var dockerContext string
8990
switch img := gitpodConfig.Image.(type) {
9091
case nil:
91-
// TODO: GET FROM SERVER
92-
image = "gitpod/workspace-full:latest"
92+
defaultImage, err := getOrganizationDefaultWorkspaceImage(ctx)
93+
if err != nil {
94+
return GpError{Err: err, OutCome: utils.Outcome_SystemErr, ErrorCode: utils.RebuildErrorCode_FailedToGetDefaultImage, Silence: true}
95+
}
96+
image = defaultImage
9397
case string:
9498
image = img
9599
case map[interface{}]interface{}:
@@ -485,6 +489,26 @@ Connect using SSH keys (https://gitpod.io/keys):
485489
return nil
486490
}
487491

492+
func getOrganizationDefaultWorkspaceImage(ctx context.Context) (string, error) {
493+
wsInfo, err := gitpod.GetWSInfo(ctx)
494+
if err != nil {
495+
return "", err
496+
}
497+
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
498+
"function:getOrgSettings",
499+
"resource:team::" + wsInfo.OrganizationId + "::get",
500+
})
501+
if err != nil {
502+
return "", err
503+
}
504+
defer client.Close()
505+
settings, err := client.GetOrgSettings(ctx, wsInfo.OrganizationId)
506+
if err != nil {
507+
return "", err
508+
}
509+
return settings.DefaultWorkspaceImage, nil
510+
}
511+
488512
func setLoggerFormatter(logger *logrus.Logger) {
489513
logger.SetFormatter(&prefixed.TextFormatter{
490514
TimestampFormat: "2006-01-02 15:04:05",

components/gitpod-cli/pkg/utils/trackEvent.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ const (
2424
UserErrorCode = "user_error"
2525

2626
// Rebuild
27-
RebuildErrorCode_ImageBuildFailed = "rebuild_image_build_failed"
28-
RebuildErrorCode_DockerErr = "rebuild_docker_err"
29-
RebuildErrorCode_DockerNotFound = "rebuild_docker_not_found"
30-
RebuildErrorCode_DockerRunFailed = "rebuild_docker_run_failed"
31-
RebuildErrorCode_MalformedGitpodYaml = "rebuild_malformed_gitpod_yaml"
32-
RebuildErrorCode_MissingGitpodYaml = "rebuild_missing_gitpod_yaml"
33-
RebuildErrorCode_NoCustomImage = "rebuild_no_custom_image"
34-
RebuildErrorCode_AlreadyInDebug = "rebuild_already_in_debug"
35-
RebuildErrorCode_InvaligLogLevel = "rebuild_invalid_log_level"
27+
RebuildErrorCode_ImageBuildFailed = "rebuild_image_build_failed"
28+
RebuildErrorCode_DockerErr = "rebuild_docker_err"
29+
RebuildErrorCode_DockerNotFound = "rebuild_docker_not_found"
30+
RebuildErrorCode_DockerRunFailed = "rebuild_docker_run_failed"
31+
RebuildErrorCode_MalformedGitpodYaml = "rebuild_malformed_gitpod_yaml"
32+
RebuildErrorCode_MissingGitpodYaml = "rebuild_missing_gitpod_yaml"
33+
RebuildErrorCode_NoCustomImage = "rebuild_no_custom_image"
34+
RebuildErrorCode_AlreadyInDebug = "rebuild_already_in_debug"
35+
RebuildErrorCode_InvaligLogLevel = "rebuild_invalid_log_level"
36+
RebuildErrorCode_FailedToGetDefaultImage = "rebuild_failed_to_get_default_image"
3637

3738
// UserError
3839
UserErrorCode_NeedUpgradePlan = "plan_upgrade_required"

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type APIInterface interface {
9393
SetTeamMemberRole(ctx context.Context, teamID, userID string, role TeamMemberRole) error
9494
RemoveTeamMember(ctx context.Context, teamID, userID string) error
9595

96+
// Organization
97+
GetOrgSettings(ctx context.Context, orgID string) (*OrganizationSettings, error)
98+
9699
// Projects
97100
CreateProject(ctx context.Context, options *CreateProjectOptions) (*Project, error)
98101
DeleteProject(ctx context.Context, projectID string) error
@@ -235,6 +238,10 @@ const (
235238
// FunctionDeleteTeam is the name of the deleteTeam function
236239
FunctionDeleteTeam FunctionName = "deleteTeam"
237240

241+
// Organizations
242+
// FunctionGetOrgSettings is the name of the getOrgSettings function
243+
FunctionGetOrgSettings FunctionName = "getOrgSettings"
244+
238245
// Projects
239246
FunctionCreateProject FunctionName = "createProject"
240247
FunctionDeleteProject FunctionName = "deleteProject"
@@ -1471,6 +1478,16 @@ func (gp *APIoverJSONRPC) DeleteTeam(ctx context.Context, teamID string) (err er
14711478
return
14721479
}
14731480

1481+
func (gp *APIoverJSONRPC) GetOrgSettings(ctx context.Context, orgID string) (res *OrganizationSettings, err error) {
1482+
if gp == nil {
1483+
err = errNotConnected
1484+
return
1485+
}
1486+
_params := []interface{}{orgID}
1487+
err = gp.C.Call(ctx, string(FunctionGetOrgSettings), _params, &res)
1488+
return
1489+
}
1490+
14741491
func (gp *APIoverJSONRPC) CreateProject(ctx context.Context, options *CreateProjectOptions) (res *Project, err error) {
14751492
if gp == nil {
14761493
err = errNotConnected
@@ -2238,6 +2255,11 @@ type TeamMembershipInvite struct {
22382255
InvitedEmail string `json:"invitedEmail,omitempty"`
22392256
}
22402257

2258+
type OrganizationSettings struct {
2259+
WorkspaceSharingDisabled bool `json:"workspaceSharingDisabled,omitempty"`
2260+
DefaultWorkspaceImage string `json:"defaultWorkspaceImage,omitempty"`
2261+
}
2262+
22412263
type Project struct {
22422264
ID string `json:"id,omitempty"`
22432265
UserID string `json:"userId,omitempty"`

components/gitpod-protocol/go/mock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/server/src/workspace/workspace-starter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ImageBuildLogInfo,
4141
ImageConfigFile,
4242
NamedWorkspaceFeatureFlag,
43+
Organization,
4344
Permission,
4445
Project,
4546
RefType,
@@ -1563,6 +1564,11 @@ export class WorkspaceStarter {
15631564
sysEnvvars.push(ev);
15641565
}
15651566

1567+
const orgIdEnv = new EnvironmentVariable();
1568+
orgIdEnv.setName("GITPOD_ORGANIZATION_ID");
1569+
orgIdEnv.setValue(workspace.organizationId);
1570+
sysEnvvars.push(orgIdEnv);
1571+
15661572
const spec = new StartWorkspaceSpec();
15671573
await createGitpodTokenPromise;
15681574
spec.setEnvvarsList(envvars);
@@ -1634,6 +1640,7 @@ export class WorkspaceStarter {
16341640
"function:setEnvVar",
16351641
"function:deleteEnvVar",
16361642
"function:getTeams",
1643+
"function:getOrgSettings",
16371644
"function:trackEvent",
16381645
"function:getSupportedWorkspaceClasses",
16391646
// getIDToken is used by Gitpod's OIDC Identity Provider to check for authorisation.
@@ -1678,6 +1685,12 @@ export class WorkspaceStarter {
16781685
subjectID: "*",
16791686
operations: ["create", "get"],
16801687
}),
1688+
"resource:" +
1689+
ScopedResourceGuard.marshalResourceScope({
1690+
kind: "team",
1691+
subjectID: workspace.organizationId,
1692+
operations: ["get"],
1693+
}),
16811694
];
16821695
if (CommitContext.is(workspace.context)) {
16831696
const subjectID = workspace.context.repository.owner + "/" + workspace.context.repository.name;

components/supervisor-api/go/info.pb.go

Lines changed: 45 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/info.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ message WorkspaceInfoResponse {
100100

101101
// configcat_enabled controls whether configcat is enabled
102102
bool configcat_enabled = 18;
103+
104+
// organization_id is the Organization that open this workspace
105+
string organization_id = 19;
103106
}
104107

105108
enum DebugWorkspaceType {

0 commit comments

Comments
 (0)