Skip to content

Commit 64f4da8

Browse files
Prince Rachit Sinharoboquat
Prince Rachit Sinha
authored andcommitted
[ws-deployment] Add gitpod installation step
1 parent fa8abe5 commit 64f4da8

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

operations/workspace/deployment/pkg/orchestrate/deploy.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ func Deploy(context *common.Context, clusters []*common.WorkspaceCluster) error
3535
return nil
3636
}
3737

38-
// TODO(prs): Add implementation once we have scripts in ops repo tested and
39-
// install step implemented
4038
func installGitpod(context *common.Context, cluster *common.WorkspaceCluster) error {
41-
log.Log.Infof("received request to install gitpod on cluster: %s cannot be processed. Implementation pending", cluster.Name)
42-
return nil
39+
log.Log.Infof("installing gitpod on cluster %s", cluster.Name)
40+
err := step.InstallGitpod(context, cluster)
41+
if err != nil {
42+
log.Log.Errorf("installation of gitpod on cluster: %s failed: %s", cluster.Name, err)
43+
} else {
44+
log.Log.Infof("installation of gitpod on cluster %s succeeded", cluster.Name)
45+
}
46+
return err
4347
}
4448

4549
func createCluster(context *common.Context, cluster *common.WorkspaceCluster) error {

operations/workspace/deployment/pkg/step/installgitpod.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
package step
66

77
import (
8+
"errors"
9+
"fmt"
10+
"os"
11+
"os/exec"
812
"strings"
913

14+
"github.com/gitpod-io/gitpod/common-go/log"
1015
"github.com/gitpod-io/gitpod/ws-deployment/pkg/common"
11-
"github.com/gitpod-io/gitpod/ws-deployment/pkg/runner"
1216
)
1317

1418
const (
@@ -17,18 +21,36 @@ const (
1721
DefaultGitpodInstallationScript = "dev/build-ws-cluster/install-gitpod.sh"
1822
)
1923

20-
func InstallGitpod(context *common.ProjectContext, gitpodContext *common.GitpodContext, cluster *common.WorkspaceCluster) error {
21-
err := runner.ShellRunWithDefaultConfig(DefaultGitpodInstallationScript, []string{"-g", context.Id, "-l", cluster.Region, "-n", cluster.Name, "-a", getValuesFilesArgString(gitpodContext)})
22-
return err
24+
func InstallGitpod(context *common.Context, cluster *common.WorkspaceCluster) error {
25+
if context.Overrides.DryRun {
26+
log.Log.Infof("dry run not supported for gitpod installation. skipping...")
27+
return nil
28+
}
29+
credFileEnvVar := fmt.Sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", context.Project.GCPSACredFile)
30+
if _, err := os.Stat(context.Project.GCPSACredFile); errors.Is(err, os.ErrNotExist) {
31+
// reset this to empty string so that we can fallback to default
32+
// gcloud context. This is useful in local development and execution
33+
// scenarios
34+
credFileEnvVar = ""
35+
}
36+
37+
cmd := exec.Command(DefaultGitpodInstallationScript, "-g", context.Project.Id, "-l", cluster.Region, "-n", cluster.Name, "-v", context.Gitpod.VersionsManifestFilePath, "-a", getValuesFilesArgString(cluster.ValuesFiles))
38+
// Set the env variable
39+
cmd.Env = append(os.Environ(), credFileEnvVar)
40+
// we will route the output to standard devices
41+
cmd.Stdout = os.Stdout
42+
cmd.Stderr = os.Stderr
43+
return cmd.Run()
44+
2345
}
2446

25-
func getValuesFilesArgString(gitpodContext *common.GitpodContext) string {
47+
func getValuesFilesArgString(valuesFiles []string) string {
2648
// the first file name should also have -f before it so we add
2749
// it explicitly here
2850
//
2951
// so for something like:
3052
// [v1.yaml, v2.yaml. v3.yaml]
3153
// we get
3254
// -f v1.yaml -f v2.yaml -f v3.yaml
33-
return " -f " + strings.Join(gitpodContext.ValuesFiles, " -f ")
55+
return " -f " + strings.Join(valuesFiles, " -f ")
3456
}

0 commit comments

Comments
 (0)