From a8ccdaa705fb449cb3aa8bbcaa6e470b19c0b7b5 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Mon, 14 Dec 2020 14:56:34 -0500 Subject: [PATCH] Default worker's name to hostname (#196) * Default worker's name to hostname * Replaced hostname term * connected-device label in the example --- PERSISTENT-WORKERS.md | 20 +++++++++----------- internal/commands/worker/run.go | 4 +++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PERSISTENT-WORKERS.md b/PERSISTENT-WORKERS.md index 51fb6d8d..632ff0df 100644 --- a/PERSISTENT-WORKERS.md +++ b/PERSISTENT-WORKERS.md @@ -8,7 +8,7 @@ Follow the instruction in the [INSTALL.md](INSTALL.md) but note that Docker or P ## Running -The most simplest invocation looks like this: +The simplest invocation looks like this: ``` cirrus worker run --token @@ -16,17 +16,13 @@ cirrus worker run --token This will start the persistent worker that periodically poll for new tasks in the foreground mode. -By default the worker's name gets assigned semi-automatically based on the name of the current system and a counter variable. Specify `--name` to explicitly specify the worker's name: +By default, the worker's name is equal to the name of the current system. Specify `--name` to explicitly provide the worker's name: ``` cirrus worker run --token --name z390-worker ``` -Note that persistent worker's name should be unique within a poll, otherwise a registration will fail. To avoid this, use a special counter variable `%n` that gets expanded in the cloud to the worker's registration slot: - -``` -cirrus worker run --token --name "z390-worker-%n" -``` +Note that persistent worker's name should be unique within a pool. ## Configuration @@ -37,13 +33,13 @@ Example configuration: ```yaml token: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 -name: "%hostname-%n" +name: "MacMini-Slot-1" labels: - distro: debian + connected-device: iPhone12ProMax ``` -Currently configuration files support the same set of options exposed via the command-line flags, but in the future the only way to configure certain options would be using the configuration file. +Currently, configuration files support the same set of options exposed via the command-line flags, but in the future the only way to configure certain options would be using the configuration file. ## Writing tasks @@ -51,6 +47,8 @@ Here's an example of how to run a task on one of the persistent workers [registe ```yaml task: - persistent_worker: {} + persistent_worker: + labels: + os: darwin script: echo "running on-premise" ``` diff --git a/internal/commands/worker/run.go b/internal/commands/worker/run.go index 64977b07..00965a42 100644 --- a/internal/commands/worker/run.go +++ b/internal/commands/worker/run.go @@ -6,6 +6,7 @@ import ( "github.com/cirruslabs/cirrus-cli/internal/worker" "github.com/spf13/cobra" "github.com/spf13/viper" + "os" ) var ErrRun = errors.New("run failed") @@ -60,7 +61,8 @@ func NewRunCmd() *cobra.Command { cmd.PersistentFlags().StringVarP(&configPath, "file", "f", "", "configuration file path (e.g. /etc/cirrus/worker.yml)") - cmd.PersistentFlags().StringVar(&name, "name", "%hostname-%n", "worker name to use when registering in the pool") + hostname, _ := os.Hostname() + cmd.PersistentFlags().StringVar(&name, "name", hostname, "worker name to use when registering in the pool") _ = viper.BindPFlag("name", cmd.PersistentFlags().Lookup("name")) cmd.PersistentFlags().StringVar(&token, "token", "", "pool registration token")