nvs icon indicating copy to clipboard operation
nvs copied to clipboard

[documentation] - Use of nvs inside a VsCode dev container

Open ontoneio opened this issue 3 years ago • 0 comments

Trying to use nvs to manage node versioning in my VSCode .devcontainer environment. I am running Docker Desktop and using the Remote-Containers feature to spin up a Linux development environment in VsCode.

I tried to get several iterations of this to work and got close with some configurations by inspecting the code closer as I couldn't find it documented. I'll try to be as succinct and clear as I can.

So the .devcontainer spec has several prebuilt environments , I am using one that comes with Kubernetes and Helm. There was no prebuilt template that included Node.js in that. I figured it would be an easy setup. but like everything it has not been straight forward.

Here's what's been tried thus far:

Version 1 - System Install

# .devcontainer/Dockerfile
ARG NVS_INSTALL_DIR=/usr/local
WORKDIR ${NVS_INSTALL_DIR}
RUN git clone https://github.com/jasongin/nvs ./nvs
RUN export NVS_HOME=/home/vscode/.nvs
RUN sudo -s source ./nvs/nvs.sh install

Results

This configuration yields the following results and observations:

  1. echo $NVS_HOME returns /usr/local/nvs despite running the explicit export command in the Dockerfile
  2. The nvs repo does in fact get cloned to the usr/local/nvs directory and does in both subsequent runs below.
  3. In the VsCode terminal that indicates I am in fact connected to my remote docker container and when the nvs command is invoked I receive the Select a node version prompt .
  4. None of my files located in /home/vscode/ including .zshrc,.bashrc, or .profile include any added refences to NVS_HOME
  5. Upon Selecting a version of Node I am greeted with this error
Could not create directory: /usr/local/nvs/node
EACCES: permission denied, mkdir '/usr/local/nvs/node'
Try running again with sudo:
  nvsudo

Version 2 - System Install - no shell script sourcing

# .devcontainer/Dockerfile
ARG NVS_INSTALL_DIR=/usr/local
WORKDIR ${NVS_INSTALL_DIR}
RUN git clone https://github.com/jasongin/nvs ./nvs
RUN export NVS_HOME=/home/vscode/.nvs
RUN ./nvs/nvs install

Results

This configuration yields the following results and observations: Following some guidance I found in Issue #214, I changed the script to use the nvs command instead of sourcing from the nvs.sh file.

  • All the conditions tested above 1-5 are still TRUE

Version 3 - System Install - add NVS_HOME variable to .devcontainer.json & Remove explicit export

// .devcontainer/devcontainer.json
{
	"remoteEnv": {
		"NVS_HOME": "/home/vscode/.nvs"
	},
}
# .devcontainer/Dockerfile
ARG NVS_INSTALL_DIR=/usr/local
WORKDIR ${NVS_INSTALL_DIR}
RUN git clone https://github.com/jasongin/nvs ./nvs
RUN ./nvs/nvs install

Results

This configuration yields the following results and observations: Basically I set an environment variable in my devcontainer.json file and got things partially working the way I want.

  1. echo $NVS_HOME returns /home/vscode/.nvs without the explicit export command in the Dockerfile and instead being set in the devcontainer.json file.
  2. Now when I type the nvs command I am greeted with the prompt below
Downloading bootstrap node from https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.gz
########################################################################################################################################################################## 100.0%

Followed by the Select a node version prompt once again. 3. I select the version I would like and it now succeeds in installing the correct node version but at the cost of manually having to type it in. 4. None of my terminal configuration files are modified to include NVS_HOME or nvs in any capacity. Not sure how I am able to access it from the terminal or where it's being added to the $PATH 5. echo $PATH returns below and doesn't indicate where I am getting access to the nvs command. Does this come from the temporary scripts mentioned that need to live in $HOME/.nvs ?

/home/vscode/.nvs/node/16.15.0/x64/bin:/vscode/vscode-server/bin/linux-x64/dfd34e8260c270da74b5c2d86d61aee4b6d56977/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin

CONCLUSION

Ultimately I ended up nixing this setup because it was taking too long to figure out even though I would love to use it in my development environment.

This is the code that ended up working for me.

WORKDIR /home/vscode/
RUN curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
RUN sudo apt-get install -y nodejs

However this has limitations, including not letting me specify the node version which isn't ideal. It does however instantiate a working copy of Node.js. Which I couldn't get NVS to allow me to do on container start up.

More documentation and guidance for Linux environments would be very helpful. Thanks!

ontoneio avatar May 02 '22 23:05 ontoneio