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 "$@"