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 <akalipetis@gmail.com>
This commit is contained in:
Antonis Kalipetis
2016-12-28 18:45:18 +02:00
parent 1e0eb3784e
commit 6b6314227e
4 changed files with 42 additions and 2 deletions
+2
View File
@@ -0,0 +1,2 @@
node_modules
.git
+23 -2
View File
@@ -1,4 +1,25 @@
FROM node:4-onbuild
FROM node:6.9
MAINTAINER Paris Kasidiaris <paris@sourcelair.com>
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"]
+9
View File
@@ -0,0 +1,9 @@
version: '2'
services:
web:
build: ./
volumes:
- ./:/usr/src/app
ports:
- 3000:3000
Executable
+8
View File
@@ -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 "$@"