Envoy deployment tool
Writing Task
- Configuration Stories
- Multi-service mode
- Run task
- Task confirmation
- ##Message notification
- Slack
- ##
Introduction
Laravel Envoy provides a set of concise and lightweight syntax for defining daily tasks of remote servers. Blade style syntax can be used to configure deployment tasks, execute Artisan commands, etc. Currently, Envoy only supports Mac and Linux operating systems. .
Installation
First, run Composer’s
global require
command to install Envoy globally. :composer global require laravel/envoy
Since global Composer libraries can sometimes cause package version conflicts, you may want to consider using
cgr
, which is a drop-in replacement for thecomposer global require
command.cgr
The installation instructions of the library can be found found on GitHub.Make sure to put the
~/.composer/vendor/bin
directory In the PATH so that theenvoy
executable is found when running theenvoy
command in the terminal.Updating Envoy
You can also use Composer to keep your Envoy installation up to date. Using the
composer global update
command will update all globally installed Composer packages:composer global update
##Writing tasksEnvoy.blade.php
file in the root directory of your project. Here's an example to get you started:
@servers(['web' => ['user@192.168.1.1']]) @task('foo', ['on' => 'web']) ls -la @endtask
As you can see, there is a@server
You can force the script to run locally by specifying the server's IP address asarray defined at the top of the file, allowing you to
onThese servers are referenced in the options. In your
@ taskdeclaration, you should place the Bash code that should run on your server when the task executes.
127.0.0.1
:
@servers(['localhost' => '127.0.0.1'])
Configuration Sometimes, you may need to execute some PHP code before executing the Envoy task. You can use the@ setup
directive to declare variables and perform other general PHP work before performing any other tasks:
@setup $now = new DateTime(); $environment = isset($env) ? $env : "testing"; @endsetup
If you need additional PHP files before performing a task, you can do so inUse the
@include
directive at the top of the Envoy.blade.phpfile:
@include('vendor/autoload.php') @task('foo') # ... @endtask
##VariablesIf desired, you can use the command line to pass option values to the Envoy task:
envoy run deploy --branch=master
You can access options in the task through Blade's "echo" syntax. You can also use
ifstatements and loops within tasks. For example, before executing the
git pull
command, let's verify the existence of the$ branch
variable:@servers(['web' => '192.168.1.1']) @task('deploy', ['on' => 'web']) cd site @if ($branch) git pull origin {{ $branch }} @endif php artisan migrate @endtask
Stories
Stories Group a set of tasks under a convenient name, allowing you to group small, focused tasks into larger tasks. For example, the
deploy
story can run thegit
andcomposer
tasks by listing the task name in its definition:@servers(['web' => '192.168.1.1']) @story('deploy') git composer @endstory @task('git') git pull origin master @endtask @task('composer') composer install @endtask
Once the story is written , you can run it like a typical task:
envoy run deploy
##Multiple ServersEnvoy allows you to easily span Multiple servers run tasks. First, add additional servers in the@server
declaration. Each server should be assigned a unique name. After defining the other servers, list each server in the "on" array of the task:
@servers(['web-1' => '192.168.1.1', 'web-2' => '192.168.1.2']) @task('deploy', ['on' => ['web-1', 'web-2']]) cd site git pull origin {{ $branch }} php artisan migrate @endtask
Run in parallelBy default, each server will be Execute tasks serially. In other words, the task will finish running on the first server before continuing on the second server. If you want to run tasks on multiple servers in parallel, add theparallel
option to the task declaration:
@servers(['web-1' => '192.168.1.1', 'web-2' => '192.168.1.2']) @task('deploy', ['on' => ['web-1', 'web-2'], 'parallel' => true]) cd site git pull origin {{ $branch }} php artisan migrate @endtask
Run a taskTo run a task or story defined in theEnvoy.blade.php
file, execute Envoy's
runcommand, passing the The name of the quest or story. When the task runs, Envoy will run the task and display the output from the server:
envoy run task
Task ConfirmationIf you If you want to be prompted for confirmation before running a given task on the server, you should add theconfirm
directive to the task declaration. This option is particularly useful for destructive operations:
@task('deploy', ['on' => 'web', 'confirm' => true]) cd site git pull origin {{ $branch }} php artisan migrate @endtask
Message NotificationSlackEnvoy also supports sending notifications toSlack after each task is executed. @slack
The directive accepts a Slack hook URL and channel name. You can retrieve your webhook URL by creating an
Incoming WebHooksintegration in your Slack dashboard. You should pass the entire webhook URL to the
@slackdirective:
@finished @slack('webhook-url', '#bots') @endfinished
You can provide one of the following as a channel parameter:##- to the channel Send notification:
- #channel
- @user
Discord
Envoy also supports sending notifications to Discord after each task is performed.
@ discord
The directive accepts Discord hook URLs and messages. You can retrieve your webhook URL by creating a webhook inWebhook
and selecting the channel to which the webhook should be published. You should pass the entire webhook URL to the@ discord
command:@finished @discord('discord-webhook-url') @endfinished
- #channel
- ##