feat(mage): shutdown an environment

Add a mage target for shutting down an entire environment.
This commit is contained in:
Dan Anglin 2023-08-28 15:23:12 +01:00
parent 5dd6ab8ee6
commit 8172a6b64d
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

29
magefiles/shutdown.go Normal file
View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/magefile/mage/sh"
)
func Shutdown(environment string) error {
os.Setenv("MAGEFILE_VERBOSE", "true")
cfg, err := 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", rootBuildDir, environment),
"down",
}
return sh.Run(command[0], command[1:]...)
}