-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
deploy_jobspecs_cmd.go
66 lines (54 loc) · 1.56 KB
/
deploy_jobspecs_cmd.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
package src
import (
"bytes"
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli"
helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
)
type deployJobSpecs struct {
}
func NewDeployJobSpecsCommand() *deployJobSpecs {
return &deployJobSpecs{}
}
func (g *deployJobSpecs) Name() string {
return "deploy-jobspecs"
}
func (g *deployJobSpecs) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError)
nodesFile := fs.String("nodes", "", "a file containing nodes urls, logins and passwords")
if err := fs.Parse(args); err != nil || nodesFile == nil || *nodesFile == "" {
fs.Usage()
os.Exit(1)
}
nodes := mustReadNodesList(*nodesFile)
for _, n := range nodes {
output := &bytes.Buffer{}
client, app := newApp(n, output)
fmt.Println("Logging in:", n.url)
loginFs := flag.NewFlagSet("test", flag.ContinueOnError)
loginFs.Bool("bypass-version-check", true, "")
loginCtx := cli.NewContext(app, loginFs, nil)
err := client.RemoteLogin(loginCtx)
helpers.PanicErr(err)
output.Reset()
tomlPath := filepath.Join(artefactsDir, n.url.Host+".toml")
tomlPath, err = filepath.Abs(tomlPath)
if err != nil {
helpers.PanicErr(err)
}
fmt.Println("Deploying jobspec:", tomlPath)
if _, err = os.Stat(tomlPath); err != nil {
helpers.PanicErr(errors.New("toml file does not exist"))
}
fileFs := flag.NewFlagSet("test", flag.ExitOnError)
err = fileFs.Parse([]string{tomlPath})
helpers.PanicErr(err)
err = client.CreateJob(cli.NewContext(app, fileFs, nil))
helpers.PanicErr(err)
output.Reset()
}
}