diff --git a/internal/deploy/deploy.go b/internal/deploy/deploy.go new file mode 100644 index 0000000..269fc23 --- /dev/null +++ b/internal/deploy/deploy.go @@ -0,0 +1,32 @@ +package deploy + +import ( + "flow/services/internal" + "fmt" + "os" + + "github.com/magefile/mage/sh" +) + +func Deploy(dockerHost, environment, name string, daemon bool) error { + os.Setenv("DOCKER_HOST", dockerHost) + + command := []string{ + "docker", + "compose", + "--project-directory", + fmt.Sprintf("%s/%s/compose", internal.RootBuildDir, environment), + "up", + "--build", + } + + if daemon { + command = append(command, "-d") + } + + if name != "all" { + command = append(command, name) + } + + return sh.RunV(command[0], command[1:]...) +} diff --git a/magefiles/magefile.go b/magefiles/magefile.go index 9480af9..00760be 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -5,6 +5,7 @@ package main import ( "flow/services/internal" "flow/services/internal/config" + "flow/services/internal/deploy" "flow/services/internal/prepare" "fmt" "os" @@ -36,10 +37,10 @@ func Clean(environment string) error { return nil } -// Deploy deploys the services to the Flow Platform. -func Deploy(environment, name string) error { +// Deploy deploys the service(s) to the Flow Platform. +func Deploy(environment, service string) error { mg.Deps( - mg.F(Prepare, environment, name), + mg.F(Prepare, environment, service), ) cfg, err := config.NewConfig(environment) @@ -47,23 +48,11 @@ func Deploy(environment, name string) error { return fmt.Errorf("unable to load the configuration; %w", err) } - os.Setenv("DOCKER_HOST", cfg.Docker.Host) - - command := []string{ - "docker", - "compose", - "--project-directory", - fmt.Sprintf("%s/%s/compose", internal.RootBuildDir, environment), - "up", - "-d", - "--build", + if err := deploy.Deploy(cfg.Docker.Host, environment, service, true); err != nil { + return fmt.Errorf("error deploying %q; %w", service, err) } - if name != "all" { - command = append(command, name) - } - - return sh.RunV(command[0], command[1:]...) + return nil } // Prepare prepares the service's build directory.