Skip to content

Commit

Permalink
Improve error handling/output
Browse files Browse the repository at this point in the history
  • Loading branch information
kdambekalns committed Sep 29, 2020
1 parent 5395312 commit d7ca065
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cmd/beach/cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ func handleDownRun(cmd *cobra.Command, args []string) {
return
}
commandArgs := []string{"-f", sandbox.ProjectRootPath + "/.localbeach.docker-compose.yaml", "rm", "--force", "--stop", "-v"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
output, err := exec.RunCommand("docker-compose", commandArgs)
if err != nil {
log.Fatal(err)
log.Fatal(output)
return
}
}

log.Info("Stopping database & nginx...")
commandArgs := []string{"-f", "/usr/local/lib/localbeach/docker-compose.yml", "rm", "--force", "--stop", "-v"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
output, err := exec.RunCommand("docker-compose", commandArgs)
if err != nil {
log.Fatal(err)
log.Fatal(output)
return
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/beach/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func handleStartRun(cmd *cobra.Command, args []string) {

sandbox, err := beachsandbox.GetActiveSandbox()
if err != nil {
log.Fatal(err)
log.Fatal("Could not activate sandbox")
return
}

Expand All @@ -71,16 +71,16 @@ func handleStartRun(cmd *cobra.Command, args []string) {
}

commandArgs = []string{"-f", sandbox.ProjectRootPath + "/.localbeach.docker-compose.yaml", "up", "--remove-orphans", "-d"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
output, err := exec.RunCommand("docker-compose", commandArgs)
if err != nil {
log.Fatal(err)
log.Fatal(output)
return
}

commandArgs = []string{"exec", "local_beach_database", "/bin/bash", "-c", "echo 'CREATE DATABASE IF NOT EXISTS `" + sandbox.ProjectName + "`' | mysql -u root --password=password"}
_, err = exec.RunCommand("docker", commandArgs)
output, err = exec.RunCommand("docker", commandArgs)
if err != nil {
log.Fatal(err)
log.Fatal(output)
return
}

Expand All @@ -92,22 +92,22 @@ func handleStartRun(cmd *cobra.Command, args []string) {
func startLocalBeach() error {
output, err := exec.RunCommand("docker-compose", []string{"-f", "/usr/local/lib/localbeach/docker-compose.yml", "ps", "-q"})
if err != nil {
return err
return errors.New("failed to check for running containers")
}
if len(output) == 0 {
log.Info("Starting nginx & database ...")
commandArgs := []string{"-f", "/usr/local/lib/localbeach/docker-compose.yml", "up", "--remove-orphans", "-d"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
if err != nil {
return err
return errors.New("container startup failed")
}

log.Info("Waiting for database ...")
tries := 1
for {
output, err := exec.RunCommand("docker", []string{"inspect", "-f", "{{.State.Health.Status}}", "local_beach_database"})
if err != nil {
return err
return errors.New("failed to check for database container health")
}
if strings.TrimSpace(output) == "healthy" {
break
Expand Down

0 comments on commit d7ca065

Please sign in to comment.