5
5
package step
6
6
7
7
import (
8
+ "errors"
9
+ "fmt"
10
+ "os"
11
+ "os/exec"
8
12
"strings"
9
13
14
+ "github.com/gitpod-io/gitpod/common-go/log"
10
15
"github.com/gitpod-io/gitpod/ws-deployment/pkg/common"
11
- "github.com/gitpod-io/gitpod/ws-deployment/pkg/runner"
12
16
)
13
17
14
18
const (
@@ -17,18 +21,36 @@ const (
17
21
DefaultGitpodInstallationScript = "dev/build-ws-cluster/install-gitpod.sh"
18
22
)
19
23
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
+
23
45
}
24
46
25
- func getValuesFilesArgString (gitpodContext * common. GitpodContext ) string {
47
+ func getValuesFilesArgString (valuesFiles [] string ) string {
26
48
// the first file name should also have -f before it so we add
27
49
// it explicitly here
28
50
//
29
51
// so for something like:
30
52
// [v1.yaml, v2.yaml. v3.yaml]
31
53
// we get
32
54
// -f v1.yaml -f v2.yaml -f v3.yaml
33
- return " -f " + strings .Join (gitpodContext . ValuesFiles , " -f " )
55
+ return " -f " + strings .Join (valuesFiles , " -f " )
34
56
}
0 commit comments