From 711d246fc374cfbfeb94966e56c3db4beb7392dd Mon Sep 17 00:00:00 2001 From: "Guillaume \"B.B.\" Van Hemmen" <GuillaumeHemmen@noreply.git.van-hemmen.com> Date: Mon, 14 Jul 2025 18:28:45 +0200 Subject: [PATCH] #2 - Improve Dockerfile NVM setup and persist environment configuration Refined NVM setup to ensure persistence across shells, updated PATH for non-interactive shells, and optimized Node.js and package installation. --- Dockerfile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a5f91b..0f801c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,18 +61,22 @@ RUN curl -sL ${GITIGNORE_URL} -o /home/coder/.gitignore && \ git config --global core.excludesfile /home/coder/.gitignore # Install Node.js using NVM -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | PROFILE="${BASH_ENV}" bash && \ - . $BASH_ENV && \ +# IMPORTANT: Persist `nvm` and its binaries in the correct environment +ENV NVM_DIR="/home/coder/.nvm" +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash && \ + . $NVM_DIR/nvm.sh && \ nvm install ${ARG_NODE_MAJOR} && \ nvm alias default ${ARG_NODE_MAJOR} && \ - nvm use ${ARG_NODE_MAJOR} && \ - npm i -g yarn patch-package + nvm use default && \ + npm install -g yarn patch-package && \ + # Update PATH to include nvm's Node.js binaries globally + echo 'export NVM_DIR="$HOME/.nvm"' >> /home/coder/.bashrc && \ + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /home/coder/.bashrc && \ + echo 'export PATH="$NVM_DIR/versions/node/$(ls $NVM_DIR/versions/node | tail -n 1)/bin:$PATH"' >> /home/coder/.bashrc + +# Ensure the `nvm` and Node.js paths are available in non-interactive shells by adding it to ENV +ENV PATH="/home/coder/.nvm/versions/node/$(ls /home/coder/.nvm/versions/node | tail -n 1)/bin:$PATH" -# After installing nvm -ENV NVM_DIR="/home/coder/.nvm" -RUN echo 'export NVM_DIR="$HOME/.nvm"' >> /home/coder/.bash_env && \ - echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /home/coder/.bash_env && \ - echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> /home/coder/.bash_env # Install Firebase CLI RUN curl -sL firebase.tools | bash