2023-11-26 07:46:10 +00:00
|
|
|
package actions
|
2023-11-25 15:52:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flow/services/internal"
|
2023-12-17 08:51:11 +00:00
|
|
|
"flow/services/internal/config"
|
2023-11-25 15:52:25 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/magefile/mage/sh"
|
|
|
|
)
|
|
|
|
|
2023-12-17 08:51:11 +00:00
|
|
|
func Deploy(environment, service string) error {
|
|
|
|
cfg, err := config.NewConfig(environment)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to load the configuration; %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := deploy(cfg.Docker.Host, environment, service, true); err != nil {
|
|
|
|
return fmt.Errorf("error deploying %q; %w", service, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func deploy(dockerHost, environment, service string, daemon bool) error {
|
2023-11-25 15:52:25 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-11-26 07:46:10 +00:00
|
|
|
if service != "all" {
|
|
|
|
command = append(command, service)
|
2023-11-25 15:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sh.RunV(command[0], command[1:]...)
|
|
|
|
}
|