forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
167 lines (154 loc) · 5.12 KB
/
main.go
File metadata and controls
167 lines (154 loc) · 5.12 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import (
"context"
"fmt"
"os"
"github.com/sourcegraph/log"
"github.com/urfave/cli/v2"
"github.com/sourcegraph/sourcegraph/cmd/executor/internal/config"
"github.com/sourcegraph/sourcegraph/cmd/executor/internal/run"
"github.com/sourcegraph/sourcegraph/cmd/executor/internal/util"
"github.com/sourcegraph/sourcegraph/internal/env"
"github.com/sourcegraph/sourcegraph/internal/hostname"
"github.com/sourcegraph/sourcegraph/internal/logging"
"github.com/sourcegraph/sourcegraph/internal/sanitycheck"
"github.com/sourcegraph/sourcegraph/internal/version"
)
func main() {
sanitycheck.Pass()
cfg := &config.Config{}
cfg.Load()
env.Lock()
logging.Init() //nolint:staticcheck // Deprecated, but logs unmigrated to sourcegraph/log look really bad without this.
liblog := log.Init(log.Resource{
Name: env.MyName,
Version: version.Version(),
InstanceID: hostname.Get(),
})
defer liblog.Sync()
logger := log.Scoped("executor")
runner := &util.RealCmdRunner{}
makeActionHandler := func(handler func(cliCtx *cli.Context, runner util.CmdRunner, logger log.Logger, config *config.Config) error) func(*cli.Context) error {
return func(ctx *cli.Context) error {
return handler(ctx, runner, logger, cfg)
}
}
app := &cli.App{
Version: version.Version(),
// TODO: More info, link to docs, some inline documentation etc.
Description: "The Sourcegraph untrusted jobs runner. See https://sourcegraph.com/docs/admin/executors to learn more about setup, how it works and how to configure features that depend on it.",
Name: "executor",
Usage: "The Sourcegraph untrusted jobs runner.",
DefaultCommand: "run",
CommandNotFound: func(ctx *cli.Context, s string) {
fmt.Printf("Unknown command %s. Use %s help to learn more.\n", s, ctx.App.HelpName)
os.Exit(1)
},
Commands: []*cli.Command{
{
Name: "run",
Usage: "Runs the executor. Connects to the job queue and processes jobs.",
// Also show the env vars supported.
CustomHelpTemplate: cli.CommandHelpTemplate + env.HelpString(),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verify",
Usage: "Run validation checks to make sure the environment is set up correctly before starting to dequeue jobs.",
Required: false,
},
},
Action: makeActionHandler(run.Run),
},
{
Name: "validate",
Usage: "Validate the environment is set up correctly.",
Action: makeActionHandler(run.Validate),
},
{
Name: "install",
Usage: "Install components required to run executors.",
Subcommands: []*cli.Command{
{
Name: "ignite",
Usage: "Installs ignite required for executor VMs. Firecracker only.",
Flags: []cli.Flag{
&cli.PathFlag{
Name: "bin-dir",
Usage: "Set the bin directory used to install ignite to. Must be in the PATH.",
DefaultText: "/usr/local/bin",
Required: false,
},
},
Action: makeActionHandler(run.InstallIgnite),
},
{
Name: "image",
Usage: "Ensures required runtime images are pulled and imported properly. Firecracker only.",
Action: makeActionHandler(run.InstallImage),
},
{
Name: "cni",
Usage: "Installs CNI plugins required for executor VMs. Firecracker only.",
Action: makeActionHandler(run.InstallCNI),
},
{
Name: "src-cli",
Usage: "Installs src-cli at a supported version.",
Flags: []cli.Flag{
&cli.PathFlag{
Name: "bin-dir",
Usage: "Set the bin directory used to install src-cli to. Must be in the PATH.",
DefaultText: "/usr/local/bin",
Required: false,
},
},
Action: makeActionHandler(run.InstallSrc),
},
{
Name: "iptables-rules",
Usage: "Installs iptables rules required for maximum isolation of executor VMs. Firecracker only.",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "recreate-chain",
Usage: "Force recreate the CNI_ADMIN iptables chain.",
Required: false,
},
},
Action: makeActionHandler(run.InstallIPTablesRules),
},
{
Name: "all",
Usage: "Runs all installers listed above.",
Action: makeActionHandler(run.InstallAll),
},
},
},
{
Name: "test-vm",
Usage: "Spawns a test VM with the parameters configured through the environment and prints a command to connect to it.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Usage: "Provide a repo name to clone the repository at HEAD into the VM. Optional.",
Required: false,
},
&cli.StringFlag{
Name: "revision",
Usage: "Provide a revision to check out when using --repo. Required when using --repo.",
Required: false,
},
&cli.BoolFlag{
Name: "name-only",
Usage: "Only print the vm name on stdout. Can be used to call ignite attach programmatically.",
Required: false,
},
},
Action: makeActionHandler(run.TestVM),
},
},
}
if err := app.RunContext(context.Background(), os.Args); err != nil {
println(err.Error())
os.Exit(1)
}
}