-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func
setupClient
is unused (fromunused
)