From cdde74a55d05b7925bb3822e8f31c05789e56968 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 14:27:20 +0800 Subject: [PATCH 1/4] [Dockerfile] install missing eclint package --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 49bc3c5..22e759a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,7 +101,7 @@ RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # Th # nodejs and tools RUN bash -c 'source $HOME/.nvm/nvm.sh && \ nvm install node && \ - npm install -g doctoc urchin && \ + npm install -g doctoc urchin eclint && \ npm install --prefix "$HOME/.nvm/"' # Set WORKDIR to nvm directory From 7ff20855a2b7328ada8049e4570078f7db6d68cc Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:14:06 +0800 Subject: [PATCH 2/4] [Tests] Integrate dockerfile_lint to test Dockerfile --- .travis.yml | 4 +++- Dockerfile | 2 +- package.json | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c32943..8af8a2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,12 +19,13 @@ before_install: - curl --version - wget --version install: - - if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint; fi + - if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y' script: - if [ -n "${MAKE_RELEASE-}" ]; then export GIT_EDITOR="sed -i '1 s/^/99.99.99 make release test/'" && git fetch --unshallow --tags && echo proceed | make TAG=99.99.99 release ; fi - if [ -n "${DOCTOCCHECK-}" ]; then cp README.md README.md.orig && npm run doctoc && diff -q README.md README.md.orig ; fi - if [ -n "${ECLINT-}" ]; then npm run eclint ; fi + - if [ -n "${DOCKERFILE_LINT-}" ]; then npm run dockerfile_lint ; fi - if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash nvm.sh && shellcheck -s sh nvm.sh && shellcheck -s dash nvm.sh && shellcheck -s ksh nvm.sh ; fi - if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash install.sh bash_completion nvm-exec ; fi - if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi @@ -42,6 +43,7 @@ env: - DOCTOCCHECK=true - SHELLCHECK=true - ECLINT=true + - DOCKERFILE_LINT=true - SHELL=bash TEST_SUITE=install_script - SHELL=sh TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast diff --git a/Dockerfile b/Dockerfile index 22e759a..22cc068 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,7 +101,7 @@ RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # Th # nodejs and tools RUN bash -c 'source $HOME/.nvm/nvm.sh && \ nvm install node && \ - npm install -g doctoc urchin eclint && \ + npm install -g doctoc urchin eclint dockerfile_lint && \ npm install --prefix "$HOME/.nvm/"' # Set WORKDIR to nvm directory diff --git a/package.json b/package.json index 5a4fd87..310b802 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell", "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell", "doctoc": "doctoc --title='## Table of Contents' --github README.md", - "eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)" + "eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)", + "dockerfile_lint": "dockerfile_lint" }, "repository": { "type": "git", @@ -35,6 +36,7 @@ }, "homepage": "https://github.com/creationix/nvm", "devDependencies": { + "dockerfile_lint": "^0.3.2", "eclint": "^2.6.0", "replace": "^0.3.0", "semver": "^5.0.1", From 5f9ccaada08940eabe1c95ecdc44d781fce987b0 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:22:41 +0800 Subject: [PATCH 3/4] [Dockerfile] Set the SHELL to bash with pipefail option --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 22cc068..d2ac044 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,9 @@ LABEL maintainer="Peter Dave Hello " LABEL name="nvm-dev-env" 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 From 4bd99bcfa21a2c83c1958445ea7347439e894309 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:29:46 +0800 Subject: [PATCH 4/4] [Dockerfile] Refactor to prevent using `sudo` during build `sudo` may lead to unpredictable behavior in some cases, and we don't really need to use `sudo` to reach what we need. --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2ac044..d4b0f1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,6 +88,10 @@ RUN wget --version # Add user "nvm" as non-root user RUN useradd -ms /bin/bash nvm +# Copy and set permission for nvm directory +COPY . /home/nvm/.nvm/ +RUN chown nvm:nvm -R "home/nvm/.nvm" + # Set sudoer for "nvm" RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers @@ -95,8 +99,6 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER nvm # nvm -COPY . /home/nvm/.nvm/ -RUN sudo chown nvm:nvm -R "$HOME/.nvm" RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$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"