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"`
|
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
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
|
||||||
|
}
|
36
main.go
36
main.go
|
@ -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()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(buildOutput)
|
||||||
|
// 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
|
// pre-deploy
|
||||||
// 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
|
// 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")
|
||||||
|
|
Loading…
Reference in a new issue