services/internal/actions/deploy.go

47 lines
906 B
Go
Raw Permalink Normal View History

package actions
import (
"flow/services/internal"
"flow/services/internal/config"
"fmt"
"os"
"github.com/magefile/mage/sh"
)
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 {
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 service != "all" {
command = append(command, service)
}
return sh.RunV(command[0], command[1:]...)
}