dispatch job
This commit is contained in:
parent
afc1838eb5
commit
3fff73597f
1 changed files with 31 additions and 4 deletions
35
main.go
35
main.go
|
@ -3,9 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
//"github.com/hashicorp/nomad/api"
|
nomad "github.com/hashicorp/nomad/api"
|
||||||
//"code.gitea.io/sdk/gitea"
|
//"code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,25 +66,51 @@ type GiteaNotification struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func hook(w http.ResponseWriter, r *http.Request) {
|
func hook(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Hook only support POST requests", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
var notification GiteaNotification
|
var notification GiteaNotification
|
||||||
dec := json.NewDecoder(r.Body)
|
dec := json.NewDecoder(r.Body)
|
||||||
if err := dec.Decode(¬ification); err != nil {
|
if err := dec.Decode(¬ification); err != nil {
|
||||||
log.Fatal("Unable to unmarshal gitea notification")
|
http.Error(w, "Can't parse your request JSON", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta := map[string]string{
|
||||||
|
"REPO_URL": "https://git.deuxfleurs.fr/quentin/albatros.git",
|
||||||
|
"COMMIT": "9fc771827e94e89e28107a0a13ec8c11b6f740b8",
|
||||||
|
"BRANCH": "poc/nomad-ci",
|
||||||
|
}
|
||||||
|
|
||||||
|
jobs := NomadClient.Jobs()
|
||||||
|
jobs.Dispatch("builder", meta, []byte{}, "test", &nomad.WriteOptions{})
|
||||||
|
|
||||||
fmt.Println(notification.CompareUrl)
|
fmt.Println(notification.CompareUrl)
|
||||||
|
io.WriteString(w, "ok")
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(w http.ResponseWriter, r *http.Request) {
|
func build(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var NomadClient *nomad.Client
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("albatros")
|
var err error
|
||||||
|
nomadConfig := nomad.DefaultConfig()
|
||||||
|
nomadConfig.Namespace = "ci"
|
||||||
|
// @TODO read env
|
||||||
|
NomadClient, err = nomad.NewClient(nomadConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Unable to connect to Nomad, check your config and setup")
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/hook", hook)
|
http.HandleFunc("/hook", hook)
|
||||||
http.HandleFunc("/build", build)
|
http.HandleFunc("/build", build)
|
||||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
|
||||||
|
fmt.Println("albatros (:8080)")
|
||||||
|
if err = http.ListenAndServe(":8080", nil); err != nil {
|
||||||
log.Fatal("Can't start HTTP server")
|
log.Fatal("Can't start HTTP server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue