3

When deploying to multiple servers using Laravel Envoy, how can you specify the project root per server?. The example provided in the documentation assumes that the project root is the same path for both servers.

Screenshot

Assume web-1 has project root as /var/html/www and web-2 has project root as /var/foo/bar. How can I access the different server's project root at runtime?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Richie
  • 1,398
  • 1
  • 19
  • 36
  • 1
    I wonder if you can define `@servers` as an associative array, like `@servers(['web1' => ['ip_address' => ..., 'web_root' => ...], 'web2' => [...]])`, then `cd {{ $server['web_root'] }}` in the `@task`. Note: This is speculation; I don't have any experience with `envoy`. Might be worth asking about in their Issues section. This https://github.com/laravel/envoy/issues/216 might help (seems like a similar question) – Tim Lewis Jul 15 '21 at 18:41

2 Answers2

-1

There are different ways to use Laravel Envoy for what you want to achieve. For example, based on your description, something like the following would work in your Envoy.blade.php file after running envoy run deploy.

@servers(['web-1' => '127.0.0.1', 'web-2' => '127.0.0.1'])

@setup
    function logMessage($message) {
        return "echo '\033[32m" .$message. "\033[0m';\n";
    }
@endsetup

@story('deploy')
    deploy-web-1
    deploy-web-2
@endstory

@task('deploy-web-1', ['on' => ['web-1']])
    cd /Users/Shared
    {{ logMessage(' Task complete for web-1') }}
@endtask

@task('deploy-web-2', ['on' => ['web-2']])
    cd /Users/khill
    {{ logMessage(' Task complete for web-2') }}
@endtask
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
-2

you have to try this

$webServerIps = [
'web-1' => 'xxx.xxx.xxx.xxx',
'web-2' => 'xxx.xxx.xxx.xxx',
];

@servers(array_merge($webServerIps, ['persistent' => 'xxx.xxx.xxx.xxx', 'worker' 
=> 'xxx.xxx.xxx.xxx', 'local' => '127.0.0.1']))

i hope you got your solution .

also you can follow this link for more help

Rakesh kumar Oad
  • 1,332
  • 1
  • 15
  • 24
  • You have not gotten my question well. Assume web-1 has project root as /var/html/www and web-2 has project root as /var/foo/bar. How can I access the different project roots at runtime? The link you've provided makes an assumption that project roots are similar. – Richie Jul 15 '21 at 18:24