laravel / envoy Goto Github PK
View Code? Open in Web Editor NEWElegant SSH tasks for PHP.
Home Page: https://laravel.com/docs/envoy
License: MIT License
Elegant SSH tasks for PHP.
Home Page: https://laravel.com/docs/envoy
License: MIT License
I'm currently trying to setup a deployment onto remote servers.It works fine but I would like going further by using Illuminate\Foundation\Application
class to be able to inject some dependencies into @setup
Envoy directive (e.g. retrieve some config or Eloquent models). But I keep getting this error, whatever I tried.
https://nsa40.casimages.com/img/2019/07/22/190722111809435118.png
Run this script
@servers(['localhost' => '127.0.0.1'])
@include('vendor/autoload.php')
@setup
define('LARAVEL_START', microtime(true));
$app = require_once __DIR__.'/bootstrap/app.php';
dump($app->make('config'));
@endsetup
@task('foo', ['on' => 'localhost'])
ls
@endtask
Here is the file generated by Blade compiler, I don't see anything wrong on it
<?php $app = isset($app) ? $app : null; ?>
<?php $__container->servers(['localhost' => '127.0.0.1']); ?>
<?php require_once('vendor/autoload.php'); ?>
<?php
define('LARAVEL_START', microtime(true));
$app = require_once __DIR__.'/bootstrap/app.php';
dump($app->make('config'));
?>
<?php $__container->startTask('foo', ['on' => 'localhost']); ?>
ls
<?php $__container->endTask(); ?>
Any help would be greatly appreciated, thanks!
We need to have an option for sshpass support
Envoy cant access any server trought Supervisor... I have a job that create a server in DO then use envoy to connect to it and install docker. But Envoy can't connect to the server in production... What shoul I do?
This is my Supervisor configuration:
[program:queue]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/api.posit.us/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/api.posit.us/storage/logs/queue.log
it would be great if Envoy detects if running inside a Laravel project folder and use Servers provided in app/config/remote.php
demo
@servers(['web' => 'localhost'])
@php
\Blade::directive("hello", function ($message) {
echo "echo here is message from user defined direct: $message";
});
@endphp
@task("hello")
@hello
@endtask
Recently when running envoy self-update it returns a JSON exception related to the GitHub manifest:
Looking for updates...
[Herrera\Json\Exception\FileException]
file_get_contents(https://github.com/laravel/envoy/raw/master/envoy-manifest.json): failed to open stream: operation failed.
Envoy still works which means there's no real problem.
I've tried reinstalling the .phar but no fix.
Running Laravel Envoy version 1.0.13 on MAMP PRO PHP v5.4.25 (with the path to PHP set correctly). Have tried 5.5.10 too but same problem.
Like fabric, I'd like something similar to Fabric's -f to specify a file with a non-standard name
envoy -f foo/bar.blade.php run deploy
First let me just say that I'm loving Envoy so far. Great little tool.
So consider this a minor nitpick, but the filename 'Envoy.blade.php' seems overly verbose to me, and also really exposes details about the file that is of no interest - I don't need to know that it is a Blade (-like) syntax file, or even that it's PHP to be honest.
Just something like calling it '.envoy' or plain 'Envoy' or similar would be simpler, and more inline with other tools like Capistrano etc.
Just a thought :-)
is it possible to upload files to remote server with envoy?
looking around for a while, but I can't find a solution to this.
I want to execute code after specyfic task execution (like e.g after task 'push' sent message to discord. I see @after is implemented but I cant figure out how to use it. I trying something like
@task( 'push', [ 'on' => 'production' ] )
whoami
@after
@discord( 'https://discordapp.com/api/webhooks/63.....t', 'My message' )
@endafter
@endtask
Not sure if possible at all currently, but the Envoy.blade.php
file tends to get larger and larger when tasks are added and made more flexible.
I have already externalized most of the configuration and I was wondering if there was a possibility to split the tasks from that file and put them in another file.
If not currently possible, do you think it would technically be easy to add this? I may be able to work on a PR if that is not a huge one.
Thanks!
While I see there is @include
which calls require_once
... being able to do something on the lines of (taking this from LESS)
@extend("mixins")
which includes mixins.blade.php and compiles into the main file allowing generic tasks to be shared between projects easily.
Suggestion: Allow a subtask to be called from a parent task.
@story('s1', ['on' => ['localhost']])
_task_s1
common
@endstory
@task('_task_s1')
subtask
@endtask
@task('common')
echo "common";
@endtask
@task('subtask')
echo "subtask called";
@endtask
This doesnt work and results in:
$ envoy run s1
[localhost]: sh: subtask: command not found
[✗] This task did not complete successfully on one of your servers.
Blade comments {{-- Macro Task Below --}} creates the Envoy.php file but doesn't fire/execute/remove.
workaround:
// Macro Task Below //
The workaround for now is fine but figured since we are using blade why not allow the comment syntax.
Thanks,
Jose
Hi!
Thank for your work, it's awesome!
Can you help me?
When I run envoy task, while running I have errors in console.
Can I catch console errors, and stop running envoy task?
When I run a story or task the slack hooks fires a call and that all works but I only get the default message with my name and that a task has been run, but not with the name of the story or task.
I don't know if it even works for stories, but for the task it should but doesn't in my case.
@servers(['live' => 'hostname'])
@task('test', ['on' => 'live'])
echo 'TEST!'
@endtask
@finished
@slack('https://hooks.slack.com/services/XXXX', '@gertjan')
@endfinished
Instead of Gertjanroke ran the [test] task.
.
Happy to take a stab at a PR here but I wanted to confirm I wasn't missing something. Consider the case where you want to update multiple staging servers, and as part of it download a production db snapshot and restore it to staging:
@servers(['staging-servers' => ['alpha.staging.example.com', 'beta.staging.example.com'], 'staging-primary' => 'alpha.staging.example.com'])
@story('stage', [ 'on' => 'staging-servers' ])
down
pull
dependencies
restoredb
migrate
up
@endstory
Most of these task, of course, we want to run on all servers. However, we have a "restoredb" task that grabs the latest production database backup and restores it to staging, so we can work with the latest data. We obviously only want this to run one time.
I would expect that I could override the on
setting on the restoredb
task specifically:
@task('restoredb', [ 'on' => 'staging-primary' ])
...
@endtask
But that doesn't seem to work. So first, is this expected? Second, if it is expected, is there a different way we ought go about this, and is there a downside to changing behavior so it does work this way?
Can we expect Windows support? If yes, when?
This repository is only for reporting bugs or issues. If you need support, please use the forums:
Alternatively, you may use Slack (https://larachat.co/), Discord (https://discordapp.com/invite/mPZNm7A), or Stack Overflow (http://stackoverflow.com/questions/tagged/laravel).
Thanks!
So normally when I do something on the remote machine, it asks me for credentials every time I try to pull... is there any way to allow this kind of behavior using envoy?
I know it must be something small, but its telling me permission denied, remote host shut down etc.
Look at the bug in the laravel documentation. It says,
Currently, Envoy only supports the Mac and Linux operating systems
This means, Laravel Envoy doesn't work with the Windows operating system and but my team is using it with windows. I tried also. It works on windows
I came out with
@servers(['web' => '192.168.1.1'])
@task('test', ['on' => 'web'])
nohup sleep 10 > /dev/null 2>&1 &
echo $!
@Endtask
when I tested it, I didn't get the pid, my workaround ends with escaping character from echo
@servers(['web' => '192.168.1.1'])
@task('test', ['on' => 'web'])
nohup sleep 10 > /dev/null 2>&1 &
echo $!
@Endtask
For example:
If Envoy.blade.php contains:
@servers(['web' => '[email protected]'])
The following error appears:
[deploy<?php.example.com]: sh: ?php.example.com: No such file or directory
Current workaround:
@servers(['web' => 'deploy@' . 'php.example.com'])
I'm interested in develop a package that depends on Envoy, please distribute it so i can use as composer dependency.
The @if
Blade directive cannot be used within @finished
.
Write the following code
@finished
@if($env != 'local')
@slack($slack, '#myChannel', "Deployment on {$env}: {$release} complete")
@endif
echo "Envoy deployment complete.\r\n";
@endfinished
results in
PHP Parse error: syntax error, unexpected '<' in /var/www/einsteinfiv2/Envoyac3a4661d761f643c317961bc4f87ff8.php on line 269
Compiled PHP file:
<?php $_vars = get_defined_vars(); $__container->finished(function() use ($_vars) { extract($_vars);
<?php if($env != 'local'): ?>
if (! isset($task)) $task = null; Laravel\Envoy\Slack::make($slack, '#myChannel', "Deployment on {$env}: {$release} complete")->task($task)->send();
<?php endif; ?>
echo "Envoy deployment complete.\r\n";
}); ?>
I think one should be able to use Blade directive within the @finished
section
Hello!
With laravel 5.8 envoy command I deploy on remote server and I set password in command line, like:
envoy run Hostels2Deploy --lardeployer_password=111 --app_version=0.105a
and envoy file:
@setup
$server_login_user= 'lardeployer';
$lardeployer_password = isset($lardeployer_password) ? $lardeployer_password : "Not Defined";
@endsetup
@servers(['dev' => $server_login_user.':'.$lardeployer_password.'@NNN.NN.NNN.N'])
@task('clean_old_releases')
echo "Step # 81";
echo 'The password is: {{ $lardeployer_password }}';
echo 'The $server_login_user is: {{ $server_login_user }}';
echo "Step # 00 app_version ::{{ $app_version }}";
cd {{ $release_number_dir }}
# php artisan envoy:delete-old-versions Hostels2Deployed
@endtask
@macro('Hostels2Deploy',['on'=>'dev'])
clean_old_releases
@endmacro
With credentials in @servers block I expected I will not have to enter password manually, but in command line I see prompt to enter password. I output $server_login_user and $lardeployer_password vars and they have valid values.
Which is valid path ?
When executing a story directive on some remote server (CentOS 7) , each task in the story first returns to the home directory before executing the contents of the task, eg:
@story('staging', ['on' => 'staging'])
cdSiteStaging
git
migrate
composer
npmInstallAndDev
compileComponents
@endstory
@task('cdSiteStaging')
cd /var/www/website/docroot
@endtask
@task('git')
@if($branch)
git pull origin {{ $branch }}
@else
git pull origin master
@endif
@endtask
Happens on a CentOS 7 server when executing the above story, eg: envoy run staging
Our server IPs change as we scale up/down on AWS.
Ansible has a neat dynamic inventory capability that'd be nice to implement here as well.
From all the testing I've done with Envoy over the past few months, there doesn't seem to be an efficient way to make the code DRY (as in, avoid duplication). This is more concerning than it appears because envoy scripts can get very long and complicated, even for basic deployment tasks.
Here are some real use-cases I am struggling with at the moment:
Luckily, envoy accepts passing variables into it from the command line, like so:
envoy run build --env=local
envoy run build --env=staging
envoy run build --env=production
envoy run deploy --env=staging
envoy run deploy --env=production
The first 3 build for different environments, the last 2 build and deploy to the appropriate environment.
All of these use-cases involve 90% of the same set of steps (checkout repo, pick the right env file, create build, optionally deploy to the appropriate server or keep it local), except they need to do slightly different things (like use .env.local instead of .env.production) based on the variables that are passed in.
Variables passed in from the command line can be 'read' within the @ setup directive, but the problem arises in taking it a step further from there:
I am raising this again because copy-pasting and duplicating 200 lines of a task in envoy.blade.php another 3-4 times makes zero sense to me.
The ask is simple...to provide a way to do # 1 or # 2 above, so that envoy scripts can become a lot more manageable.
Since Envoy 1.6.0, PHP 7.0 is not supported anymore due to syntax at least in this file https://github.com/laravel/envoy/blob/v1.6.0/src/SSHConfigFile.php#L106 and it broke my build. I don't know which solution is the best, either put the supported PHP version in the composer file or use older syntax (or something else)?
I'm willing to make a PR with the solution you choose.
I've fixed the Envoy version to 1.5.0 to fix it but I was hopping that composer could handle it by itself if we set the supported PHP version in the composer file.
Install the latest Envoy version and run an SSH command in a PHP 7.0 environment.
It seems like this one was forgotten to be tagged for Laravel 6.
After the update today i am getting the following issue
$ ~/.composer/vendor/bin/envoy run deploy --commit="$CI_COMMIT_SHA"
Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in /home/php/.composer/vendor/laravel/envoy/src/RemoteProcessor.php on line 62 and defined in /home/php/.composer/vendor/symfony/process/Process.php on line 140
TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in /home/php/.composer/vendor/laravel/envoy/src/RemoteProcessor.php on line 62 in /home/php/.composer/vendor/symfony/process/Process.php on line 140
Is there any better way to make Envoy work with sudo other than turning off password request in visudo?
Hi,
I would simply like a way to run variations of the @setup section based on the task type. For example if I run;
envoy run install - I can check for 'install' in the @setup section and load a set of variables, error checking and so on. This 'install' would require specific parameters.
If I run;
envoy run upgrade - I can check for the 'upgrade' command and load a separate set of setup vars, or tasks. Maybe some are shared with 'install'.
After setup, their individual stories are run.
Is this possible, can it be done easily? I've tried everything, But I cannot find a way to access these.
Thank you
Hello,
It would be great to provide the phar file in the release page as for:
https://github.com/sebastianbergmann/phpunit/releases
We can't have empty lines on macro sections, it throws:
HP Notice: Undefined index: on in phar:///usr/local/bin/envoy/src/lib/TaskContainer.php on line 225
PHP Notice: Undefined index: as in phar:///usr/local/bin/envoy/src/lib/TaskContainer.php on line 203
envoy/src/lib/ConfigurationParser.php on line 64
calls phpuname
, not php_uname
Does Envoy support class based tasks?
With fabric I use classes and have utilized inheritance a fair bit. Can this be done?
http://docs.fabfile.org/en/1.8/usage/tasks.html#task-subclasses
thanks!
An example:
@before(['on' => 'dev'])
cd /home/user/webapps/project
@endbefore
This way I wouldn't need to run cd
in the beginning of each task.
I could obviously create macros, but I'd rather have this than build macros for all the simple tasks.
With the new TLS/SSL settings in PHP 5.6a2, envoy is unable to perform an update due to CN problems.
file_get_contents(): Peer certificate CN=`www.github.com' did not match expected CN=`raw.github.com'
file_get_contents(): Failed to enable crypto
I got those errors while running the file_get_contents
code in boris
after seeing that envoy was unable to self-update.
Switching to 5.5 allows it to self-update just fine. I'm just posting this here to make you aware, I'm not sure there's anything you should / could do to address it.
I don't think envoy supports a way to pass variables into tasks. In this (simplified) example, is it possible to NOT replicate 'common' for s1 and s2?
@story('s1')
_task_s1
common
@endstory
@story('s2')
_task_s2
common
@endstory
@task('_task_s1')
file=".env_local"
@endtask
@task('_task_s2')
file=".env_prod"
@endtask
@task('common')
echo "file: {{ $file }}";
#rm -rf {{ $file }}
@endtask
The above example doesnt work and results in:
$ envoy run s1
[localhost]: file:
It would be nice if you could do:
@after(['task1', 'task2'])
...
@endafter
So that the @after is executed only when those specific tasks are run.
I was trying to make a task which would pull my app source from a GitHub repository. However, I don't want to write down my SSH pass phrase in the Envoy-file, for obvious reasons.
There should be a way for my task to ask for the pass phrase and then send it to SSH.
hi
(envoy command not found)
Does this package support Linux Centos7?
Thanks!
Ability to Self-Update would be nice =]
I want to color the output from Envoy commands using Bash color codes. These codes contain semicolons.
The following failed to correctly parse the variable string containing a semicolon.
@setup
$error_msg = "\033[0;31mWarning: Some message.\033[0m\n";
@endsetup
@servers(['local' => 'localhost'])
@task('test', ['on' => 'local'])
echo {{ $error_msg }}
@endtask
The following error occurs:
[localhost]: sh: 1: 33mWarning:: not found
[✗] This task did not complete successfully on one of your servers.
To prove this is the issue, you can escape the semicolon in the variable string value to get it working:
$error_msg = "\033[0\;31mWarning: Some message.\033[0m\n";
Given that the variable string value is wrapped in quotes, it should not be necessary to escape the semicolon within the string.
When staring an Envoy task from a Laravel 5.8 app, an exception is thrown.
Dotenv\Dotenv::__construct() must be an instance of Dotenv\Loader, string given,
It seems caused by the fact that the compiled Envoy php file contains
(new \Dotenv\Dotenv(__DIR__, '.env'))->load();
It should be:
\Dotenv\Dotenv::create(__DIR__, '.env')->load();
Since version 1.6.3, servers configured with a port number will be parsed incorrectly, resulting in SSH connection errors.
For example, this configuration @servers(['myserver' => 'user@server -p 2222']) will result in a "ssh: Could not resolve hostname 'user@server -p 2222'" error.
Using the same server configuration in 1.6.2 works (see this thread)
add a port configuration to the server config
run
Envoy 1.5.0 no longer loads the user's environment by default. Before 1.5.0, all of a user's environment variables were available by default when running Envoy tasks.
For example, in 1.4.1, this task:
@task('test', ['on' => 'localhost'])
echo $HOME
@endtask
would produce this output:
[127.0.0.1]: /home/myusername
However, after upgrading to 1.5.0, this no longer works and $HOME
is no longer defined.
I'm just using $HOME
as a simple example. In my case, my deployments broke because envoy
stopped using my $PATH
variable, and my rsync
commands that use ssh keys also stopped working (it started asking me for my key's passphrase).
Based on some quick digging, it looks like the issue might have originated with commit Add ENVOY environment var to allow checking host within tasks, on line 31 of RemoteProcessor.php
.
I solved the issue for myself by rolling Envoy back to version 1.4.1.
Edit: fixed typo in code example
request feature: ability to set PORT (other than default 22) hostname:port
Temporary workaround: use /.ssh/config
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.