Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: worker startup process #68

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cmd/vela-worker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ package main
import (
"github.com/go-vela/sdk-go/vela"

log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/sirupsen/logrus"
)

// helper function to setup the queue from the CLI arguments.
func setupClient(c *cli.Context) (*vela.Client, error) {
log.Debug("Creating vela client from CLI configuration")
func setupClient(s *Server) (*vela.Client, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func setupClient is unused (from unused)

logrus.Debug("creating vela client from worker configuration")

vela, err := vela.NewClient(c.String("server-addr"), nil)
vela, err := vela.NewClient(s.Address, nil)
if err != nil {
return nil, err
}
// set token for auth
vela.Authentication.SetTokenAuth(c.String("vela-secret"))
vela.Authentication.SetTokenAuth(s.Secret)

return vela, nil
}
58 changes: 0 additions & 58 deletions cmd/vela-worker/executor.go

This file was deleted.

97 changes: 97 additions & 0 deletions cmd/vela-worker/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2020 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package main

import (
"time"

"github.com/go-vela/pkg-executor/executor"
"github.com/go-vela/pkg-runtime/runtime"

"github.com/urfave/cli"
)

func flags() []cli.Flag {
f := []cli.Flag{

cli.StringFlag{
EnvVar: "WORKER_LOG_LEVEL,VELA_LOG_LEVEL,LOG_LEVEL",
Name: "log.level",
Usage: "set log level - options: (trace|debug|info|warn|error|fatal|panic)",
Value: "info",
},

// API Flags

cli.StringFlag{
EnvVar: "WORKER_API_PORT,VELA_API_PORT,API_PORT",
Name: "api.port",
Usage: "API port for the worker to listen on",
Value: ":8080",
},

// Build Flags

cli.IntFlag{
EnvVar: "WORKER_BUILD_LIMIT,VELA_BUILD_LIMIT,BUILD_LIMIT",
Name: "build.limit",
Usage: "maximum amount of builds that can run concurrently",
Value: 1,
},
cli.DurationFlag{
EnvVar: "WORKER_BUILD_TIMEOUT,VELA_BUILD_TIMEOUT,BUILD_TIMEOUT",
Name: "build.timeout",
Usage: "maximum amount of time a build can run for",
Value: 30 * time.Minute,
},

// Queue Flags

cli.StringFlag{
EnvVar: "VELA_QUEUE_DRIVER,QUEUE_DRIVER",
Name: "queue.driver",
Usage: "queue driver",
},
cli.StringFlag{
EnvVar: "VELA_QUEUE_CONFIG,QUEUE_CONFIG",
Name: "queue.config",
Usage: "queue driver configuration string",
},
cli.BoolFlag{
EnvVar: "VELA_QUEUE_CLUSTER,QUEUE_CLUSTER",
Name: "queue.cluster",
Usage: "queue client is setup for clusters",
},
// By default all builds are pushed to the "vela" route
cli.StringSliceFlag{
EnvVar: "VELA_QUEUE_ROUTES,QUEUE_ROUTES",
Name: "queue.routes",
Usage: "queue routes (channels) the worker is listening on for builds",
},

// Server Flags

cli.StringFlag{
EnvVar: "WORKER_SERVER_ADDR,VELA_SERVER_ADDR,VELA_SERVER,SERVER_ADDR",
Name: "server.addr",
Usage: "Vela server address as a fully qualified url (<scheme>://<host>)",
},
cli.StringFlag{
EnvVar: "WORKER_SERVER_SECRET,VELA_SERVER_SECRET,SERVER_SECRET",
Name: "server.secret",
Usage: "secret used for server <-> worker communication",
},
}

// Executor Flags

f = append(f, executor.Flags...)

// Runtime Flags

f = append(f, runtime.Flags...)

return f
}
105 changes: 22 additions & 83 deletions cmd/vela-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,104 +11,43 @@ import (
"github.com/go-vela/worker/version"

"github.com/sirupsen/logrus"

"github.com/urfave/cli"

_ "github.com/joho/godotenv/autoload"
)

func main() {
app := cli.NewApp()
app.Name = "vela-worker"
app.Action = server
app.Version = version.Version.String()

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "server-port",
Usage: "API port to listen on",
EnvVar: "VELA_PORT",
Value: ":8080",
},
cli.StringFlag{
EnvVar: "VELA_LOG_LEVEL,LOG_LEVEL",
Name: "log-level",
Usage: "set log level - options: (trace|debug|info|warn|error|fatal|panic)",
Value: "info",
},
cli.StringFlag{
EnvVar: "VELA_ADDR,VELA_HOST",
Name: "server-addr",
Usage: "server address as a fully qualified url (<scheme>://<host>)",
},
cli.StringFlag{
EnvVar: "VELA_SECRET",
Name: "vela-secret",
Usage: "secret used for server <-> worker communication",
},
// Worker Information

// Executor Flags
cli.StringFlag{
EnvVar: "VELA_EXECUTOR_DRIVER,EXECUTOR_DRIVER",
Name: "executor-driver",
Usage: "executor driver",
Value: "linux",
},
cli.IntFlag{
EnvVar: "VELA_EXECUTOR_THREADS,EXECUTOR_THREADS",
Name: "executor-threads",
Usage: "number of executor threads to create",
Value: 1,
},
cli.DurationFlag{
EnvVar: "VELA_EXECUTOR_TIMEOUT,EXECUTOR_TIMEOUT",
Name: "executor-timeout",
Usage: "max time an executor will run a build",
Value: 60 * time.Minute,
app.Name = "vela-worker"
app.HelpName = "vela-executor"
app.Usage = "Vela executor package for integrating with different executors"
app.Copyright = "Copyright (c) 2020 Target Brands, Inc. All rights reserved."
app.Authors = []cli.Author{
{
Name: "Vela Admins",
Email: "[email protected]",
},
}

// Queue Flags
cli.StringFlag{
EnvVar: "VELA_QUEUE_DRIVER,QUEUE_DRIVER",
Name: "queue-driver",
Usage: "queue driver",
},
cli.StringFlag{
EnvVar: "VELA_QUEUE_CONFIG,QUEUE_CONFIG",
Name: "queue-config",
Usage: "queue driver configuration string",
},
cli.BoolFlag{
EnvVar: "VELA_QUEUE_CLUSTER,QUEUE_CLUSTER",
Name: "queue-cluster",
Usage: "queue client is setup for clusters",
},
// By default all builds are pushed to the "vela" route
cli.StringSliceFlag{
EnvVar: "VELA_QUEUE_WORKER_ROUTES,QUEUE_WORKER_ROUTES",
Name: "queue-worker-routes",
Usage: "queue worker routes is configuration for routing builds",
},
// Worker Metadata

// Runtime Flags
app.Compiled = time.Now()
app.Action = run
app.Version = version.Version.String()

cli.StringFlag{
EnvVar: "VELA_RUNTIME_DRIVER,RUNTIME_DRIVER",
Name: "runtime.driver",
Usage: "name of runtime driver to use",
},
cli.StringFlag{
EnvVar: "VELA_RUNTIME_CONFIG,RUNTIME_CONFIG",
Name: "runtime.config",
Usage: "path to runtime configuration file",
},
cli.StringFlag{
EnvVar: "VELA_RUNTIME_NAMESPACE,RUNTIME_NAMESPACE",
Name: "runtime.namespace",
Usage: "name of namespace for runtime configuration (kubernetes runtime only)",
},
}
// Worker Flags

app.Flags = flags()

// set logrus to log in JSON format
logrus.SetFormatter(&logrus.JSONFormatter{})

// Worker Start

err := app.Run(os.Args)
if err != nil {
logrus.Fatal(err)
Expand Down
Loading