Created
October 15, 2024 23:59
-
-
Save f440/89b0ed9af913aac240833a3de0f8d6a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:noble AS base | |
RUN <<-EOF | |
apt-get update && | |
apt-get install -y \ | |
curl \ | |
git | |
EOF | |
############################################# | |
FROM base AS nvm | |
SHELL ["/bin/bash", "-c"] | |
# Setup nvm | |
RUN <<-EOF | |
set -x | |
export NVM_DIR="$HOME/.nvm" && ( | |
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR" | |
cd "$NVM_DIR" | |
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)` | |
) && \. "$NVM_DIR/nvm.sh" | |
nvm install v20.18.0 | |
nvm install v22.9.0 | |
EOF | |
RUN <<-EOF | |
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc | |
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc | |
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> ~/.bashrc | |
EOF | |
# Setup direnv | |
RUN curl -L -o /usr/local/bin/direnv https://github.com/direnv/direnv/releases/download/v2.35.0/direnv.linux-amd64 | |
RUN chmod a+x /usr/local/bin/direnv | |
RUN echo 'eval "$(direnv hook bash)"' >> ~/.bashrc | |
RUN <<-EOF | |
mkdir -p ~/.config/direnv/ | |
# https://github.com/direnv/direnv/wiki/Node#using-nvm | |
cat <<-'SCRIPT' > ~/.config/direnv/direnvrc | |
use_nvm() { | |
local node_version=$1 | |
nvm_sh=~/.nvm/nvm.sh | |
if [[ -e $nvm_sh ]]; then | |
source $nvm_sh | |
nvm use $node_version | |
fi | |
} | |
SCRIPT | |
EOF | |
RUN mkdir /work | |
WORKDIR /work | |
############################################# | |
FROM nvm AS test-nvm | |
SHELL ["/bin/bash", "-c"] | |
RUN <<-EOF | |
set -x | |
mkdir /work/v20-use-node | |
cd /work/v20-use-node | |
echo NODE_VERSIONS=\$HOME/.nvm/versions/node > .envrc | |
echo NODE_VERSION_PREFIX=v >> .envrc | |
echo use node >> .envrc | |
echo 20 > .node-version | |
direnv allow | |
cd - | |
mkdir /work/v20-use-nvm | |
cd /work/v20-use-nvm | |
echo use nvm 20 >> .envrc | |
direnv allow | |
cd - | |
mkdir /work/v22-use-node | |
cd /work/v22-use-node | |
echo NODE_VERSIONS=\$HOME/.nvm/versions/node > .envrc | |
echo NODE_VERSION_PREFIX=v >> .envrc | |
echo use node >> .envrc | |
echo 22 > .node-version | |
direnv allow | |
cd - | |
mkdir /work/v22-use-nvm | |
cd /work/v22-use-nvm | |
echo use nvm 22 >> .envrc | |
direnv allow | |
cd - | |
EOF | |
CMD bash -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment