5
5
"errors"
6
6
"os"
7
7
"os/exec"
8
+ "path"
8
9
"strings"
9
10
10
11
"github.com/DefangLabs/defang/src/pkg"
@@ -19,6 +20,7 @@ const (
19
20
var (
20
21
DefangPrefix = pkg .Getenv ("DEFANG_PREFIX" , "Defang" ) // prefix for all resources created by Defang
21
22
DefangPulumiBackend = os .Getenv ("DEFANG_PULUMI_BACKEND" )
23
+ ErrLocalPulumiStopped = errors .New ("local pulumi command succeeded; stopping" )
22
24
PulumiConfigPassphrase = pkg .Getenv ("PULUMI_CONFIG_PASSPHRASE" , "asdf" )
23
25
)
24
26
@@ -44,6 +46,7 @@ func GetPulumiBackend(stateUrl string) (string, string, error) {
44
46
}
45
47
46
48
func runLocalCommand (ctx context.Context , dir string , env []string , cmd ... string ) error {
49
+ term .Debug ("Running local command `" , cmd , "` in dir " , dir )
47
50
// TODO - use enums to define commands instead of passing strings down from the caller
48
51
// #nosec G204
49
52
command := exec .CommandContext (ctx , cmd [0 ], cmd [1 :]... )
@@ -54,7 +57,7 @@ func runLocalCommand(ctx context.Context, dir string, env []string, cmd ...strin
54
57
return command .Run ()
55
58
}
56
59
57
- func DebugPulumi (ctx context.Context , env []string , cmd ... string ) error {
60
+ func DebugPulumiNodeJS (ctx context.Context , env []string , cmd ... string ) error {
58
61
// Locally we use the "dev" script from package.json to run Pulumi commands, which uses ts-node
59
62
localCmd := append ([]string {"npm" , "run" , "dev" }, cmd ... )
60
63
term .Debug (strings .Join (append (env , localCmd ... ), " " ))
@@ -73,7 +76,35 @@ func DebugPulumi(ctx context.Context, env []string, cmd ...string) error {
73
76
return err
74
77
}
75
78
// We always return an error to stop the CLI from "tailing" the cloud logs
76
- return errors .New ("local pulumi command succeeded; stopping" )
79
+ return ErrLocalPulumiStopped
80
+ }
81
+
82
+ func DebugPulumiGolang (ctx context.Context , env []string , cmd ... string ) error {
83
+ localCmd := append ([]string {"go" , "run" , "./..." }, cmd ... )
84
+ term .Debug (strings .Join (append (env , localCmd ... ), " " ))
85
+
86
+ dir := os .Getenv ("DEFANG_PULUMI_DIR" )
87
+ if dir == "" {
88
+ return nil // show the shell command, but use regular Pulumi command in cloud task
89
+ }
90
+
91
+ if gopath , err := exec .Command ("go" , "env" , "GOPATH" ).Output (); err != nil {
92
+ return err
93
+ } else {
94
+ env = append (env , "GOPATH=" + strings .TrimSpace (string (gopath )))
95
+ }
96
+
97
+ // Run the Pulumi command locally
98
+ env = append ([]string {
99
+ "PATH=" + os .Getenv ("PATH" ),
100
+ "USER=" + pkg .GetCurrentUser (), // needed for Pulumi
101
+ "HOME=" + os .Getenv ("HOME" ), // needed for go
102
+ }, env ... )
103
+ if err := runLocalCommand (ctx , path .Join (dir , "cd" , "gcp" ), env , localCmd ... ); err != nil {
104
+ return err
105
+ }
106
+ // We always return an error to stop the CLI from "tailing" the cloud logs
107
+ return ErrLocalPulumiStopped
77
108
}
78
109
79
110
func GetPrivateDomain (projectName string ) string {
0 commit comments