Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davidrushton's avatar

Envoyer inspired Envoy script

The new https://envoyer.io service from Taylor looks great and something we hope to use on future apps.

In the meantime, we were inspired to create a very basic deployment script using Envoy http://laravel.com/docs/5.0/envoy which follows the same "zero-downtime" approach.

The GitHub repo is https://github.com/papertank/envoy-deploy

After setting two variables (git url and server path) and setting up the Envoy file with your SSH login, the idea is you simply run envoy run init to setup the first deployment and envoy run deploy for each subsequent deployment.

We've only tested this on a Homestead / Vagrant VM but it appears to work ok. Not sure if anyone else will use this, but would really appreciate the feedback and of course any contributions.

David.

0 likes
9 replies
michaeldyrynda's avatar

I did this just the other day and it's working nicely.

My issue is this - and it doesn't appear your solution tackles it at all @davidrushton - I want to clean up the old releases so I don't end up with hundreds of copies of the code. I've tried the following:

rm -rf `ls -dt {{ $release_dir }}/* | tail -n +6`;

What this should do is list the releases with the most recent first, then remove the 6th and oldest records.

I'm just getting en ls: /path/to/releases/*: No such file or directory.

Any help would be appreciated. I suspect the backticks are causing issues here.

1 like
noeldiaz's avatar

For those who haven't seen it, a while back Servers for Hackers had a two part series for using Envoy to do symlink deployments like the ones mentioned here:

https://serversforhackers.com/video/deploying-with-envoy-cast

https://serversforhackers.com/video/enhancing-envoy-deployment

Only mention it since there are some good tips and enhancements offered there regarding better handling of user and owner ACL permissions, more efficient git cloning by only getting the HEAD of the master branch, and others. Might be some good enhancements to add.

noeldiaz's avatar

Tested the script and it is working well. As a quick test I was able to get a cleanup routine of old releases going by adding this to the end of the "deploy" task:

cd {{ $path }};
ls -1d 20* | head -n -5 | xargs -d '\n' rm -Rf

This will sort all the release directories (ones that start with 20*), in descending order, then will keep all but the highest (most recent) 5, and then do a remove on these listed directories. So far seems to work as a starting point.

1 like
michaeldyrynda's avatar

Thanks @noeldiaz - that worked like a charm! Now I have envoy for my staging deploys and Envoyer for production. Happy days :D

davidrushton's avatar

@noeldiaz - Thanks for the heads up, I just watched @fideloper 's Servers for Hackers videos on Envoy and they are really helpful. Also thanks for the cleanup command - that was on the TODO list.

kfirba's avatar

@davidrushton Haha I was also inspired to make such a script. I actually started working on it while creating another layer of an endpoint in my application that will respond only to bitbucket, gitlab and github (based on IP check and more). Guess I don't need to make my own Envoy script now :P

Thanks for sharing!

1 like
davidrushton's avatar
davidrushton
OP
Best Answer
Level 5

Just a heads up f or anyone that used (or might use) the Envoy Deploy script at https://github.com/papertank/envoy-deploy.

I've just updated the repository to v2 based on some of the refactors i'd made on my own copy.

It's also much easier to use within a Laravel project / repository now: you just copy the Envoy.blade.php file and then put your server host and path in the .env. Readme has been updated with the details: https://github.com/papertank/envoy-deploy/blob/master/readme.md

Thanks.

1 like

Please or to participate in this conversation.