agaainnn
All checks were successful
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 37s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 11s

This commit is contained in:
2026-03-14 12:03:35 -03:00
parent 07cacfeb29
commit 86870c22db

View File

@@ -27,15 +27,33 @@ func NewGitService() Service {
}
}
func shouldUseSSH() bool {
_, err := os.Stat("/root/.ssh/id_rsa")
return err == nil
func prepareSSHKey() (string, bool) {
b, err := os.ReadFile("/root/.ssh/id_rsa")
if err != nil {
return "", false
}
// Fix literal escaped newlines and CRLF issues that cause libcrypto errors
content := strings.ReplaceAll(string(b), "\\n", "\n")
content = strings.ReplaceAll(content, "\r", "")
// Ensure there is a trailing newline
if !strings.HasSuffix(content, "\n") {
content += "\n"
}
tmpPath := "/tmp/id_rsa"
if err := os.WriteFile(tmpPath, []byte(content), 0600); err != nil {
return "", false
}
return tmpPath, true
}
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 keyPath, ok := prepareSSHKey(); ok {
cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s -o StrictHostKeyChecking=no", keyPath))
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to check git connection: %w", err)
@@ -52,9 +70,9 @@ func (s *gitService) FetchContents(url string) error {
fmt.Println("Cloning repository")
var cmd *exec.Cmd
if shouldUseSSH() {
if keyPath, ok := prepareSSHKey(); ok {
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")
cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s -o StrictHostKeyChecking=no", keyPath))
} else {
cmd = exec.Command("git", "clone", url, s.repoDir)
}