-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (51 loc) · 2.03 KB
/
Copy pathmain.go
File metadata and controls
64 lines (51 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"net/http"
"github.com/devclub-iitd/DeployBot/src/controllers"
"github.com/devclub-iitd/DeployBot/src/history"
"github.com/devclub-iitd/DeployBot/src/options"
"github.com/devclub-iitd/DeployBot/src/slack"
"github.com/robfig/cron"
log "github.com/sirupsen/logrus"
)
func main() {
log.Info("Initializaing server")
// Regenerate NGINX templates on restart
if repoURL, err := controllers.NginxRegenerate(); err != nil {
log.Fatalf("Could not regenerate NGINX template for repo: %s, details: %v", repoURL, err)
}
// Initialize from options
if err := options.Initialize(); err != nil {
log.Fatalf("Cannot initialize server - %v", err)
}
log.Info("Initialization of server completed")
// Slack related HTTP handlers
http.HandleFunc("/slack/commands/deploy/", slack.DeployCommandHandler)
http.HandleFunc("/slack/commands/stop/", slack.StopCommandHandler)
http.HandleFunc("/slack/commands/redeploy/", slack.RedeployCommandHandler)
http.HandleFunc("/slack/commands/logs/", slack.LogsCommandHandler)
http.HandleFunc("/slack/interactive/request/", controllers.ActionHandler)
http.HandleFunc("/slack/interactive/data-options/", options.DataOptionsHandler)
// Github New repo creation HTTP handler
http.HandleFunc("/github/repo/", controllers.RepoHandler)
// General status and history HTTP handlers
http.HandleFunc("/logs/", controllers.LogHandler)
http.HandleFunc("/status/", history.StatusHandler)
http.HandleFunc("/history/", history.Handler)
// General Health checking handlers
http.HandleFunc("/", okHandler)
http.HandleFunc("/healthz", okHandler)
c := cron.New()
c.AddFunc("@every 5m", history.BackupState)
c.AddFunc("@every 20m", options.UpdateRepos)
c.AddFunc("@every 2m", controllers.HealthCheck)
c.AddFunc("@weekly", controllers.CleanupDanglingImages)
c.Start()
defer c.Stop()
log.Infof("starting HTTP server on %s:%s", serverURL, port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func okHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK. Healthy!\n") // send healthy data
}