refactor: move deploy code to internal package
Move the deploy code to an internal package in preparation for the support for multiple mage targets deploying services to the Flow Platform. Add an option to deploy a service in the foreground.
This commit is contained in:
parent
ba68c51594
commit
9d2d5f36cc
2 changed files with 39 additions and 18 deletions
32
internal/deploy/deploy.go
Normal file
32
internal/deploy/deploy.go
Normal file
|
@ -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:]...)
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flow/services/internal"
|
"flow/services/internal"
|
||||||
"flow/services/internal/config"
|
"flow/services/internal/config"
|
||||||
|
"flow/services/internal/deploy"
|
||||||
"flow/services/internal/prepare"
|
"flow/services/internal/prepare"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -36,10 +37,10 @@ func Clean(environment string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy deploys the services to the Flow Platform.
|
// Deploy deploys the service(s) to the Flow Platform.
|
||||||
func Deploy(environment, name string) error {
|
func Deploy(environment, service string) error {
|
||||||
mg.Deps(
|
mg.Deps(
|
||||||
mg.F(Prepare, environment, name),
|
mg.F(Prepare, environment, service),
|
||||||
)
|
)
|
||||||
|
|
||||||
cfg, err := config.NewConfig(environment)
|
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)
|
return fmt.Errorf("unable to load the configuration; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("DOCKER_HOST", cfg.Docker.Host)
|
if err := deploy.Deploy(cfg.Docker.Host, environment, service, true); err != nil {
|
||||||
|
return fmt.Errorf("error deploying %q; %w", service, err)
|
||||||
command := []string{
|
|
||||||
"docker",
|
|
||||||
"compose",
|
|
||||||
"--project-directory",
|
|
||||||
fmt.Sprintf("%s/%s/compose", internal.RootBuildDir, environment),
|
|
||||||
"up",
|
|
||||||
"-d",
|
|
||||||
"--build",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if name != "all" {
|
return nil
|
||||||
command = append(command, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sh.RunV(command[0], command[1:]...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare prepares the service's build directory.
|
// Prepare prepares the service's build directory.
|
||||||
|
|
Loading…
Reference in a new issue