Dan Anglin
ee910722cb
Add support for taking on demand backups of Code Flow. Resolves flow/services#7
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"flow/services/internal"
|
|
"flow/services/internal/actions"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
"github.com/magefile/mage/sh"
|
|
)
|
|
|
|
// Backup creates a backup of the specified service.
|
|
func Backup(environment, service string) error {
|
|
if err := actions.Backup(environment, service); err != nil {
|
|
return fmt.Errorf("error running Backup for %q; %w", service, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// 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),
|
|
)
|
|
|
|
if err := actions.Deploy(environment, service); err != nil {
|
|
return fmt.Errorf("error running Deploy for %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 Prepare for %q; %w", service, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Shutdown shuts down the Flow Platform in a given environment.
|
|
func Shutdown(environment string) error {
|
|
if err := actions.Shutdown(environment); err != nil {
|
|
return fmt.Errorf("error running Shutdown for %q; %w", environment, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Stop stops a running service within the Flow Platform.
|
|
func Stop(environment, service string) error {
|
|
if err := actions.Stop(environment, service); err != nil {
|
|
return fmt.Errorf("error running Stop for %q; %w", service, err)
|
|
}
|
|
|
|
return nil
|
|
}
|