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

Add nvm (Node Version Manager) to PHP container tools #499

Closed
az09asdf opened this issue Feb 8, 2019 · 28 comments · Fixed by #528 or #935
Closed

Add nvm (Node Version Manager) to PHP container tools #499

az09asdf opened this issue Feb 8, 2019 · 28 comments · Fixed by #528 or #935
Assignees

Comments

@az09asdf
Copy link

az09asdf commented Feb 8, 2019

ISSUE TYPE

  • Feature request

SUMMARY

Add nvm to PHP container tools (Ubuntu 18.04 example).

install nvm script:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

install the latest LTS version:
nvm install --lts

install the latest available version of node.js:
nvm install node

Goal

It would be nice to have multiple node.js versions to select from, instead of just the latest node.js lts version.

@cytopia
Copy link
Owner

cytopia commented Feb 28, 2019

@az09asdf I will probably need a bit of support here as I am not too familiar with NodeJS and NVM.

Currently I am already installing a couple of NodeJS packages via (yarn, which could also be changed back to npm). The question is how will this conflict with the above listed method of having multiple NodeJS versions available? Do I need to explicitly specify directories when installing stuff globally?

I think it is a general good idea to also have multiple NodeJS versions available, could you list a few common once, just that I get an idea here.

@cytopia cytopia self-assigned this Feb 28, 2019
@az09asdf
Copy link
Author

@cytopia

while learning some front-end frameworks, sometimes it was a requirement to have the latest node version

so, I found instruction for instaling node using nvm here, installed it on the php container, tried it and it looks good

it is realy simple to install and use

the first thing I do before installing nvm and node versions needed is to uninstall node from the php container:
sudo apt remove nodejs npm

and then as per my previous post

if your project needs version 11.10.0 (which you previously installed using nvm install 11.10.0) you need this:
nvm use 11.10.0

and that's it: from now on you have that version on your php container

devilbox@php-7.2.15 in /shared/httpd/react-redux/code $ nvm current
v11.10.0
devilbox@php-7.2.15 in /shared/httpd/react-redux/code $ nvm ls
v10.15.1
-> v11.10.0
default -> node (-> v11.10.0)
node -> stable (-> v11.10.0) (default)
stable -> 11.10 (-> v11.10.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.15.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.16.0 (-> N/A)
lts/carbon -> v8.15.0 (-> N/A)
lts/dubnium -> v10.15.1
devilbox@php-7.2.15 in /shared/httpd/react-redux/code $ nvm use 10.15.1
Now using node v10.15.1 (npm v6.4.1)
devilbox@php-7.2.15 in /shared/httpd/react-redux/code $ nvm use 11.10.0
Now using node v11.10.0 (npm v6.7.0)
devilbox@php-7.2.15 in /shared/httpd/react-redux/code $

all juggling with installed node versions is handled by nvm

the only thing which is changed is that on the devilbox home page now we have:
node not installed
npm not installed

I hope this will be of some help

keep up the good work

@cytopia
Copy link
Owner

cytopia commented Mar 1, 2019

@az09asdf Thanks for the explanation. When uninstalling nodejs and npm, what will happen to the already globally installed npm packages?

@az09asdf
Copy link
Author

az09asdf commented Mar 1, 2019

@cytopia
I'm not sure, but probably not (the trouble is as it seems to get rid of them).

However, according to https://github.com/creationix/nvm#system-version-of-node it seems that removing already installed version on node (pre nvm) is not needed: you could switch to it by
nvm use system

That would mean you could just add nvm install after already installed stuff (node also) to PHP image and either leave it as it is or (better) at least install current LTS version of node (nvm install --lts).

The best course of action while creating PHP image might be as follows:

  1. do not install node
  2. install nvm
  3. install current LTS node version: it will be automatically set to default version (nvm install --lts)
  4. install all global packages you need

That way, user will have at least current LTS already installed, and if they need another node version - no problem, nvm is already installed so it is really easy to do (and how to for example transfer global packages to another version if you need them is described here).

@cytopia
Copy link
Owner

cytopia commented Mar 8, 2019

@az09asdf can you try out the branch from the PR to see if this resolves the issue: #528

cytopia added a commit that referenced this issue Mar 9, 2019
@tikoflano
Copy link

This is still needed. Would be nice to have it added.

@cytopia
Copy link
Owner

cytopia commented Jan 25, 2020

This is still needed. Would be nice to have it added.

If it is still needed, feel free to use it then ;-) It is already available since a long time. Did you miss out any updates?

$ devilbox@php-7.4.1 in /shared/httpd $ nvm --version
0.35.2

