Skip to content

Commit

Permalink
Default worker's name to hostname (#196)
Browse files Browse the repository at this point in the history
* Default worker's name to hostname

* Replaced hostname term

* connected-device label in the example
  • Loading branch information
fkorotkov authored Dec 14, 2020
1 parent 8abb593 commit a8ccdaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 9 additions & 11 deletions PERSISTENT-WORKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ 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 <poll registration 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 <poll registration 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 <poll registration token> --name "z390-worker-%n"
```
Note that persistent worker's name should be unique within a pool.

## Configuration

Expand All @@ -37,20 +33,22 @@ 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
Here's an example of how to run a task on one of the persistent workers [registered in the dashboard](https://cirrus-ci.com/):
```yaml
task:
persistent_worker: {}
persistent_worker:
labels:
os: darwin
script: echo "running on-premise"
```
4 changes: 3 additions & 1 deletion internal/commands/worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a8ccdaa

Please sign in to comment.