From 5dd6ab8ee6d5d36053dca809307567689ed12aeb Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Mon, 28 Aug 2023 15:14:36 +0100 Subject: [PATCH] feat(mage): add a target to stop services --- magefiles/stop.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 magefiles/stop.go diff --git a/magefiles/stop.go b/magefiles/stop.go new file mode 100644 index 0000000..49ee4f0 --- /dev/null +++ b/magefiles/stop.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "os" + + "github.com/magefile/mage/sh" +) + +func Stop(environment, service 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), + "stop", + service, + } + + return sh.Run(command[0], command[1:]...) +}