lando / platformsh

The Official Platform.sh Lando Plugin
https://docs.lando.dev/platformsh
GNU General Public License v3.0
6 stars 4 forks source link

`node` installed via `nvm` in the platform.sh build hook is not available via Lando tooling #33

Closed thasmo closed 2 years ago

thasmo commented 3 years ago

In the platform.sh build hook nvm gets installed, sets up the desired node version defined in .nvmrc and also defines it as the system's default node version.

Running node -v within the service/container works fine and returns v10.23.1, but when running lando node -v via Lando tooling, the actual node version is not the one which was set using nvm and returns v6.17.1. It seems the platform.sh build hook and the Lando tooling commands are executed with different users.

Is there anything I can do to get the desired node version running via Lando tooling while setting it up using the platform.sh build hook?

.platform.app.yaml

hooks:
    build: |
        if [ -s .nvmrc ]; then
            unset NPM_CONFIG_PREFIX
            curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | dash
            export NVM_DIR="$HOME/.nvm"
            [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
            nvm install --default --latest-npm --no-progress
        fi

.lando.yml

tooling:
    node:
        service: app
        description: Runs node commands
pirog commented 3 years ago

@thasmo i can replicate this, also looks like this is probably address in lando/lando#2826 so ill check that out

thasmo commented 3 years ago

@pirog Seems the version is now correct but there're still some weird behaviors I encountered.

lando ssh -c "node -v"

nvm
/bin/sh: 1: /usr/share/lando/bin/lando: not found

should print v12.20.1.

lando ssh -c "npm -v"

nvm
7.5.2

should print 7.5.2.

lando ssh -c "nvm -v"

nvm
/bin/sh: 1: nvm: not found

should print 0.37.2.

It seems any of those commands prepends a line with nvm to the output, even the ones not related to nvm/node.

lando ssh -c "php -v"

nvm
PHP 7.4.11 (cli) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies

It also gets printed after executing lando ssh.

I guess nvm configured itself during installation and somehow prints the string everytime the configuration for a new login session is read/executed; but I can't find where it does that. Maybe it's still somehow connected to how lando executes the SSH commands.

xaqrox commented 3 years ago

Just wanted to add that I am also having this issue and have not been able to track it down either. https://devwithlando.slack.com/archives/C2XBSHX8R/p1612461534165500

pirog commented 3 years ago

@thasmo and @xaqrox circling back around to this i think we are going to revert this change since it produces some weird behavior. Looking at https://docs.platform.sh/languages/nodejs/nvm.html it seems like its a better bet to either