Skip to content

Commit a11f8c7

Browse files
authored
Use nvm to install Node in Dockerfile (swiftlang#788)
1 parent 228be75 commit a11f8c7

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.19.0

CONTRIBUTING.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ All contributors are expected to adhere to the project's [Code of Conduct](CODE_
66

77
## Development
88

9-
To begin development on the VSCode extension for Swift you will need to install [Node.js](https://nodejs.org). On Linux, make sure to install Node.js from its official website or from [NodeSource](https://github.com/nodesource/distributions/) as the version included with your Linux distribution may be outdated.
9+
To begin development on the VSCode extension for Swift you will need to install [Node.js](https://nodejs.org). We use [nvm](https://github.com/nvm-sh/nvm) the Node version manager to install Node.js. To install or update nvm you should run their install script
10+
```
11+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
12+
```
13+
More details on nvm installation can be found in the [README](https://github.com/nvm-sh/nvm/blob/master/README.md) from its GitHub repository.
1014

11-
Next, clone this repository, and in the project directory run `npm install` to install all the dependencies.
15+
Once you have installed nvm, clone this repository, and in the project directory run `nvm install`. This will install the correct version of node.js for developing the extension. Then you should run `npm install` to install all the dependencies the extension requires.
1216

13-
When you first open the project in VSCode you will be recommended to also install [`ESLint`](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint), [`Prettier - Code formatter`](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and [`esbuild Problem Matchers`](https://marketplace.visualstudio.com/items?itemName=connor4312.esbuild-problem-matchers). Please do so. `ESLint`, `Prettier - Code formatter` are used to ensure a consistent style and expect everyone who contributes to follow this style as well. `esbuild Problem Matchers` provides proper error output from building the project.
17+
When you first open the project in VSCode you will be recommended to also install [`ESLint`](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint), [`Prettier - Code formatter`](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and [`esbuild Problem Matchers`](https://marketplace.visualstudio.com/items?itemName=connor4312.esbuild-problem-matchers). Please do so. `ESLint`, `Prettier - Code formatter` is used to ensure a consistent style and we expect everyone who contributes to follow this style as well. `esbuild Problem Matchers` provides proper error output from building the project.
1418

1519
To run your version of the Swift extension while in VSCode, press `F5`. This will open up another instance of VSCode with it running. You can use the original version of VSCode to debug it.
1620

docker/Dockerfile

+14-13
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ ENV LANGUAGE en_US.UTF-8
1515
# dependencies
1616
RUN apt-get update && apt-get install -y curl gpg libasound2 libgbm1 libgtk-3-0 libnss3 xvfb build-essential
1717

18-
# install NodeJS 18
19-
# Add the NodeSource package signing key
20-
ENV KEYRING /usr/share/keyrings/nodesource.gpg
21-
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee "$KEYRING" >/dev/null
22-
RUN gpg --no-default-keyring --keyring "$KEYRING" --list-keys
23-
# Add the desired NodeSource repository
24-
ENV VERSION node_18.x
25-
ENV DISTRO $ubuntu_version
26-
RUN echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | tee /etc/apt/sources.list.d/nodesource.list
27-
RUN echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | tee -a /etc/apt/sources.list.d/nodesource.list
28-
# Update package lists and install Node.js
29-
RUN apt-get update && apt-get install -y nodejs
18+
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /vscode vscode
3019

31-
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /vscode vscode
20+
RUN mkdir -p /usr/local/nvm
21+
RUN chown vscode /usr/local/nvm
22+
23+
USER vscode
24+
ENV NVM_DIR /usr/local/nvm
25+
26+
ENV NODE_VERSION v18.19.0
27+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
28+
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"
29+
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
30+
ENV PATH $NODE_PATH:$PATH
31+
RUN npm -v
32+
RUN node -v

0 commit comments

Comments
 (0)