@@ -13,9 +13,8 @@ import (
13
13
"time"
14
14
15
15
"cdr.dev/slog"
16
- "github.com/coder/coder/v2/codersdk"
17
- "github.com/coder/coder/v2/codersdk/agentsdk"
18
16
"github.com/coder/envbuilder"
17
+ "github.com/coder/envbuilder/internal/notcodersdk"
19
18
"github.com/coder/serpent"
20
19
21
20
// *Never* remove this. Certificates are not bundled as part
@@ -25,12 +24,21 @@ import (
25
24
)
26
25
27
26
func main () {
27
+ cmd := envbuilderCmd ()
28
+ err := cmd .Invoke ().WithOS ().Run ()
29
+ if err != nil {
30
+ fmt .Fprintf (os .Stderr , "error: %v" , err )
31
+ os .Exit (1 )
32
+ }
33
+ }
34
+
35
+ func envbuilderCmd () serpent.Command {
28
36
var options envbuilder.Options
29
37
cmd := serpent.Command {
30
38
Use : "envbuilder" ,
31
39
Options : options .CLI (),
32
40
Handler : func (inv * serpent.Invocation ) error {
33
- var sendLogs func (ctx context.Context , log ... agentsdk .Log ) error
41
+ var sendLogs func (ctx context.Context , log ... notcodersdk .Log ) error
34
42
if options .CoderAgentToken != "" {
35
43
if options .CoderAgentURL == "" {
36
44
return errors .New ("CODER_AGENT_URL must be set if CODER_AGENT_TOKEN is set" )
@@ -39,34 +47,34 @@ func main() {
39
47
if err != nil {
40
48
return fmt .Errorf ("unable to parse CODER_AGENT_URL as URL: %w" , err )
41
49
}
42
- client := agentsdk .New (u )
50
+ client := notcodersdk .New (u )
43
51
client .SetSessionToken (options .CoderAgentToken )
44
- client .SDK . HTTPClient = & http.Client {
52
+ client .HTTPClient = & http.Client {
45
53
Transport : & http.Transport {
46
54
TLSClientConfig : & tls.Config {
47
55
InsecureSkipVerify : options .Insecure ,
48
56
},
49
57
},
50
58
}
51
59
var flushAndClose func (ctx context.Context ) error
52
- sendLogs , flushAndClose = agentsdk .LogsSender (agentsdk .ExternalLogSourceID , client .PatchLogs , slog.Logger {})
60
+ sendLogs , flushAndClose = notcodersdk .LogsSender (notcodersdk .ExternalLogSourceID , client .PatchLogs , slog.Logger {})
53
61
defer flushAndClose (inv .Context ())
54
62
55
63
// This adds the envbuilder subsystem.
56
64
// If telemetry is enabled in a Coder deployment,
57
65
// this will be reported and help us understand
58
66
// envbuilder usage.
59
- if ! slices .Contains (options .CoderAgentSubsystem , string (codersdk .AgentSubsystemEnvbuilder )) {
60
- options .CoderAgentSubsystem = append (options .CoderAgentSubsystem , string (codersdk .AgentSubsystemEnvbuilder ))
67
+ if ! slices .Contains (options .CoderAgentSubsystem , string (notcodersdk .AgentSubsystemEnvbuilder )) {
68
+ options .CoderAgentSubsystem = append (options .CoderAgentSubsystem , string (notcodersdk .AgentSubsystemEnvbuilder ))
61
69
os .Setenv ("CODER_AGENT_SUBSYSTEM" , strings .Join (options .CoderAgentSubsystem , "," ))
62
70
}
63
71
}
64
72
65
- options .Logger = func (level codersdk .LogLevel , format string , args ... interface {}) {
73
+ options .Logger = func (level notcodersdk .LogLevel , format string , args ... interface {}) {
66
74
output := fmt .Sprintf (format , args ... )
67
75
fmt .Fprintln (inv .Stderr , output )
68
76
if sendLogs != nil {
69
- sendLogs (inv .Context (), agentsdk .Log {
77
+ sendLogs (inv .Context (), notcodersdk .Log {
70
78
CreatedAt : time .Now (),
71
79
Output : output ,
72
80
Level : level ,
@@ -76,14 +84,10 @@ func main() {
76
84
77
85
err := envbuilder .Run (inv .Context (), options )
78
86
if err != nil {
79
- options .Logger (codersdk .LogLevelError , "error: %s" , err )
87
+ options .Logger (notcodersdk .LogLevelError , "error: %s" , err )
80
88
}
81
89
return err
82
90
},
83
91
}
84
- err := cmd .Invoke ().WithOS ().Run ()
85
- if err != nil {
86
- fmt .Fprintf (os .Stderr , "error: %v" , err )
87
- os .Exit (1 )
88
- }
92
+ return cmd
89
93
}
0 commit comments