Yarn: is there a way to run yarn using ssh remote command?

Created on 24 Jul 2018  路  2Comments  路  Source: yarnpkg/yarn

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.

triaged

Most helpful comment

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=:/usr/bin:/bin; yarn run build')

All 2 comments

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=:/usr/bin:/bin; yarn run build')

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

torifat picture torifat  路  3Comments

danez picture danez  路  3Comments

sebmck picture sebmck  路  3Comments

davidmaxwaterman picture davidmaxwaterman  路  3Comments

Ambroos picture Ambroos  路  3Comments