layin a base

This commit is contained in:
Iris Lightshard 2023-09-16 23:23:59 -06:00
parent 734eab3cfd
commit c28267af04
Signed by: Iris Lightshard
GPG key ID: F54E0D40695271D4
4 changed files with 71 additions and 6 deletions

14
.memnarch/test.yml Normal file
View file

@ -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

View file

@ -12,10 +12,10 @@ type Action struct {
Cmd string `yaml:"cmd"` Cmd string `yaml:"cmd"`
} `yaml:"build,omitempty"` } `yaml:"build,omitempty"`
Deploy struct { Deploy struct {
Hosts []string `yaml:"hosts"` Hosts map[string]string `yaml:"hosts"`
Artifacts map[string][]string `yaml:"artifacts"` Artifacts map[string][]string `yaml:"artifacts"`
Before map[string]string `yaml:"before,omitempty"` Before map[string][]string `yaml:"before,omitempty"`
After map[string]string `yaml:"after,omitempty"` After map[string][]string `yaml:"after,omitempty"`
} `yaml:"deploy,omitempty"` } `yaml:"deploy,omitempty"`
} }

17
hosts/hosts.go Normal file
View file

@ -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
}

40
main.go
View file

@ -15,6 +15,7 @@ import (
"forge.lightcrystal.systems/lightcrystal/memnarch/action" "forge.lightcrystal.systems/lightcrystal/memnarch/action"
"forge.lightcrystal.systems/lightcrystal/memnarch/webhook" "forge.lightcrystal.systems/lightcrystal/memnarch/webhook"
host "forge.lightcrystal.systems/lightcrystal/memnarch/hosts"
) )
func decode(next http.Handler) http.Handler { func decode(next http.Handler) http.Handler {
@ -87,10 +88,43 @@ func runJob(secret string, next http.Handler) http.Handler {
// build // build
buildCmd := exec.Command(a.Build.Cmd) buildCmd := exec.Command(a.Build.Cmd)
buildCmd.Dir = filepath.Join(workingDir, repo) buildCmd.Dir = filepath.Join(workingDir, repo)
buildOutput, err := buildCmd.CombinedOutput()
// pre-deploy if err != nil {
// deploy fmt.Println(buildOutput)
// post-deploy // log that build failed, with the complete output
}
// 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") AddContextValue(req, "data", "job submitted")