Dockerfile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Based of https://github.com/microsoft/vscode-dev-containers/blob/main/containers/javascript-node/.devcontainer/base.Dockerfile
  2. # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
  3. ARG VARIANT=18-bullseye
  4. FROM node:${VARIANT}
  5. ENV DEBIAN_FRONTEND=noninteractive
  6. # Copy library scripts to execute
  7. ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh /tmp/library-scripts/
  8. ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh /tmp/library-scripts/
  9. ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/meta.env /tmp/library-scripts/
  10. # [Option] Install zsh
  11. ARG INSTALL_ZSH="true"
  12. # [Option] Upgrade OS packages to their latest versions
  13. ARG UPGRADE_PACKAGES="true"
  14. # Install needed packages, yarn, nvm and setup non-root user. Use a separate RUN statement to add your own dependencies.
  15. ARG USERNAME=node
  16. ARG USER_UID=1000
  17. ARG USER_GID=$USER_UID
  18. ARG NPM_GLOBAL=/usr/local/share/npm-global
  19. ENV NVM_DIR=/usr/local/share/nvm
  20. ENV NVM_SYMLINK_CURRENT=true \
  21. PATH=${NPM_GLOBAL}/bin:${NVM_DIR}/current/bin:${PATH}
  22. RUN apt-get update \
  23. # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
  24. && apt-get purge -y imagemagick imagemagick-6-common \
  25. # Install common packages, non-root user, update yarn and install nvm
  26. && bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
  27. # Install yarn, nvm
  28. && rm -rf /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg \
  29. && bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "none" "${USERNAME}" \
  30. # Configure global npm install location, use group to adapt to UID/GID changes
  31. && if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
  32. && usermod -a -G npm ${USERNAME} \
  33. && umask 0002 \
  34. && mkdir -p ${NPM_GLOBAL} \
  35. && touch /usr/local/etc/npmrc \
  36. && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
  37. && chmod g+s ${NPM_GLOBAL} \
  38. && npm config -g set prefix ${NPM_GLOBAL} \
  39. && sudo -u ${USERNAME} npm config -g set prefix ${NPM_GLOBAL} \
  40. # Install eslint
  41. && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
  42. && npm cache clean --force > /dev/null 2>&1 \
  43. # Install python-is-python3 on bullseye to prevent node-gyp regressions
  44. && . /etc/os-release \
  45. && if [ "${VERSION_CODENAME}" = "bullseye" ]; then apt-get -y install --no-install-recommends python-is-python3; fi \
  46. # Clean up
  47. && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts
  48. EXPOSE 3000
  49. # Add Docker Source
  50. RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  51. RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  52. $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
  53. # Install the packages we need
  54. RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get install -qy \
  55. bash \
  56. build-essential \
  57. curl \
  58. docker-ce-cli \
  59. jq \
  60. less \
  61. git \
  62. gnupg2 \
  63. nano \
  64. netcat \
  65. pandoc \
  66. unzip \
  67. wget
  68. # avoid million NPM install messages
  69. ENV npm_config_loglevel warn
  70. # allow installing when the main user is root
  71. ENV npm_config_unsafe_perm true
  72. # disable NPM funding messages
  73. ENV npm_config_fund false
  74. # Colorize the bash shell
  75. RUN sed -i 's/#force_color_prompt=/force_color_prompt=/' /root/.bashrc
  76. # Fetch wait-for utility
  77. ADD https://raw.githubusercontent.com/eficode/wait-for/v2.2.3/wait-for /usr/local/bin/
  78. RUN chmod +rx /usr/local/bin/wait-for
  79. # Copy the startup file
  80. COPY app-init.sh /docker-init.sh
  81. RUN sed -i 's/\r$//' /docker-init.sh && \
  82. chmod +x /docker-init.sh
  83. # Create workspace
  84. RUN mkdir -p /workspace
  85. WORKDIR /workspace