layin a base
This commit is contained in:
parent
734eab3cfd
commit
c28267af04
4 changed files with 71 additions and 6 deletions
14
.memnarch/test.yml
Normal file
14
.memnarch/test.yml
Normal 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
|
|
@ -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"`
|
||||
}
|
||||
|
||||
|
|
17
hosts/hosts.go
Normal file
17
hosts/hosts.go
Normal 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
40
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")
|
||||
|
|
Loading…
Reference in a new issue