2019-07-02 08:05:15 +03:00
# CLI Usage
2023-07-29 12:02:46 +02:00
We recommend adding the following alias to your .bashrc file:
2021-04-03 11:44:40 -04:00
2022-03-22 20:39:45 +01:00
```bash
2022-07-24 13:26:08 +02:00
alias dep='vendor/bin/dep'
2021-11-10 23:20:32 +01:00
```
2019-07-02 08:05:15 +03:00
2023-07-29 12:02:46 +02:00
It is also recommended to install the completion script for Deployer. Completion supports:
2022-09-06 09:17:58 +02:00
2022-03-22 20:39:45 +01:00
- tasks,
- options,
- host names,
- and configs.
2023-07-29 12:02:46 +02:00
For example, on macOS run the following commands:
2019-07-02 08:05:15 +03:00
2022-03-22 20:39:45 +01:00
```bash
brew install bash-completion
dep completion bash > /usr/local/etc/bash_completion.d/deployer
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
2021-11-22 03:23:57 -05:00
## Overriding configuration options
2019-07-02 08:05:15 +03:00
For example, if your _deploy.php_ file contains this configuration:
2021-04-03 11:44:40 -04:00
```php
2019-07-02 08:05:15 +03:00
set('ssh_multiplexing', false);
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
2021-12-05 16:45:33 +00:00
And you want to enable [ssh multiplexing ](https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing ) without modifying the recipe, you can pass the `-o` option to the `dep` command:
2019-07-02 08:05:15 +03:00
2021-11-10 23:20:32 +01:00
```
2019-07-02 08:05:15 +03:00
dep deploy -o ssh_multiplexing=true
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
To override multiple config options, you can pass multiple `-o` args:
2021-11-10 23:20:32 +01:00
```
2019-07-02 08:05:15 +03:00
dep deploy -o ssh_multiplexing=true -o branch=master
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
2021-11-22 03:23:57 -05:00
## Running arbitrary commands
2021-04-03 11:44:40 -04:00
2021-12-05 16:45:33 +00:00
Run any command on one or more hosts:
2019-07-02 08:05:15 +03:00
2021-04-03 11:44:40 -04:00
```
2021-12-05 16:45:33 +00:00
dep run 'uptime -p'
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
2021-12-05 20:45:44 +00:00
## Tree command
2019-07-02 08:05:15 +03:00
2023-07-29 12:02:46 +02:00
Deployer supports [task grouping ](tasks.md#task-grouping ) and [before/after hooks ](tasks.md#addbefore ).
To visualize the task hierarchy, use the **dep tree** command.
2019-07-02 08:05:15 +03:00
2021-11-10 23:20:32 +01:00
```
2021-12-05 20:45:44 +00:00
$ dep tree deploy
The task-tree for deploy:
└── deploy
├── deploy:prepare
│ ├── deploy:info
│ ├── deploy:setup
│ ├── deploy:lock
│ ├── deploy:release
│ ├── deploy:update_code
│ ├── build // after deploy:update_code
│ ├── deploy:shared
│ └── deploy:writable
├── deploy:vendors
├── artisan:storage:link
├── artisan:config:cache
├── artisan:route:cache
├── artisan:view:cache
├── artisan:migrate
└── deploy:publish
├── deploy:symlink
├── deploy:unlock
├── deploy:cleanup
└── deploy:success
```
## Execution plan
2023-07-29 12:02:46 +02:00
Before executing tasks, Deployer needs to flatten the task tree and decide in which order it will be executing tasks
on which hosts. Use the `--plan` option to output a table with tasks/hosts:
2021-12-05 20:45:44 +00:00
```
$ dep deploy --plan all
┌──────────────────────┬──────────────────────┬──────────────────────┬──────────────────────┐
│ prod01 │ prod02 │ prod03 │ prod04 │
├──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┤
│ deploy:info │ deploy:info │ deploy:info │ deploy:info │
│ deploy:setup │ deploy:setup │ deploy:setup │ deploy:setup │
│ deploy:lock │ deploy:lock │ deploy:lock │ deploy:lock │
│ deploy:release │ deploy:release │ deploy:release │ deploy:release │
│ deploy:update_code │ deploy:update_code │ deploy:update_code │ deploy:update_code │
│ build │ build │ build │ build │
│ deploy:shared │ deploy:shared │ deploy:shared │ deploy:shared │
│ deploy:writable │ deploy:writable │ deploy:writable │ deploy:writable │
│ deploy:vendors │ deploy:vendors │ deploy:vendors │ deploy:vendors │
│ artisan:storage:link │ artisan:storage:link │ artisan:storage:link │ artisan:storage:link │
│ artisan:config:cache │ artisan:config:cache │ artisan:config:cache │ artisan:config:cache │
│ artisan:route:cache │ artisan:route:cache │ artisan:route:cache │ artisan:route:cache │
│ artisan:view:cache │ artisan:view:cache │ artisan:view:cache │ artisan:view:cache │
│ artisan:migrate │ artisan:migrate │ artisan:migrate │ artisan:migrate │
│ deploy:symlink │ - │ - │ - │
│ - │ deploy:symlink │ - │ - │
│ - │ - │ deploy:symlink │ - │
│ - │ - │ - │ deploy:symlink │
│ deploy:unlock │ deploy:unlock │ deploy:unlock │ deploy:unlock │
│ deploy:cleanup │ deploy:cleanup │ deploy:cleanup │ deploy:cleanup │
│ deploy:success │ deploy:success │ deploy:success │ deploy:success │
└──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┘
```
2022-09-06 09:17:58 +02:00
The **deploy.php** :
2021-12-05 20:45:44 +00:00
```php
host('prod[01:04]');
task('deploy:symlink')->limit(1);
2021-04-03 11:44:40 -04:00
```
2019-07-02 08:05:15 +03:00
2021-12-05 16:45:33 +00:00
## The `runLocally` working dir
2019-07-02 08:05:15 +03:00
2023-07-29 12:02:46 +02:00
By default, `runLocally()` commands are executed relative to the recipe file directory.
2021-12-05 16:45:33 +00:00
This can be overridden globally by setting an environment variable:
2019-07-02 08:05:15 +03:00
2021-11-10 23:20:32 +01:00
```
2021-09-07 10:03:01 +02:00
DEPLOYER_ROOT=. dep taskname`
```
2023-07-29 12:02:46 +02:00
Alternatively, the root directory can be overridden per command via the cwd configuration.
2021-12-05 16:45:33 +00:00
2021-09-07 10:03:01 +02:00
```php
runLocally('ls', ['cwd' => '/root/directory']);
```
2021-12-05 20:45:44 +00:00
## Play blackjack
2022-03-22 20:39:45 +01:00
> Yeah, well. I'm gonna go build my own theme park... with blackjack and hookers!
2022-09-06 09:17:58 +02:00
>
2022-03-22 20:39:45 +01:00
> In fact, forget the park!
2022-09-06 09:17:58 +02:00
>
2022-03-22 20:39:45 +01:00
> — Bender
2021-12-05 20:45:44 +00:00
```
dep blackjack
```