Add optional node to Java
This commit is contained in:
Родитель
59eb39d918
Коммит
d498ea78d8
|
@ -48,6 +48,19 @@ RUN if [ "${INSTALL_GRADLE}" = "true" ]; then \
|
|||
# Allow for a consistant java home location for settings - image is changing over time
|
||||
RUN if [ ! -d "/docker-java-home" ]; then ln -s "${JAVA_HOME}" /docker-java-home; fi
|
||||
|
||||
# [Optional] Install Node.js for use with web applications - update the INSTALL_NODE arg in devcontainer.json to enable.
|
||||
ARG INSTALL_NODE="false"
|
||||
ARG NODE_VERSION="lts/*"
|
||||
ENV NVM_DIR=/usr/local/share/nvm \
|
||||
NVM_SYMLINK_CURRENT=true \
|
||||
PATH=${NVM_DIR}/current/bin:${PATH}
|
||||
COPY library-scripts/node-debian.sh /tmp/library-scripts/
|
||||
RUN if [ "$INSTALL_NODE" = "true" ]; then \
|
||||
/bin/bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \
|
||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*; \
|
||||
fi \
|
||||
&& rm -rf /tmp/library-scripts
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
# RUN apt-get update \
|
||||
# && export DEBIAN_FRONTEND=noninteractive \
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
"MAVEN_DOWNLOAD_SHA": "c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0",
|
||||
"INSTALL_GRADLE": "true",
|
||||
"GRADLE_VERSION": "5.4.1",
|
||||
"GRADLE_DOWNLOAD_SHA": "7bdbad1e4f54f13c8a78abc00c26d44dd8709d4aedb704d913fb1bb78ac025dc"
|
||||
"GRADLE_DOWNLOAD_SHA": "7bdbad1e4f54f13c8a78abc00c26d44dd8709d4aedb704d913fb1bb78ac025dc",
|
||||
"INSTALL_NODE": "false",
|
||||
"NODE_VERSION": "lts/*"
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env bash
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# Syntax: ./node-debian.sh <directory to install nvm> <node version to install (use "none" to skip)> <non-root user>
|
||||
|
||||
set -e
|
||||
|
||||
export NVM_DIR=${1:-"/usr/local/share/nvm"}
|
||||
export NODE_VERSION=${2:-"lts/*"}
|
||||
NONROOT_USER=${3:-"vscode"}
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure apt is in non-interactive to avoid prompts
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
if [ "${NODE_VERSION}" = "none" ]; then
|
||||
export NODE_VERSION=
|
||||
fi
|
||||
|
||||
# Install NVM
|
||||
mkdir -p ${NVM_DIR}
|
||||
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 2>&1
|
||||
if [ "${NODE_VERSION}" != "" ]; then
|
||||
/bin/bash -c "source $NVM_DIR/nvm.sh && nvm alias default ${NODE_VERSION}" 2>&1
|
||||
fi
|
||||
|
||||
echo -e "export NVM_DIR=\"${NVM_DIR}\"\n\
|
||||
[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\"\n\
|
||||
[ -s \"\$NVM_DIR/bash_completion\" ] && \\. \"\$NVM_DIR/bash_completion\"" \
|
||||
| tee -a /home/${NONROOT_USER}/.bashrc /home/${NONROOT_USER}/.zshrc >> /root/.zshrc
|
||||
|
||||
echo -e "if [ \"\$(stat -c '%U' \$NVM_DIR)\" != \"${NONROOT_USER}\" ]; then\n\
|
||||
sudo chown -R ${NONROOT_USER}:root \$NVM_DIR\n\
|
||||
fi" | tee -a /root/.bashrc /root/.zshrc /home/${NONROOT_USER}/.bashrc >> /home/${NONROOT_USER}/.zshrc
|
||||
|
||||
chown ${NONROOT_USER}:${NONROOT_USER} /home/${NONROOT_USER}/.bashrc /home/${NONROOT_USER}/.zshrc
|
||||
chown -R ${NONROOT_USER}:root ${NVM_DIR}
|
||||
|
||||
# Install yarn
|
||||
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 2>/dev/null
|
||||
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
|
||||
apt-get update
|
||||
apt-get -y install --no-install-recommends yarn
|
|
@ -68,6 +68,18 @@ And if you'd like the download SHA to be checked, you can add it as well.
|
|||
}
|
||||
```
|
||||
|
||||
### Installing Node.js
|
||||
|
||||
Given how frequently web applications use Node.js for front end code, this container also includes an optional install of Node.js. You can enable installation and change the version of Node.js installed or disable its installation by updating the `args` property in `.devcontainer/devcontainer.json`.
|
||||
|
||||
```json
|
||||
"args": {
|
||||
"VARIANT": "11",
|
||||
"INSTALL_NODE": "true",
|
||||
"NODE_VERSION": "10",
|
||||
}
|
||||
```
|
||||
|
||||
### Adding the definition to your folder
|
||||
|
||||
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
|
||||
|
|
Загрузка…
Ссылка в новой задаче