- 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.
This commit is contained in:
Guillaume "B.B." Van Hemmen 2025-07-14 18:28:45 +02:00
parent b35f03b863
commit 711d246fc3
Signed by: GuillaumeHemmen
GPG key ID: 7921E64524F7EB35

View file

@ -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