Dan Anglin
ce490db95d
Migrate all 'action' code to the new internal actions package to reduce the number of internal packages. Migrate the Bundle type to a separate package to avoid circular dependencies. Refactor code around bundle definition and download for relevant services.
98 lines
2.1 KiB
Go
98 lines
2.1 KiB
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"flow/services/internal"
|
|
"flow/services/internal/actions"
|
|
"flow/services/internal/config"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
"github.com/magefile/mage/sh"
|
|
)
|
|
|
|
// Clean cleans the workspace.
|
|
func Clean(environment string) error {
|
|
buildDir := filepath.Join(internal.RootBuildDir, environment)
|
|
|
|
objects, err := os.ReadDir(buildDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for i := range objects {
|
|
name := objects[i].Name()
|
|
|
|
if name != ".gitkeep" {
|
|
if err := sh.Rm(buildDir + "/" + name); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Deploy deploys the service(s) to the Flow Platform.
|
|
func Deploy(environment, service string) error {
|
|
mg.Deps(
|
|
mg.F(Prepare, environment, service),
|
|
)
|
|
|
|
cfg, err := config.NewConfig(environment)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load the configuration; %w", err)
|
|
}
|
|
|
|
if err := actions.Deploy(cfg.Docker.Host, environment, service, true); err != nil {
|
|
return fmt.Errorf("error deploying %q; %w", service, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Prepare prepares the service's build directory.
|
|
func Prepare(environment, service string) error {
|
|
if err := actions.Prepare(environment, service); err != nil {
|
|
return fmt.Errorf("error running preparations; %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Shutdown shuts down the Flow Platform in a given environment.
|
|
func Shutdown(environment string) error {
|
|
cfg, err := config.NewConfig(environment)
|
|
if err != nil {
|
|
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),
|
|
"down",
|
|
}
|
|
|
|
return sh.RunV(command[0], command[1:]...)
|
|
}
|
|
|
|
// Stop stops a running service within the Flow Platform.
|
|
func Stop(environment, service string) error {
|
|
cfg, err := config.NewConfig(environment)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load the configuration; %w", err)
|
|
}
|
|
|
|
if err := actions.Stop(cfg.Docker.Host, environment, service); err != nil {
|
|
return fmt.Errorf("error stopping %q; %w", service, err)
|
|
}
|
|
|
|
return nil
|
|
}
|