Browse Source

watch docker-compose log

master
forest 2 years ago
parent
commit
012d958d4e
  1. 39
      automation/dockerCompose.go
  2. 12
      automation/terraformActions.go

39
automation/dockerCompose.go

@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path"
"regexp"
"strings"
"time"
@ -188,6 +189,37 @@ func DockerComposeUp(
go (func() {
for logLine := range logLinesChannel {
logLines = append(logLines, logLine)
split := strings.Split(logLine, " ... ")
if len(split) == 2 {
leftSide := strings.Split(strings.TrimSpace(split[0]), " ")
status := split[1]
if len(leftSide) == 2 {
action := leftSide[0]
containerName := leftSide[1]
for moduleName, _ := range configs {
moduleNameUnderscore := fmt.Sprintf("%s_", moduleName)
if strings.HasPrefix(containerName, moduleNameUnderscore) {
serviceName := strings.TrimPrefix(containerName, moduleNameUnderscore)
serviceName = regexp.MustCompile("_[0-9]$").ReplaceAllString(serviceName, "")
if simpleStatus.Modules[moduleName] != nil {
for _, service := range simpleStatus.Modules[moduleName].Resources {
if service.DisplayName == serviceName {
if status == "done" {
service.State = "ok"
} else if action == "Recreating" {
service.State = "modifying"
} else if action == "Creating" {
service.State = "creating"
}
}
}
}
}
}
}
}
}
})()
@ -222,8 +254,8 @@ func DockerComposeUp(
// TODO handle panics in here with abort
details := applicationModulesMap[moduleName]
process := exec.Command("docker-compose", "--no-ansi", "up", "-d")
logLinesChannel <- fmt.Sprintf("\n(%s) $ docker-compose --no-ansi up -d\n", details.WorkingDir)
process := exec.Command("docker-compose", "--no-ansi", "up", "-d", "--remove-orphans")
logLinesChannel <- fmt.Sprintf("\n(%s) $ docker-compose --no-ansi up -d --remove-orphans\n", details.WorkingDir)
process.Dir = details.WorkingDir
stdoutPipe, err := process.StdoutPipe()
@ -259,6 +291,9 @@ func DockerComposeUp(
}
dockerComposeIsRunning = false
time.Sleep(time.Millisecond * 100)
close(logLinesChannel)
outputChannel <- TerraformApplyResult{
Error: nil,
Complete: true,

12
automation/terraformActions.go

@ -582,16 +582,14 @@ func monitorTerraformApplyProgress(
err = nil
}
terraformIsRunning = false
terraformSuccess := true
// once upon a time I got an error
// panic: send on closed channel @ terraformActions.go:204 (logLinesChannel <- blahblah; in scanAllOutput())
// I assumed it was a race condition so I put this sleep here to try to fix it, lets see if it ever happens again...
go (func() {
time.Sleep(time.Millisecond * 100)
close(logLinesChannel)
})()
terraformIsRunning = false
terraformSuccess := true
time.Sleep(time.Millisecond * 100)
close(logLinesChannel)
if err == nil && applyProcess.ProcessState.ExitCode() != 0 {
// If the apply fails, its not really an exceptional case, we don't want to exit the application.

Loading…
Cancel
Save