From 18cde996c3ed75c3d012270dc7783e14ca3cf279 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Sat, 19 Jun 2021 23:10:03 +0200 Subject: [PATCH] Created improved DevContainer using vscode --- .devcontainer/Dockerfile | 74 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 26 ++++++++++++ .devcontainer/postCreation.sh | 14 +++++++ 3 files changed, 114 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/postCreation.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..f9e7e57 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,74 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/ubuntu/.devcontainer/base.Dockerfile + +# [Choice] Ubuntu version: bionic, focal +ARG VARIANT="focal" +FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} +LABEL name="nvm-dev-conteriner" +LABEL version="latest" + +# Set the SHELL to bash with pipefail option +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +# Prevent dialog during apt install +ENV DEBIAN_FRONTEND noninteractive + +# ShellCheck version +ENV SHELLCHECK_VERSION=0.7.0 + +# Install apt packages +RUN apt-get update && \ + apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && \ + apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \ + coreutils \ + util-linux \ + bsdutils \ + file \ + openssl \ + libssl-dev \ + locales \ + ca-certificates \ + ssh \ + wget \ + patch \ + sudo \ + htop \ + dstat \ + vim \ + tmux \ + curl \ + git \ + jq \ + zsh \ + ksh \ + gcc \ + g++ \ + xz-utils \ + build-essential \ + bash-completion && \ + apt-get clean + +RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \ + tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \ + mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \ + rmdir shellcheck-v$SHELLCHECK_VERSION + +# Set locale +# Add user "nvm" as non-root user +# Set sudoer for "nvm" +RUN locale-gen en_US.UTF-8 \ + && useradd -ms /bin/bash nvm \ + && echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers + +# Switch to user "nvm" from now +USER nvm + +# # nvm +# RUN echo 'export NVM_DIR="\Workspace"' >> "$HOME/.bashrc" +# RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc" +# RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc" + +# # nodejs and tools +# RUN bash -c 'source $NVM_DIR/nvm.sh && \ +# nvm install node && \ +# npm install -g doctoc urchin eclint dockerfile_lint && \ +# npm install --prefix "$HOME/.nvm/"' diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..862e859 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/ubuntu +{ + "name": "Ubuntu", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Ubuntu version: focal, bionic + "args": { "VARIANT": "bionic" } + }, + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash /workspaces/nvm/.devcontainer/postCreation.sh", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "nvm" +} \ No newline at end of file diff --git a/.devcontainer/postCreation.sh b/.devcontainer/postCreation.sh new file mode 100644 index 0000000..cec3754 --- /dev/null +++ b/.devcontainer/postCreation.sh @@ -0,0 +1,14 @@ +# # nvm + +NVM_DIR="/workspaces/nvm" +echo 'export ${NVM_DIR}' >> "${HOME}/.bashrc" +echo '[ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh" # This loads nvm' >> "${HOME}/.bashrc" +echo '[ -s "${NVM_DIR}/bash_completion" ] && . "${NVM_DIR}/bash_completion" # This loads nvm bash_completion' >> "${HOME}/.bashrc" + +# nodejs and tools +source ${NVM_DIR}/nvm.sh +nvm install node +npm install -g doctoc urchin eclint dockerfile_lint +npm install --prefix "${NVM_DIR}" + +echo hi >> $NVM_DIR/test \ No newline at end of file