Skip to content

Commit

Permalink
🐛 When launching docker linter, log folder does not exist for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid committed Sep 18, 2024
1 parent 5a9660b commit 161a96a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions platform/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ func gitRun(cwd string, command []string, logdir string) (string, string, error)
return "", "", err
}
stdout, stderr, _, err := RunCmdRedirectOutput(cwd, args...)
logger.Printf("Executing command: %v", args)
logger.Println(stdout)
if logger != nil {
logger.Printf("Executing command: %v", args)
logger.Println(stdout)
}
if stderr != "" {
logger.Error(stderr + "\n")
if logger != nil {
logger.Error(stderr + "\n")
} else {
log.Error(stderr)
}
}
if err != nil {
log.Errorf("Error executing git command %s: %s", strings.Join(args, " "), err)
Expand Down Expand Up @@ -114,8 +120,8 @@ func GitCurrentRevision(cwd string, logdir string) (string, error) {

// GitRevisionExists returns true when revision exists in history.
func GitRevisionExists(cwd string, revision string, logdir string) bool {
_, stderr, _ := gitRun(cwd, []string{"show", "--no-patch", revision}, logdir)
if strings.Contains(stderr, revision) || strings.Contains(stderr, "fatal:") {
_, stderr, err := gitRun(cwd, []string{"show", "--no-patch", revision}, logdir)
if strings.Contains(stderr, revision) || strings.Contains(stderr, "fatal:") || err != nil {
return false
}
return true
Expand Down
4 changes: 4 additions & 0 deletions platform/logmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (lm *LoggerManager) GetLogger(logdir string, command string) (*logrus.Logge

logger := logrus.New()

if _, err := os.Stat(logdir); os.IsNotExist(err) {
// When docker being launched, directory does not get created, returning nil
return nil, nil
}
logFileName := filepath.Join(logdir, filepath.Base(command)+".log")

logFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
Expand Down

0 comments on commit 161a96a

Please sign in to comment.