fixing ssh connection
All checks were successful
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 38s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 14s

This commit is contained in:
2026-03-14 11:54:44 -03:00
parent 3f4cbfd41d
commit a7b46760c8

View File

@@ -32,19 +32,35 @@ func (s *gitService) CheckConnection(url string) error {
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to check git connection: %w", err)
}
fmt.Println("Git connection checked successfully")
return nil
}
func (s *gitService) FetchContents(url string) error {
// Remove the repo directory if it already exists from a previous run
fmt.Println("Removing repo directory")
_ = os.RemoveAll(s.repoDir)
cmd := exec.Command("git", "clone", url, s.repoDir)
fmt.Println("Cloning repository")
// check for existing /root/.ssh/id_rsa key
useSSH := false
if _, err := os.Stat("/root/.ssh/id_rsa"); err == nil {
useSSH = true
}
var cmd *exec.Cmd
if useSSH {
cmd = exec.Command("git", "clone", "-i", "/root/.ssh/id_rsa", url, s.repoDir)
} else {
cmd = exec.Command("git", "clone", url, s.repoDir)
}
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to fetch contents: %w, stderr: %s", err, stderr.String())
}
fmt.Println("Repository cloned successfully")
return nil
}