diff --git a/deploy.go b/deploy.go index aca0f42..8dcbaaa 100644 --- a/deploy.go +++ b/deploy.go @@ -5,52 +5,43 @@ package main import ( - "log" - "github.com/tsuru/deploy-agent/internal/tsuru" "github.com/tsuru/tsuru/exec" ) -func build(c tsuru.Client, appName string, cmd []string, fs Filesystem, executor exec.Executor) { - log.SetFlags(0) +func build(c tsuru.Client, appName string, cmd []string, fs Filesystem, executor exec.Executor) error { envs, err := c.GetAppEnvs(appName) if err != nil { - log.Fatal(err) - } - err = execScript(cmd, envs, nil, fs, executor) - if err != nil { - log.Fatal(err) + return err } + return execScript(cmd, envs, nil, fs, executor) } -func deploy(c tsuru.Client, appName string, fs Filesystem, executor exec.Executor) { - log.SetFlags(0) +func deploy(c tsuru.Client, appName string, fs Filesystem, executor exec.Executor) error { var yamlData tsuru.TsuruYaml envs, err := c.RegisterUnit(appName, yamlData) if err != nil { - log.Fatal(err) + return err } diff, firstDeploy, err := readDiffDeploy(fs) if !firstDeploy || err != nil { err = c.SendDiffDeploy(diff, appName) if err != nil { - log.Fatal(err) + return err } } yamlData, err = loadTsuruYaml(fs) if err != nil { - log.Fatal(err) + return err } err = buildHooks(yamlData, envs, fs, executor) if err != nil { - log.Fatal(err) + return err } err = loadProcesses(&yamlData, fs) if err != nil { - log.Fatal(err) + return err } _, err = c.RegisterUnit(appName, yamlData) - if err != nil { - log.Fatal(err) - } + return err } diff --git a/deploy_test.go b/deploy_test.go index 5dd0376..f156b0a 100644 --- a/deploy_test.go +++ b/deploy_test.go @@ -30,7 +30,8 @@ func (s *S) TestBuild(c *check.C) { URL: server.URL, Token: "fake-token", } - build(client, "app1", []string{"ls"}, s.fs, s.exec) + err := build(client, "app1", []string{"ls"}, s.fs, s.exec) + c.Assert(err, check.IsNil) } func (s *S) TestDeploy(c *check.C) { @@ -72,5 +73,6 @@ func (s *S) TestDeploy(c *check.C) { URL: server.URL, Token: "fake-token", } - deploy(client, "app1", s.fs, s.exec) + err = deploy(client, "app1", s.fs, s.exec) + c.Assert(err, check.IsNil) } diff --git a/main.go b/main.go index 2bba032..75806f5 100644 --- a/main.go +++ b/main.go @@ -97,18 +97,25 @@ func main() { }() } + var err error switch command[len(command)-1] { case "build": - build(c, appName, command[:len(command)-1], filesystem, executor) + err = build(c, appName, command[:len(command)-1], filesystem, executor) case "deploy-only": - deploy(c, appName, filesystem, executor) + err = deploy(c, appName, filesystem, executor) case "deploy": // backward compatibility with tsuru < 1.4.0 command = command[:len(command)-1] fallthrough default: - build(c, appName, command, filesystem, executor) - deploy(c, appName, filesystem, executor) + err = build(c, appName, command, filesystem, executor) + if err != nil { + break + } + err = deploy(c, appName, filesystem, executor) + } + if err != nil { + fatal("[deploy-agent] error: %v", err) } }