-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (72 loc) · 1.93 KB
/
main.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"context"
"os"
"sync"
"time"
"github.com/jrcasso/tugboat/providers/github"
"github.com/jrcasso/tugboat/providers/kubernetes"
"github.com/jrcasso/tugboat/tugboat"
log "github.com/sirupsen/logrus"
)
const SERVICE_DIR = "services"
func main() {
start := time.Now()
initializeLogging()
var wg sync.WaitGroup
services := tugboat.LoadServices(SERVICE_DIR)
ctx := context.Background()
plans := [][]tugboat.ExecutionPlan{}
githubClient := github.CreateClient(ctx)
k8sClient := kubernetes.CreateClient()
// Make this allocation dynamic based out of LoadServices
providers := []tugboat.Provider{
kubernetes.KubernetesProvider{
Client: k8sClient,
Context: &ctx,
},
github.GithubProvider{
Client: &githubClient,
Context: &ctx,
},
}
for _, provider := range providers {
wg.Add(1)
go func(provider tugboat.Provider, service []tugboat.Service) {
plan := provider.Plan(services, &wg)
log.Infof("Generated execution plan: %+v", plan)
plans = append(plans, plan)
}(provider, services)
}
log.Debugf("Waiting for execution planning to complete...")
wg.Wait()
log.Debugf("Planning completed!")
for _, plan := range plans {
wg.Add(1)
go tugboat.Execute(plan, &wg)
}
log.Debugf("Waiting for plan execution to complete...")
wg.Wait()
log.Debugf("Plan execution completed!")
// Cleanup
for _, provider := range providers {
for _, service := range services {
wg.Add(1)
go func(provider tugboat.Provider, service tugboat.Service) {
defer wg.Done()
log.Infof("Cleaning up %v", service.Name)
provider.Delete(service)
}(provider, service)
}
}
log.Debugf("Waiting for cleanup to complete...")
wg.Wait()
log.Debugf("Cleanup completed!")
duration := time.Since(start)
log.Debugf("Execution took %v seconds", duration)
}
func initializeLogging() {
// TODO: Implement dynamic log level, output, and format switches
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stdout)
}