fixing ssh again :)
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 13s

This commit is contained in:
2026-03-14 11:59:33 -03:00
parent a7b46760c8
commit 07cacfeb29

View File

@@ -27,8 +27,16 @@ func NewGitService() Service {
}
}
func shouldUseSSH() bool {
_, err := os.Stat("/root/.ssh/id_rsa")
return err == nil
}
func (s *gitService) CheckConnection(url string) error {
cmd := exec.Command("git", "ls-remote", url)
if shouldUseSSH() {
cmd.Env = append(os.Environ(), "GIT_SSH_COMMAND=ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no")
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to check git connection: %w", err)
}
@@ -43,15 +51,10 @@ func (s *gitService) FetchContents(url string) error {
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)
if shouldUseSSH() {
cmd = exec.Command("git", "clone", url, s.repoDir)
cmd.Env = append(os.Environ(), "GIT_SSH_COMMAND=ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no")
} else {
cmd = exec.Command("git", "clone", url, s.repoDir)
}