From c28267af045fccf922a7eb484b8b6844019305ab Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Sat, 16 Sep 2023 23:23:59 -0600 Subject: [PATCH] layin a base --- .memnarch/test.yml | 14 ++++++++++++++ action/action.go | 6 +++--- hosts/hosts.go | 17 +++++++++++++++++ main.go | 40 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 .memnarch/test.yml create mode 100644 hosts/hosts.go diff --git a/.memnarch/test.yml b/.memnarch/test.yml new file mode 100644 index 0000000..0d92033 --- /dev/null +++ b/.memnarch/test.yml @@ -0,0 +1,14 @@ +build: + cmd: go build +deploy: + hosts: + - amethyst + - vajra + artifacts: + - /opt/memnarch/: + - memnarch + before: + - step1 echo this is silly + - step2 echo we are just filling steps to test the parser + after: + - step99 echo deployment successful. always a pleasure \ No newline at end of file diff --git a/action/action.go b/action/action.go index a27667a..951d9b1 100644 --- a/action/action.go +++ b/action/action.go @@ -12,10 +12,10 @@ type Action struct { Cmd string `yaml:"cmd"` } `yaml:"build,omitempty"` Deploy struct { - Hosts []string `yaml:"hosts"` + Hosts map[string]string `yaml:"hosts"` Artifacts map[string][]string `yaml:"artifacts"` - Before map[string]string `yaml:"before,omitempty"` - After map[string]string `yaml:"after,omitempty"` + Before map[string][]string `yaml:"before,omitempty"` + After map[string][]string `yaml:"after,omitempty"` } `yaml:"deploy,omitempty"` } diff --git a/hosts/hosts.go b/hosts/hosts.go new file mode 100644 index 0000000..8736444 --- /dev/null +++ b/hosts/hosts.go @@ -0,0 +1,17 @@ +package hosts + +// a host is a name and an address +// memnarch expects an SSH private key to connect to Addr to exist at MEMNARCH_HOSTS/Name + +type Host struct { + Name string + Addr string +} + +type RemoteMachine interface { + Run(...string) error +} + +func (*Host) Run(cmdArgs ...string) error { + return nil +} \ No newline at end of file diff --git a/main.go b/main.go index 68626d8..60f84ad 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "forge.lightcrystal.systems/lightcrystal/memnarch/action" "forge.lightcrystal.systems/lightcrystal/memnarch/webhook" + host "forge.lightcrystal.systems/lightcrystal/memnarch/hosts" ) func decode(next http.Handler) http.Handler { @@ -87,10 +88,43 @@ func runJob(secret string, next http.Handler) http.Handler { // build buildCmd := exec.Command(a.Build.Cmd) buildCmd.Dir = filepath.Join(workingDir, repo) + buildOutput, err := buildCmd.CombinedOutput() + + if err != nil { + fmt.Println(buildOutput) + // log that build failed, with the complete output + } - // pre-deploy - // deploy - // post-deploy + // for each host, we gotta get the key and then, thru ssh + for name, addr := range a.Deploy.Hosts { + h := host.Host{ + Name: name, + Addr: addr, + } + // pre-deploy + for _, step := range a.Deploy.Before { + err := h.Run(step...) + if err != nil { + // log error or recover + } + } + // deploy artifacts + for path, artifacts := range a.Deploy.Artifacts { + for _, a := range artifacts { + fmt.Println(path + " :: " + a) + // use rsync to copy artifact to path on host + // return an error if we get one + } + } + + // post-deploy + for _, step := range a.Deploy.After { + err := h.Run(step...) + if err != nil { + // log error or recover + } + } + } }() AddContextValue(req, "data", "job submitted")