1
+ # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
2
+ ARG VARIANT=16-bullseye
3
+ FROM node:${VARIANT}
4
+
5
+ # [Option] Install zsh
6
+ ARG INSTALL_ZSH="true"
7
+ # [Option] Upgrade OS packages to their latest versions
8
+ ARG UPGRADE_PACKAGES="true"
9
+
10
+ # Install needed packages, yarn, nvm and setup non-root user. Use a separate RUN statement to add your own dependencies.
11
+ ARG USERNAME=node
12
+ ARG USER_UID=1000
13
+ ARG USER_GID=$USER_UID
14
+ ARG NPM_GLOBAL=/usr/local/share/npm-global
15
+ ENV NVM_DIR=/usr/local/share/nvm
16
+ ENV NVM_SYMLINK_CURRENT=true \
17
+ PATH=${NPM_GLOBAL}/bin:${NVM_DIR}/current/bin:${PATH}
18
+ COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
19
+ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
20
+ # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
21
+ && apt-get purge -y imagemagick imagemagick-6-common \
22
+ # Install common packages, non-root user, update yarn and install nvm
23
+ && bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
24
+ # Install yarn, nvm
25
+ && rm -rf /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg \
26
+ && bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "none" "${USERNAME}" \
27
+ # Configure global npm install location, use group to adapt to UID/GID changes
28
+ && if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
29
+ && usermod -a -G npm ${USERNAME} \
30
+ && umask 0002 \
31
+ && mkdir -p ${NPM_GLOBAL} \
32
+ && touch /usr/local/etc/npmrc \
33
+ && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
34
+ && chmod g+s ${NPM_GLOBAL} \
35
+ && npm config -g set prefix ${NPM_GLOBAL} \
36
+ && sudo -u ${USERNAME} npm config -g set prefix ${NPM_GLOBAL} \
37
+ # Install eslint
38
+ && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
39
+ && npm cache clean --force > /dev/null 2>&1 \
40
+ # Install python-is-python3 on bullseye to prevent node-gyp regressions
41
+ && . /etc/os-release \
42
+ && if [ "${VERSION_CODENAME}" = "bullseye" ]; then apt-get -y install --no-install-recommends python-is-python3; fi \
43
+ # Clean up
44
+ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts
45
+
46
+ # [Optional] Uncomment this section to install additional OS packages.
47
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
48
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
49
+
50
+ # [Optional] Uncomment if you want to install an additional version of node using nvm
51
+ # ARG EXTRA_NODE_VERSION=10
52
+ # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
53
+
54
+ # [Optional] Uncomment if you want to install more global node modules
55
+ # RUN su node -c "npm install -g <your-package-list-here>""
0 commit comments