#2 - Replace NVM with NodeSource, install global npm tools
Switched from NVM to NodeSource for Node.js installation, added global npm tools (yarn, patch-package) for streamlined package management.
This commit is contained in:
parent
711d246fc3
commit
6501875d17
1 changed files with 18 additions and 23 deletions
41
Dockerfile
41
Dockerfile
|
@ -32,6 +32,24 @@ RUN apt-get update && \
|
|||
# Clean up apt cache to reduce image size
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Install Node.js from the official NodeSource repository (no NVM)
|
||||
# -------------------------------------------------------------------
|
||||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key \
|
||||
| gpg --dearmor -o /usr/share/keyrings/nodesource.gpg && \
|
||||
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] \
|
||||
https://deb.nodesource.com/node_${ARG_NODE_MAJOR}.x nodistro main" \
|
||||
> /etc/apt/sources.list.d/nodesource.list && \
|
||||
apt-get update && \
|
||||
apt-get install -y nodejs && \
|
||||
# optional: verify installation
|
||||
node --version && npm --version \
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Global npm tools
|
||||
# -------------------------------------------------------------------
|
||||
RUN npm i -g yarn patch-package
|
||||
|
||||
# User setup and security configuration
|
||||
# Create non-root user 'coder' with sudo privileges
|
||||
RUN useradd -m -s /bin/bash -G sudo coder && \
|
||||
|
@ -51,32 +69,9 @@ RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/
|
|||
# Switch to non-root user
|
||||
USER coder
|
||||
|
||||
# Configure bash environment
|
||||
ENV BASH_ENV /home/coder/.bash_env
|
||||
RUN touch "${BASH_ENV}" && \
|
||||
echo '. "${BASH_ENV}"' >> ~/.bashrc
|
||||
|
||||
# Set up global gitignore
|
||||
RUN curl -sL ${GITIGNORE_URL} -o /home/coder/.gitignore && \
|
||||
git config --global core.excludesfile /home/coder/.gitignore
|
||||
|
||||
# Install Node.js using NVM
|
||||
# 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 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"
|
||||
|
||||
|
||||
# Install Firebase CLI
|
||||
RUN curl -sL firebase.tools | bash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue