deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Overriding the shell of the localhost doesn't work

Open guvra opened this issue 2 years ago • 5 comments
trafficstars

Context

  • Deployer version: 7.0.2
  • Deployment OS: Alpine Linux

Description

The function runLocally depends on bash to run the command. Bash is not installed on Alpine Linux.

I tried to override the default shell with the following code:

localhost()
    ->setShell('sh -s');

But it doesn't work, the function runLocally still tries to use bash.

Example

deploy.php example:

<?php
namespace Deployer;

require 'recipe/common.php';

localhost()
    ->setShell('sh -s');

host('prod')
    ->setHostname('prod_hostname')
    ->setRemoteUser('myuser')
    ->setDeployPath('/var/www/html');

task('test:runLocally', function () {
    runLocally('echo test');
});

Command:

dep test:runLocally prod -v

Output:

task test:runLocally
[localhost] run echo test
[localhost] sh: bash: not found

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

guvra avatar Jan 05 '23 10:01 guvra

Additional note: using the 2nd arg of the runLocally function is not possible, because the core recipe of php deployer also uses this function, without specifying the argument.

guvra avatar Jan 05 '23 10:01 guvra

I think it's not possible to change the shell only for the runLocally command at the moment, because the ProcessRunner is getting that config from the target host config: https://github.com/deployphp/deployer/blob/ec2ebfc537e850c8ac390ad10a5b248ddf686856/src/Component/ProcessRunner/ProcessRunner.php#L63

Should work to change the setting on host('prod') I guess

UlrichThomasGabor avatar Jan 05 '23 13:01 UlrichThomasGabor

Should work to change the setting on host('prod') I guess

It only works if both the local and remote hosts use the same shell though.

I could install the bash package before deploying as a workaround.

guvra avatar Jan 05 '23 14:01 guvra

I think we need some config to add. Maybe local_shell?

antonmedv avatar Jan 06 '23 10:01 antonmedv

local_shell would be great.

https://github.com/deployphp/deployer/blob/master/src/Deployer.php#L121-L126 might be a spot to use a new config

ulrichmathes avatar Apr 26 '24 08:04 ulrichmathes