Skip to content

Commit 0aaa80e

Browse files
Add default_selector and improve documentation on host labels and selection (#3247)
* Add default_selector configuration functionality * Add documentation about host labels, selectors and default_selector. * Add documentation about host labels, selectors and default_selector. --------- Co-authored-by: Anton Medvedev <anton@medv.io>
1 parent 9f88dd9 commit 0aaa80e

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

docs/UPGRADE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
```
7878
11. Replace `local()` tasks with combination of `once()` and `runLocally()` func.
7979
12. Replace `locateBinaryPath()` with `which()` func.
80-
13. Configuration property `default_stage` is not supported anymore and has been dropped.
80+
13. Replace `default_stage` with `default_selector`, and adjust the value accordingly (for example: "prod" to "stage=prod").
8181
14. Replace `onHosts()` and `onStage()` with [labels & selectors](selector.md).
8282
15. Replace `setPrivate()` with [`hidden()`](tasks.md#hidden).
8383
16. Configuration property `writable_recursive` defaults to `false`. This behaviour can be overridden with:

docs/basics.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ A **recipe** is a file containing definitions for **hosts** and **tasks**.
66

77
Deployer CLI requires two arguments to run: a **task** to run and a **selector**.
88

9+
Hosts can also be [selected via labels](hosts.md#labels), also a default host selection can be configured.
10+
911
```
1012
$ dep deploy deployer.org
1113
--- ------ ------------
@@ -54,6 +56,10 @@ task my_task
5456
$
5557
```
5658

59+
If no host is provided and no default_selector is set, Deployer will show an interactive prompt for selecting hosts.
60+
If your recipe contains only one host, Deployer will automatically choose it.
61+
To select all hosts specify `all`.
62+
5763
But where is our `whoami` command output? By default, Deployer runs with normal verbosity
5864
level and shows only the names of executed tasks. Let's increase verbosity to verbose, and
5965
rerun our task.

docs/hosts.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,63 @@ host('example.org')
5959
->setRemoteUser('deployer');
6060
```
6161

62+
## Host labels
63+
64+
Hosts can receive labels to identify a subselection of all available hosts. This is a flexible approach to manage and deploy multiple hosts.
65+
The label names and values can be chosen freely. For example, a stage name can be applied:
66+
67+
```php
68+
host('example.org')
69+
->setLabels(['stage' => 'prod'])
70+
;
71+
72+
host('staging.example.org')
73+
->setLabels(['stage' => 'staging'])
74+
;
75+
76+
```
77+
The example above can be simplified without labels, by giving the host prod and staging as name, and using setHostname(...).
78+
79+
But for for multi server setups, labels become much more powerful:
80+
81+
```php
82+
host('admin.example.org')
83+
->setLabels(['stage' => 'prod', 'role' => 'web'])
84+
;
85+
86+
host('web[1:5].example.org')
87+
->setLabels(['stage' => 'prod', 'role' => 'web'])
88+
;
89+
90+
host('db[1:2].example.org')
91+
->setLabels(['stage' => 'prod', 'role' => 'db'])
92+
;
93+
94+
host('test.example.org')
95+
->setLabels(['stage' => 'test', 'role' => 'web'])
96+
;
97+
98+
host('special.example.org')
99+
->setLabels(['role' => 'special'])
100+
;
101+
```
102+
103+
When calling `dep deploy`, you can filter the hosts to deploy by passing a select string:
104+
105+
```
106+
$ dep deploy stage=prod&role=web,role=special
107+
```
108+
109+
To check for multiple labels that have to be set on the same host, you can use the `&` operator.
110+
To add another selection, you can use `,` as a separator.
111+
112+
Also you can configure a default selection string, that is used when running 'dep deploy' without arguments.
113+
114+
```php
115+
set('default_selector', "stage=prod&role=web,role=special");
116+
```
117+
118+
62119
## Host config
63120

64121
### `alias`

src/Command/SelectCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function selectHosts(Input $input, Output $output): array
4949
if (!$output->isDecorated() && !defined('NO_ANSI')) {
5050
define('NO_ANSI', 'true');
5151
}
52-
$selector = $input->getArgument('selector');
52+
$selector = Deployer::get()->config->get('default_selector', $input->getArgument('selector'));
5353
$selectExpression = is_array($selector) ? implode(',', $selector) : $selector;
5454

5555
if (empty($selectExpression)) {

0 commit comments

Comments
 (0)