-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
82 lines (75 loc) · 1.5 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 (
"github.com/fortress-shell/agent/parser"
"github.com/fortress-shell/agent/worker"
"golang.org/x/crypto/ssh"
"log"
"os"
)
const (
SUCCESS_STATUS = iota
FAILURE_STATUS
TIMEOUT_STATUS
STOP_STATUS
FORTRESS_ERROR_STATUS
)
func main() {
config := worker.DefaultConfig()
payload, err := parser.NewPayloadFromFilePath(config.PayloadPath)
if err != nil {
log.Println(err)
os.Exit(FORTRESS_ERROR_STATUS)
}
tasks := parser.GenerateSteps(payload)
app, err := worker.NewWorker(config)
if err != nil {
log.Println(err)
os.Exit(FORTRESS_ERROR_STATUS)
}
// TODO: refactoring using multisteps
for _, task := range tasks.Checkout {
err := task.Run(app)
if err != nil {
app.ExitCode = FORTRESS_ERROR_STATUS
goto finish
}
select {
case <-app.Stop:
app.ExitCode = STOP_STATUS
goto finish
case <-app.Timeout:
app.ExitCode = TIMEOUT_STATUS
goto finish
default:
}
}
for _, task := range tasks.OverrideBuild {
err := task.Run(app)
if err != nil {
switch t := err.(type) {
default:
log.Println(t)
app.ExitCode = FORTRESS_ERROR_STATUS
goto finish
case *ssh.ExitError:
log.Println("Exit Status:", t.Waitmsg.ExitStatus())
app.ExitCode = FAILURE_STATUS
goto finish
}
}
select {
case <-app.Stop:
app.ExitCode = STOP_STATUS
goto finish
case <-app.Timeout:
app.ExitCode = TIMEOUT_STATUS
goto finish
default:
}
}
finish:
app.SSHClient.Close()
app.LibVirt.Close()
app.Logger.Writer.Close()
os.Exit(app.ExitCode)
}