Introduction
Laravel Envoy is a tool for executing common tasks you run on your remote servers. Using Blade style syntax, you can easily set up tasks for deployment, Artisan commands, and more.Currently, Envoy only supports the Mac and Linux operating systems. However, Windows support is achievable using WSL2.
Installation
First, install Envoy into your project using the Composer package manager:vendor/bin directory:
Writing Tasks
Defining Tasks
Tasks are the basic building block of Envoy. Tasks define the shell commands that should execute on your remote servers when the task is invoked. All of your Envoy tasks should be defined in anEnvoy.blade.php file at the root of your application.
@servers is defined at the top of the file, allowing you to reference these servers via the on option of your task declarations. The @servers declaration should always be placed on a single line.
Local Tasks
You can force a script to run on your local computer by specifying the server’s IP address as127.0.0.1:
Importing Envoy Tasks
Using the@import directive, you may import other Envoy files so their stories and tasks are added to yours.
Multiple Servers
Envoy allows you to easily run a task across multiple servers. First, add additional servers to your@servers declaration. Once you have defined your additional servers you may list each of them in the task’s on array:
Parallel Execution
By default, tasks will be executed on each server serially. If you would like to run a task across multiple servers in parallel, add theparallel option to your task declaration:
Setup
Sometimes, you may need to execute arbitrary PHP code before running your Envoy tasks. You may use the@setup directive:
@include directive at the top of your Envoy.blade.php file:
Variables
If needed, you may pass arguments to Envoy tasks by specifying them on the command line when invoking Envoy:if statements and loops:
Stories
Stories group a set of tasks under a single, convenient name.Hooks
When tasks and stories run, a number of hooks are executed. The hook types supported by Envoy are@before, @after, @error, @success, and @finished. All of the code in these hooks is interpreted as PHP and executed locally, not on the remote servers your tasks interact with.
@finished hooks receive the status code of the completed task, which may be null or an integer greater than or equal to 0.
Running Tasks
To run a task or story that is defined in your application’sEnvoy.blade.php file, execute Envoy’s run command:
Confirming Task Execution
If you would like to be prompted for confirmation before running a given task on your servers, add theconfirm directive to your task declaration. This option is particularly useful for destructive operations:
Notifications
Slack
Envoy supports sending notifications to Slack after each task is executed. The@slack directive accepts a Slack hook URL and a channel / user name.
@slack directive:
Discord
Telegram
Microsoft Teams
The@teams directive accepts a Teams webhook (required), a message, a theme color (success, info, warning, error), and an optional array of options.