@tikoflano
Copy link

I was logging in as root and that is why the nvm command wasn't found! I'm using Devilbox (best tool ever) for developing in Visual Code and it logged in as root by default. I had to add the line "remoteUser": "devilbox" to my container's configuration file inside Visual Code in order to log in as devilbox user and have access to nvm.

Sory for the mistake and thanks for your time :)

@Luc45
Copy link

Luc45 commented Apr 28, 2020

I still get nvm: command not found, both in bash and zsh inside the container in Devilbox

@Luc45
Copy link

Luc45 commented Apr 28, 2020

I ran the nvm installer script and it's running now. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

As Cytopia said in another issue, it seems to be because nvm is registered as a bash/zsh function, rather than an actual executable available in the $path. This seems to cause some issues.

@krebbi
Copy link

krebbi commented Jul 13, 2021

when trying to change the node version I get write permission errors:

nvm install lts/*
Downloading and installing node v14.17.3...
mkdir: cannot create directory ‘/opt/nvm/.cache/bin’: Permission denied
creating directory /opt/nvm/.cache/bin/node-v14.17.3-linux-x64/files failed
Downloading https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /opt/nvm/.cache/bin/node-v14.17.3-linux-x64/node-v14.17.3-linux-x64.ta
Warning: r.xz: No such file or directory

@yfridelance
Copy link

same permission issue when trying install current lts

nvm install --lts
Installing latest LTS version.
Downloading and installing node v16.13.0...
/bin/mkdir: cannot create directory ‘/opt/nvm/.cache/bin’: Permission denied
creating directory /opt/nvm/.cache/bin/node-v16.13.0-linux-x64/files failed
Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /opt/nvm/.cache/bin/node-v16.13.0-linux-x64/node-v16.13.0-linux-x64.ta
Warning: r.xz: No such file or directory

@Lenitr
Copy link

Lenitr commented Jul 1, 2022

@krebbi @yfridelance

For anyone running into the permission issue when trying to install node versions that are not available in the nvm use X command, try running sudo chmod -R 777 /opt/nvm before you run the install.

@cytopia
Would it be possible to change the default permissions of the /opt/nvm folder in the PHP containers? So installs of new node versions are a bit easier?

@cytopia
Copy link
Owner

cytopia commented Jul 1, 2022

I actually can't reproduce it on my side:

devilbox@php-8.1.6 in /opt/nvm $ ls -lap /opt/nvm/

total 332
drwxr-xr-x 1 devilbox devilbox   4096 May 14 12:14 ./
drwxr-xr-x 1 root     root       4096 May 14 12:10 ../
drwxr-xr-x 1 devilbox devilbox   4096 May 14 12:10 alias/
drwxr-xr-x 1 devilbox devilbox   4096 Jul  1 14:54 .cache/
drwxr-xr-x 8 devilbox devilbox   4096 May 14 12:10 .git/
drwxr-xr-x 3 devilbox devilbox   4096 May 14 12:10 .github/
drwxr-xr-x 9 devilbox devilbox   4096 May 14 12:10 test/
drwxr-xr-x 1 devilbox devilbox   4096 May 14 12:10 versions/
-rw-r--r-- 1 devilbox devilbox   2299 May 14 12:10 bash_completion
-rw-r--r-- 1 devilbox devilbox   5424 May 14 12:10 CODE_OF_CONDUCT.md
-rw-r--r-- 1 devilbox devilbox   1057 May 14 12:10 CONTRIBUTING.md
-rw-r--r-- 1 devilbox devilbox   3691 May 14 12:10 Dockerfile
-rw-r--r-- 1 devilbox devilbox    140 May 14 12:10 .dockerignore
-rw-r--r-- 1 devilbox devilbox    523 May 14 12:10 .editorconfig
-rw-r--r-- 1 devilbox devilbox      9 May 14 12:10 .gitattributes
-rw-r--r-- 1 devilbox devilbox    253 May 14 12:10 .gitignore
-rw-r--r-- 1 devilbox devilbox    467 May 14 12:10 GOVERNANCE.md
-rwxr-xr-x 1 devilbox devilbox  15037 May 14 12:10 install.sh
-rw-r--r-- 1 devilbox devilbox   1113 May 14 12:10 LICENSE.md
-rw-r--r-- 1 devilbox devilbox     51 May 14 12:10 .mailmap
-rw-r--r-- 1 devilbox devilbox   5361 May 14 12:10 Makefile
-rw-r--r-- 1 devilbox devilbox     19 May 14 12:10 .npmrc
-rwxr-xr-x 1 devilbox devilbox    351 May 14 12:10 nvm-exec
-rw-r--r-- 1 devilbox devilbox 139220 May 14 12:10 nvm.sh
-rw-r--r-- 1 devilbox devilbox   2371 May 14 12:10 package.json
-rw-r--r-- 1 devilbox devilbox   2935 May 14 12:10 PROJECT_CHARTER.md
-rw-r--r-- 1 devilbox devilbox  41117 May 14 12:10 README.md
-rwxr-xr-x 1 devilbox devilbox   1235 May 14 12:10 rename_test.sh
-rw-r--r-- 1 devilbox devilbox    882 May 14 12:10 ROADMAP.md
-rw-r--r-- 1 devilbox devilbox   2950 May 14 12:10 .travis.yml
-rwxr-xr-x 1 devilbox devilbox   2410 May 14 12:10 update_test_mocks.sh

Everything is owned by devilbox user and group. Adding new node versions also works fine. How do you run into this issue?

@Lenitr
Copy link

Lenitr commented Jul 1, 2022

@cytopia to reproduce it:

  • ./shell.sh into the php container (I don't change the user, so logged in as devilbox)
  • nvm install 12 (or any other version that is not installed
  • In my case currently
nvm install 12
Downloading and installing node v12.22.12...
mkdir: cannot create directory ‘/opt/nvm/.cache/bin’: Permission denied
creating directory /opt/nvm/.cache/bin/node-v12.22.12-linux-x64/files failed
Downloading https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /opt/nvm/.cache/bin/node-v12.22.12-linux-x64/node-v12.22.12-linux-x64.
Warning: tar.xz: No such file or directory

curl: (23) Failed writing body (0 != 1112)
Binary download from https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz failed, trying source.
grep: /opt/nvm/.cache/bin/node-v12.22.12-linux-x64/node-v12.22.12-linux-x64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 4 CPU core(s)
Running with 3 threads to speed up the build
mkdir: cannot create directory ‘/opt/nvm/.cache/src’: Permission denied
creating directory /opt/nvm/.cache/src/node-v12.22.12/files failed
Downloading https://nodejs.org/dist/v12.22.12/node-v12.22.12.tar.xz...
Warning: Failed to create the file
Warning: /opt/nvm/.cache/src/node-v12.22.12/node-v12.22.12.tar.xz: No such
Warning: file or directory

curl: (23) Failed writing body (0 != 1108)
Binary download from https://nodejs.org/dist/v12.22.12/node-v12.22.12.tar.xz failed, trying source.
grep: /opt/nvm/.cache/src/node-v12.22.12/node-v12.22.12.tar.xz: No such file or directory
Provided file to checksum does not exist.

Changing the permission like I mentioned in the previous comment is what allows me to run the install though. (777 is a bit much, but it confirms the issue is somewhere with the permissions)

The first error encountered suggest the root of the issue is in the creation of a new folder, which isn't allowed.

@cytopia
Copy link
Owner

cytopia commented Jul 1, 2022

@cytopia to reproduce it:

  • ./shell.sh into the php container (I don't change the user, so logged in as devilbox)
  • nvm install 12 (or any other version that is not installed

That is exactly what I did. Everything works fine.
What PHP version are you using?

@Lenitr
Copy link

Lenitr commented Jul 1, 2022

I'm running php 8.0.7

total 300
drwxr-xr-x 1 1000 1000   4096 Jun 16  2021 ./
drwxr-xr-x 1 root root   4096 Jul  1 11:54 ../
drwxr-xr-x 3 1000 1000   4096 Jun 16  2021 alias/
drwxr-xr-x 1 1000 1000   4096 Jun 16  2021 .cache/
drwxr-xr-x 8 1000 1000   4096 Jun 16  2021 .git/
drwxr-xr-x 3 1000 1000   4096 Jun 16  2021 .github/
drwxr-xr-x 9 1000 1000   4096 Jun 16  2021 test/
drwxr-xr-x 1 1000 1000   4096 Jun 16  2021 versions/
-rw-r--r-- 1 1000 1000   2201 Jun 16  2021 bash_completion
-rw-r--r-- 1 1000 1000   5424 Jun 16  2021 CODE_OF_CONDUCT.md
-rw-r--r-- 1 1000 1000   1057 Jun 16  2021 CONTRIBUTING.md
-rw-r--r-- 1 1000 1000   3723 Jun 16  2021 Dockerfile
-rw-r--r-- 1 1000 1000    140 Jun 16  2021 .dockerignore
-rw-r--r-- 1 1000 1000    523 Jun 16  2021 .editorconfig
-rw-r--r-- 1 1000 1000      9 Jun 16  2021 .gitattributes
-rw-r--r-- 1 1000 1000    253 Jun 16  2021 .gitignore
-rwxr-xr-x 1 1000 1000  14926 Jun 16  2021 install.sh
-rw-r--r-- 1 1000 1000   1113 Jun 16  2021 LICENSE.md
-rw-r--r-- 1 1000 1000     51 Jun 16  2021 .mailmap
-rw-r--r-- 1 1000 1000   5361 Jun 16  2021 Makefile
-rw-r--r-- 1 1000 1000     19 Jun 16  2021 .npmrc
-rwxr-xr-x 1 1000 1000    344 Jun 16  2021 nvm-exec
-rw-r--r-- 1 1000 1000 134284 Jun 16  2021 nvm.sh
-rw-r--r-- 1 1000 1000   2228 Jun 16  2021 package.json
-rw-r--r-- 1 1000 1000  39200 Jun 16  2021 README.md
-rwxr-xr-x 1 1000 1000   1235 Jun 16  2021 rename_test.sh
-rw-r--r-- 1 1000 1000    882 Jun 16  2021 ROADMAP.md
-rw-r--r-- 1 1000 1000   2713 Jun 16  2021 .travis.yml
-rwxr-xr-x 1 1000 1000   2364 Jun 16  2021 update_test_mocks.sh

I see my owner is different, looks like the default Docker user.
Could it be related to the host system being different? I'm running Docker Desktop 4.9.1 on Mac OS

@krebbi
Copy link

krebbi commented Jul 1, 2022

With PHP_SERVER=8.1

Bildschirmaufnahme.2022-07-01.um.15.15.05.mov

@cytopia
Copy link
Owner

cytopia commented Jul 1, 2022

total 300
drwxr-xr-x 1 1000 1000 4096 Jun 16 2021 ./
drwxr-xr-x 1 root root 4096 Jul 1 11:54 ../
drwxr-xr-x 3 1000 1000 4096 Jun 16 2021 alias/
drwxr-xr-x 1 1000 1000 4096 Jun 16 2021 .cache/
drwxr-xr-x 8 1000 1000 4096 Jun 16 2021 .git/
drwxr-xr-x 3 1000 1000 4096 Jun 16 2021 .github/

The owner does look different.

Can you post the output from id command from your host system and from within the PHP container as devilbox user

@Lenitr
Copy link

Lenitr commented Jul 1, 2022

On my host

uid=501(MYNAME) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),701(com.apple.sharepoint.group.1),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae)

In devilbox

uid=501(devilbox) gid=20(devilbox) groups=20(devilbox)

Interestingly, @krebbi seems to be on Mac OS too, wonder if that's causing the difference here

@cytopia
Copy link
Owner

cytopia commented Jul 1, 2022

OK, got it. Afaik the entrypoint script is not taking care about /opt/nvm permissions. Will have to fix it, so that it chowns this directory to the correct uid and gid

@Lenitr
Copy link

Lenitr commented Jul 1, 2022

@cytopia You're awesome, thanks a bunch!

@cytopia
Copy link
Owner

cytopia commented Jul 1, 2022

The build will take quite a lot of hours though: devilbox/docker-php-fpm#243

@cytopia
Copy link
Owner

cytopia commented Jul 3, 2022

Changing ownership during startup takes >5min, so I am changing file system permission during build time and make them wide open. Kinda dirty, but I don't see a better way.

@cytopia
Copy link
Owner

cytopia commented Jul 4, 2022

PR went through, now need to wait for the tagged build: https://github.com/devilbox/docker-php-fpm/releases/tag/0.141

@Lenitr
Copy link

Lenitr commented Jul 6, 2022

Just FYI, did a test on my Linux machine, there was still and older PHP container there. On the Linux host this problem didn't occur at all it seems, so that explains why for some people it occurred and for others didn't.
(both host and container do have uid 1000 here so that's probably why).

Thanks for fixing the issue for the other hosts.

@cytopia
Copy link
Owner

cytopia commented Jul 6, 2022

On the Linux host this problem didn't occur at all

Reason is that by default the first user being created on Linux gets uid 1000 and gid 1000 (it increments with additional users). This is also the default uid/gid used inside the PHP container.

@cytopia
Copy link
Owner

cytopia commented Dec 1, 2022

Reopened as not yet released for Devilbox

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

Successfully merging a pull request may close this issue.

7 participants