Skip to content

Commit 14f9e1a

Browse files
committed
Update docs
1 parent dbc3984 commit 14f9e1a

File tree

4 files changed

+289
-327
lines changed

4 files changed

+289
-327
lines changed

docs/basics.md

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
# Basics
22

3-
Deployer has two main concepts: [**hosts**](hosts.md) and [**tasks**](tasks.md).
3+
Deployer operates around two main concepts: [**hosts**](hosts.md) and [**tasks**](tasks.md). These are defined within a
4+
**recipe**, which is simply a file containing **hosts** and **tasks** definitions.
45

5-
A **recipe** is a file containing definitions for **hosts** and **tasks**.
6+
The Deployer CLI requires two arguments:
67

7-
Deployer CLI requires two arguments to run: a **task** to run and a **selector**.
8+
1. A **task** to execute.
9+
2. A **selector** to determine the hosts the task will run on.
810

9-
Hosts can also be [selected via labels](hosts.md#labels), also a default host selection can be configured.
11+
Here's an example:
1012

11-
```
13+
```sh
1214
$ dep deploy deployer.org
13-
--- ------ ------------
14-
| | |
15-
| | `--- Selector
16-
| `------------- Task
17-
`------------------ CLI
15+
------ ------------
16+
task selector
1817
```
1918

20-
Deployer uses the [selector](selector.md) to choose hosts. Next, it takes the given
21-
task, performs some preparation (described later), and executes the task on all
22-
selected hosts.
19+
Deployer uses the [selector](selector.md) to choose which hosts to execute the task on. After selecting hosts, it
20+
prepares the environment (details later) and runs the task.
2321

24-
If a selector is not specified, Deployer will ask you to choose a host from a list.
25-
If your recipe contains only one host, Deployer will automatically choose it.
26-
To select all hosts, specify a special selector: `all`.
22+
### Host Selection
2723

28-
The `dep` CLI looks for a `deploy.php` or `deploy.yaml` file in the current directory.
24+
- If no selector is specified, Deployer prompts you to choose a host.
25+
- If your recipe has only one host, it is automatically selected.
26+
- To run a task on all hosts, use the `all` selector.
2927

30-
Or a recipe can be specified explicitly via `-f` or `--file` option.
28+
By default, the `dep` CLI looks for a `deploy.php` or `deploy.yaml` file in the current directory. Alternatively, you
29+
can specify a recipe file explicitly using the `-f` or `--file` option:
3130

32-
```
31+
```sh
3332
$ dep --file=deploy.php deploy deployer.org
3433
```
3534

36-
Let's write a recipe.
35+
---
36+
37+
## Writing Your First Recipe
38+
39+
Here's an example of a simple recipe:
3740

3841
```php
39-
// We are going to use functions declared primarily in the Deployer namespace,
40-
// to simplify the recipe, we will also use the Deployer namespace. Alternatively,
41-
// you can import individual functions via "use function".
4242
namespace Deployer;
4343

4444
host('deployer.org');
@@ -48,57 +48,56 @@ task('my_task', function () {
4848
});
4949
```
5050

51-
Let's try to run our task on deployer.org.
51+
To execute this task on `deployer.org`:
5252

53-
```
53+
```sh
5454
$ dep my_task
5555
task my_task
56-
$
5756
```
5857

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-
63-
But where is our `whoami` command output? By default, Deployer runs with normal verbosity
64-
level and shows only the names of executed tasks. Let's increase verbosity to verbose, and
65-
rerun our task.
58+
### Increasing Verbosity
6659

67-
Add `-v` option to increase verbosity. Read more about [CLI usage](cli.md).
60+
By default, Deployer only shows task names. To see detailed output (e.g., the result of the `whoami` command), use the
61+
`-v` option:
6862

69-
```
63+
```sh
7064
$ dep my_task -v
7165
task my_task
7266
[deployer.org] run whoami
7367
[deployer.org] deployer
74-
$
7568
```
7669

77-
Now let's add a second host:
70+
---
71+
72+
## Working with Multiple Hosts
73+
74+
You can define multiple hosts in your recipe:
7875

7976
```php
8077
host('deployer.org');
8178
host('medv.io');
8279
```
8380

84-
How does Deployer know how to connect to a host? It uses the same `~/.ssh/config` file as
85-
the `ssh` command. Alternatively, you can specify [connection options](hosts.md) in the recipe.
81+
Deployer connects to hosts using the same `~/.ssh/config` file as the `ssh` command. Alternatively, you can
82+
specify [connection options](hosts.md) directly in the recipe.
8683

87-
Let's run `my_task` task on both hosts:
84+
Run a task on both hosts:
8885

89-
```
86+
```sh
9087
$ dep my_task -v all
9188
task my_task
9289
[deployer.org] run whoami
9390
[medv.io] run whoami
94-
[medv.io] anton
9591
[deployer.org] deployer
92+
[medv.io] anton
9693
```
9794

98-
Deployer runs a task in parallel on each host. This is why the output is mixed.
99-
We can limit it to run only on one host at a time.
95+
### Controlling Parallelism
10096

101-
```
97+
By default, tasks run in parallel on all selected hosts, which may mix the output. To limit execution to one host at a
98+
time:
99+
100+
```sh
102101
$ dep my_task -v all --limit 1
103102
task my_task
104103
[deployer.org] run whoami
@@ -107,21 +106,20 @@ task my_task
107106
[medv.io] deployer
108107
```
109108

110-
It is also possible to specify a [limit level](tasks.md#limit) for each individual task.
111-
By specifying the limit level for each task, you can control the degree of parallelism
112-
for each part of your deployment process.
109+
You can also specify a [limit level](tasks.md#limit) for individual tasks to control parallelism.
110+
111+
---
112+
113+
## Configuring Hosts
113114

114-
Each host has a configuration: a list of key-value pairs. Let's define our first
115-
configuration option for both our hosts:
115+
Each host can have a set of key-value configuration options. Here's an example:
116116

117117
```php
118-
host('deployer.org')
119-
->set('my_config', 'foo');
120-
host('medv.io')
121-
->set('my_config', 'bar');
118+
host('deployer.org')->set('my_config', 'foo');
119+
host('medv.io')->set('my_config', 'bar');
122120
```
123121

124-
In the task we can get the currently executing host using the [currentHost](api.md#currenthost) function:
122+
Access these options in a task using the [currentHost](api.md#currenthost) function:
125123

126124
```php
127125
task('my_task', function () {
@@ -130,41 +128,28 @@ task('my_task', function () {
130128
});
131129
```
132130

133-
Or with the [get](api.md#get) function:
131+
Or more concisely with the [get](api.md#get) function:
134132

135-
```diff
133+
```php
136134
task('my_task', function () {
137-
- $myConfig = currentHost()->get('my_config');
138-
+ $myConfig = get('my_config');
135+
$myConfig = get('my_config');
139136
writeln("my_config: " . $myConfig);
140137
});
141138
```
142139

143-
Or via the [parse](api.md#parse) function which replaces the `{{ ... }}` brackets
144-
and their enclosed values with the corresponding configuration option.
145-
146-
All functions (writeln, run, runLocally, cd, upload, etc) call the **parse** function
147-
internally. So you don't need to call the **parse** function by yourself.
140+
Or using brackets syntax `{{` and `}}`:
148141

149-
```diff
142+
```php
150143
task('my_task', function () {
151-
- $myConfig = get('my_config');
152-
- writeln("my_config: " . $myConfig);
153-
+ writeln("my_config: {{my_config}}");
144+
writeln("my_config: {{my_config}}");
154145
});
155146
```
156147

157-
Let's try to run our task:
148+
---
158149

159-
```
160-
$ dep my_task all
161-
task my_task
162-
[deployer.org] my_config: foo
163-
[medv.io] my_config: bar
164-
```
150+
## Global Configurations
165151

166-
Awesome! Each host configuration inherits global configuration. Let's refactor
167-
our recipe to define one global config option:
152+
Host configurations inherit global options. Here's how to set a global configuration:
168153

169154
```php
170155
set('my_config', 'global');
@@ -173,11 +158,23 @@ host('deployer.org');
173158
host('medv.io');
174159
```
175160

176-
The config option `my_config` will be equal to `global` on both hosts.
161+
Both hosts will inherit `my_config` with the value `global`. You can override these values for individual hosts as
162+
needed.
163+
164+
165+
```php
166+
set('my_config', 'global');
167+
168+
host('deployer.org');
169+
host('medv.io')->set('my_config', 'bar');
170+
```
171+
172+
---
177173

178-
Additionally, the value of a config option can be defined as a callback.
179-
This callback is executed upon its first access, and the returned result
180-
is then stored in the host configuration.
174+
## Dynamic Configurations
175+
176+
You can define dynamic configuration values using callbacks. These are evaluated the first time they are accessed, and
177+
the result is stored for subsequent use:
181178

182179
```php
183180
set('whoami', function () {
@@ -189,22 +186,18 @@ task('my_task', function () {
189186
});
190187
```
191188

192-
Let's try to run it:
189+
When executed:
193190

194-
```
191+
```sh
195192
$ dep my_task all
196193
task my_task
197194
[deployer.org] Who am I? deployer
198195
[medv.io] Who am I? anton
199196
```
200197

201-
We can use this to create a dynamic configuration which uses information from the current host.
202-
203-
Only the first call will trigger the callback execution. All subsequent checks use the previously
204-
saved value.
198+
---
205199

206-
207-
Here is an example:
200+
Dynamic configurations are cached after the first use:
208201

209202
```php
210203
set('current_date', function () {
@@ -218,10 +211,9 @@ task('my_task', function () {
218211
});
219212
```
220213

221-
If we run my_task, we will see that `date` is called only once on
222-
`{{current_date}}` access.
214+
Running this task:
223215

224-
```
216+
```sh
225217
$ dep my_task deployer.org -v
226218
task my_task
227219
[deployer.org] run date
@@ -231,15 +223,23 @@ task my_task
231223
[deployer.org] What time is it? Wed 03 Nov 2021 01:16:53 PM UTC
232224
```
233225

234-
We can override a config option via CLI option `-o` like this:
226+
---
235227

236-
```
228+
## Overriding Configurations via CLI
229+
230+
You can override configuration values using the `-o` option:
231+
232+
```sh
237233
$ dep my_task deployer.org -v -o current_date="I don't know"
238234
task my_task
239235
[deployer.org] What time is it? I don't know
240236
[deployer.org] run sleep 5
241237
[deployer.org] What time is it? I don't know
242238
```
243239

244-
Since the `current_date` config option is overridden there is no need to call the callback.
245-
So there is no 'run date'.
240+
Since `current_date` is overridden, the callback is never executed.
241+
242+
---
243+
244+
By now, you should have a solid understanding of Deployer’s basics, from defining tasks and hosts to working with
245+
configurations and dynamic values. Happy deploying!

0 commit comments

Comments
 (0)