Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a way to run yarn using ssh remote command? #6146

Open
oquirozm opened this issue Jul 24, 2018 · 3 comments
Open

is there a way to run yarn using ssh remote command? #6146

oquirozm opened this issue Jul 24, 2018 · 3 comments
Assignees
Labels

Comments

@oquirozm
Copy link

Hi!

I know this is not a Yarn issue but I really don't know where else to look for help.
I'm trying to automatize a deployment process that requires running a npm script on the remote server.
What I've tried so far is to use a very simple make script to rsync my changes and ssh run the npm script using yarn (i.e. ssh user@remote:/path 'cd var/www/path; yarn run build'). Problem is, the PATH isn't loaded when trying to run a command via SSH without properly loading the interactive shell. So yarn run build throws a 'Yarn requires Node 4.7.0 or higher' error.

I tried sourcing the .bashrc and .bash_profile before running the command, tried using the -t flag with SSH too. Neither worked.

Is there a way to actually accomplish this? Does a workaround exists? I can't really think of other way to automatize running the 'yarn run build' command.

@ghost ghost assigned arcanis Jul 24, 2018
@ghost ghost added the triaged label Jul 24, 2018
@m-ramp
Copy link

m-ramp commented Jan 4, 2019

Hello there.

Had the same issue when i was implementing continuous integration.
You are right about the PATH not being loaded, so it couldn't load Node. The solution is to export PATH in the command itself.

Do this on your remote machine

  1. Export Node:
    Do a 'whereis node' to find your node installation.
    export the resulting folder you get before running yarn

My Result:
/home/admin/.nvm/versions/node/v8.9.4/bin/node

export PATH=/home/admin/.nvm/versions/node/v8.9.4/bin;

  1. Export Yarn
    Yarn would probably be not found now and will throw an error 'bash: yarn: command not found'
    Do a 'whereis yarn' to find your yarn installation.
    export the resulting folder you get before running yarn

My Result:
yarn: /usr/bin/yarn /usr/share/yarn

export PATH=/home/admin/.nvm/versions/node/v8.9.4/bin:/usr/bin;

  1. Export other Yarn dependencies
    Other dependencies that are required by Yarn wont be found now.
    I got something like this.
    /usr/bin/yarn: 2: /usr/bin/yarn: sed: not found
    /usr/bin/yarn: 3: /usr/bin/yarn: readlink: not found
    /usr/bin/yarn: 5: /usr/bin/yarn: uname: not found

Do a 'whereis' on every missing module and export their PATHs too.
'whereis sed' 'whereis readlink' 'whereis uname'

My Result:
sed: /bin/sed /usr/share/man/man1/sed.1.gz /usr/share/info/sed.info.gz
readlink: /bin/readlink /usr/share/man/man2/readlink.2.gz /usr/share/man/man1/readlink.1.gz
uname: /bin/uname /usr/share/man/man2/uname.2.gz /usr/share/man/man1/uname.1.gz

export PATH=/home/admin/.nvm/versions/node/v8.9.4/bin:/usr/bin:/bin;

TL;DR
Export PATH of required modules in the command itself.
ssh user@remote:/path 'cd var/www/path; export PATH=<path/to/node>:/usr/bin:/bin; yarn run build')

@oquirozm
Copy link
Author

oquirozm commented Jan 9, 2019

@ramprasad5394 hey, thanks a lot for the detailed explanation! I'll look into and let you know how it worked for me.

@MattiasMartens
Copy link

I find myself having this same issue with the odd additional quirk that adding Yarn to PATH does not cause the SSH shell to recognize the Yarn command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants