in scripts/remote.go [70:133]
func doTarget(target string, config *ssh.ClientConfig) {
client, err := ssh.Dial("tcp", net.JoinHostPort(target, *port), config)
if err != nil {
log.Printf("ERROR: failed to connect to %s: %s", target, err)
return
}
defer client.Close()
c, err := sftp.NewClient(client)
if err != nil {
log.Printf("ERROR: failed to establish sftp to %s: %s", target, err)
return
}
defer c.Close()
tmp, err := ioutil.TempDir("", "")
if err != nil {
log.Printf("ERROR: failed to create temp dir: %s", err)
return
}
binPath, err := copySFTP(c, tmp, *binary, 0755)
if err != nil {
log.Printf("ERROR: failed to copy sftp to %s: %s", target, err)
return
}
log.Printf("copied %s to %s", *binary, binPath)
cfgPath, err := copySFTP(c, tmp, *cfg, 0644)
if err != nil {
log.Printf("ERROR: failed to copy sftp to %s: %s", target, err)
return
}
log.Printf("copied %s to %s", *cfg, cfgPath)
for _, b := range *bundles {
bPath, err := copyBundle(c, tmp, b)
if err != nil {
log.Printf("ERROR: failed to copy sftp to %s: %s", b, err)
return
}
log.Printf("copied %s to %s", b, bPath)
}
session, err := client.NewSession()
if err != nil {
log.Printf("ERROR: failed to create session on %s: %s", target, err)
return
}
defer session.Close()
session.Stderr = os.Stderr
session.Stdout = os.Stdout
if err := session.Run(
fmt.Sprintf(
"cd %s && %s --log-level DEBUG --local-config %s",
filepath.Dir(binPath), binPath, cfgPath,
),
); err != nil {
log.Printf("ERROR: failed to run go2chef remotely: %s", err)
return
}
}