From 6b6314227e2ffdb7aa3f6f0d4503fb0dc580b7a4 Mon Sep 17 00:00:00 2001 From: Antonis Kalipetis Date: Mon, 12 Dec 2016 16:37:23 +0200 Subject: [PATCH 1/4] Improve the Docker image 1. Bump Node version to 6.9 - the latest LTS 2. Include the `cpio` binary, used during building 3. Ignore node_modules and .git directories for faster builds 4. Run the tests and build during the image build, to make sure the image is not built if these break 5. Make npm run dev the default command 6. Add an entrypoint to automatically install Node modules if they do nott exist Signed-off-by: Antonis Kalipetis --- .dockerignore | 2 ++ Dockerfile | 25 +++++++++++++++++++++++-- docker-compose.yaml | 9 +++++++++ entrypoint.sh | 8 ++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yaml create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..651665bb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.git diff --git a/Dockerfile b/Dockerfile index 105e997e..ffbcd379 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,25 @@ -FROM node:4-onbuild +FROM node:6.9 MAINTAINER Paris Kasidiaris -EXPOSE 3000 +# Install cpio, used for building +RUN apt-get update \ + && apt-get install -y --no-install-recommends cpio \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /usr/src/app + +# Set an entrypoint, to automatically install node modules +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +# First, install dependencies to improve layer caching +COPY package.json /usr/src/app/ +RUN npm install + +# Add the code +COPY . /usr/src/app + +# Run the tests and build, to make sure everything is working nicely +RUN npm run test && npm run build +CMD ["npm", "run", "dev"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..22ea2e20 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,9 @@ +version: '2' + +services: + web: + build: ./ + volumes: + - ./:/usr/src/app + ports: + - 3000:3000 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..4c63d001 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +# Install Node modules, if the `node_modules` directory does not exist +if [[ ! -d node_modules ]]; then + npm install; +fi + +exec "$@" From b2e257bf378c62ab6691dd8338cbadb9be8f9595 Mon Sep 17 00:00:00 2001 From: Antonis Kalipetis Date: Thu, 15 Dec 2016 18:26:24 +0200 Subject: [PATCH 2/4] Remove entrypoint Signed-off-by: Antonis Kalipetis --- Dockerfile | 5 ++--- entrypoint.sh | 8 -------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index ffbcd379..fa1a9209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ RUN apt-get update \ WORKDIR /usr/src/app # Set an entrypoint, to automatically install node modules -COPY entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "-c", "if [[ ! -d node_modules ]]; then npm install; fi; exec \"$@\";"] +CMD ["npm", "run", "dev"] # First, install dependencies to improve layer caching COPY package.json /usr/src/app/ @@ -22,4 +22,3 @@ COPY . /usr/src/app # Run the tests and build, to make sure everything is working nicely RUN npm run test && npm run build -CMD ["npm", "run", "dev"] diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 4c63d001..00000000 --- a/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/bash - -# Install Node modules, if the `node_modules` directory does not exist -if [[ ! -d node_modules ]]; then - npm install; -fi - -exec "$@" From a4c958c54fb1becf5878354988556673333b5a26 Mon Sep 17 00:00:00 2001 From: Antonis Kalipetis Date: Wed, 28 Dec 2016 18:48:24 +0200 Subject: [PATCH 3/4] Fix EOL character in .editorconfig and update docker-compose --- .editorconfig | 1 + docker-compose.yaml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.editorconfig b/.editorconfig index ae59e935..26230e94 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,7 @@ indent_style = space indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true +end_of_line = lf [*.{j,t}s] max_line_length = 100 diff --git a/docker-compose.yaml b/docker-compose.yaml index 22ea2e20..9579dcf5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,9 @@ -version: '2' - -services: - web: - build: ./ - volumes: - - ./:/usr/src/app - ports: - - 3000:3000 +version: '2' + +services: + web: + build: ./ + volumes: + - ./:/usr/src/app + ports: + - 3000:3000 From 61c213f9e35e380b34ed3ae11726e8c353e01f5b Mon Sep 17 00:00:00 2001 From: Antonis Kalipetis Date: Thu, 29 Dec 2016 16:13:58 +0200 Subject: [PATCH 4/4] Ignore all the build directories in Docker This allows for reproducible builds. Also, fix Dockerfile to first build and then run tests and a typo in the entrypoint. Thanks @BenHall for reporting the issue with the Docker build! --- .dockerignore | 18 ++++++++++++++++-- Dockerfile | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 651665bb..c837dec7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,16 @@ -node_modules -.git +node_modules/ +*.swp +.lock-wscript +lib/ +Makefile.gyp +*.Makefile +*.target.gyp.mk +*.node +example/*.log +docs/ +npm-debug.log +/.idea/ +.env +build/ +.vscode/ +.git/ diff --git a/Dockerfile b/Dockerfile index fa1a9209..36e821bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN apt-get update \ WORKDIR /usr/src/app # Set an entrypoint, to automatically install node modules -ENTRYPOINT ["/bin/bash", "-c", "if [[ ! -d node_modules ]]; then npm install; fi; exec \"$@\";"] +ENTRYPOINT ["/bin/bash", "-c", "if [[ ! -d node_modules ]]; then npm install; fi; exec \"${@:0}\";"] CMD ["npm", "run", "dev"] # First, install dependencies to improve layer caching @@ -21,4 +21,4 @@ RUN npm install COPY . /usr/src/app # Run the tests and build, to make sure everything is working nicely -RUN npm run test && npm run build +RUN npm run build && npm run test