/
main.go
80 lines (60 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
// SPDX-License-Identifier: Apache-2.0
package main
import (
"encoding/json"
"fmt"
"os"
"time"
"github.com/go-vela/worker/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
_ "github.com/joho/godotenv/autoload"
)
// hostname stores the worker host name reported by the kernel.
var hostname string
// create an init function to set the hostname for the worker.
//
// https://golang.org/doc/effective_go.html#init
func init() {
// attempt to capture the hostname for the worker
hostname, _ = os.Hostname()
// check if a hostname is set
if len(hostname) == 0 {
// default the hostname to localhost
hostname = "localhost"
}
}
func main() {
// capture application version information
v := version.New()
// serialize the version information as pretty JSON
bytes, err := json.MarshalIndent(v, "", " ")
if err != nil {
logrus.Fatal(err)
}
// output the version information to stdout
fmt.Fprintf(os.Stdout, "%s\n", string(bytes))
app := cli.NewApp()
// Worker Information
app.Name = "vela-worker"
app.HelpName = "vela-worker"
app.Usage = "Vela build daemon designed for executing pipelines"
app.Copyright = "Copyright 2019 Target Brands, Inc. All rights reserved."
app.Authors = []*cli.Author{
{
Name: "Vela Admins",
Email: "vela@target.com",
},
}
// Worker Metadata
app.Action = run
app.Compiled = time.Now()
app.Version = v.Semantic()
// Worker Flags
app.Flags = flags()
// Worker Start
err = app.Run(os.Args)
if err != nil {
logrus.Fatal(err)
}
}