Skip to content

Commit 75e9c08

Browse files
authored
Tart: auto-detect the guest OS to use a proper Cirrus CI Agent binary (#724)
1 parent a7fb833 commit 75e9c08

File tree

2 files changed

+33
-1
lines changed
  • internal/executor/instance/persistentworker/isolation/tart

2 files changed

+33
-1
lines changed

internal/executor/instance/persistentworker/isolation/tart/tart.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,20 @@ func (tart *Tart) Run(ctx context.Context, config *runconfig.RunConfig) (err err
266266

267267
tart.logger.Debugf("IP %s retrieved from VM %s, running agent...", ip, tart.vm.Ident())
268268

269+
// Try to determine the agent OS, falling back to "darwin"
270+
// in case anything goes wrong to preserve the old behavior
271+
agentOS := "darwin"
272+
273+
info, err := tart.vm.Info(ctx)
274+
if err != nil {
275+
tart.logger.Debugf("failed to auto-detect the VM's operating system, assuming %q", agentOS)
276+
} else if info.OS != "" {
277+
agentOS = info.OS
278+
tart.logger.Debugf("successfully auto-detected the VM's operating system as %q", agentOS)
279+
}
280+
269281
err = remoteagent.WaitForAgent(ctx, tart.logger, fmt.Sprintf("%s:%d", ip, tart.sshPort),
270-
tart.sshUser, tart.sshPassword, "darwin", "arm64",
282+
tart.sshUser, tart.sshPassword, agentOS, "arm64",
271283
config, true, initializeHooks, terminateHooks, "",
272284
map[string]string{"CIRRUS_VM_ID": tart.vm.Ident()})
273285
if err != nil {

internal/executor/instance/persistentworker/isolation/tart/vm.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tart
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"github.com/cirruslabs/echelon"
78
"github.com/getsentry/sentry-go"
@@ -21,6 +22,10 @@ type VM struct {
2122
errChan chan error
2223
}
2324

25+
type Info struct {
26+
OS string `json:"os"`
27+
}
28+
2429
type directoryMount struct {
2530
Name string
2631
Path string
@@ -197,6 +202,21 @@ func (vm *VM) RetrieveIP(ctx context.Context) (string, error) {
197202
return strings.TrimSpace(stdout), nil
198203
}
199204

205+
func (vm *VM) Info(ctx context.Context) (*Info, error) {
206+
stdout, _, err := Cmd(ctx, vm.env, "get", "--format", "json", vm.ident)
207+
if err != nil {
208+
return nil, err
209+
}
210+
211+
var info Info
212+
213+
if err := json.Unmarshal([]byte(stdout), &info); err != nil {
214+
return nil, err
215+
}
216+
217+
return &info, nil
218+
}
219+
200220
func (vm *VM) Close() error {
201221
ctx := context.Background()
202222

0 commit comments

Comments
 (0)