From 6f2417a20f7ea7aee2982b4b37a6ac2ffae4923e Mon Sep 17 00:00:00 2001 From: Will Fleming Date: Wed, 13 Jan 2016 15:23:09 -0500 Subject: [PATCH] clean & optimize Dockerfile: General best practices: * Use a tag on our base image to reduce chance of random breakage * Add maintainer info CC best practices (https://github.com/codeclimate/spec/blob/master/SPEC.md#packaging): * declare /code as a VOLUME * make /code the WORKDIR Also: * rm git after npm install: git is only needed for the npm install, so we may as well remove it after to shave a bit off the final image size * With the WORKDIR change, the `make test` task had to be adjusted --- Dockerfile | 13 ++++++++----- Makefile | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd9bfb361..0580fe1ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,18 @@ -FROM mhart/alpine-node +FROM mhart/alpine-node:5.4 +MAINTAINER Code Climate WORKDIR /usr/src/app COPY package.json /usr/src/app/ -RUN apk --update add git +RUN apk --update add git && \ + npm install && \ + apk del --purge git -RUN npm install +COPY . /usr/src/app RUN adduser -u 9000 -D app USER app - -COPY . /usr/src/app +VOLUME /code +WORKDIR /code CMD ["/usr/src/app/bin/eslint.js"] diff --git a/Makefile b/Makefile index c571bf19e..ca3e0c060 100644 --- a/Makefile +++ b/Makefile @@ -6,4 +6,4 @@ image: docker build --rm -t $(IMAGE_NAME) . test: image - docker run $(IMAGE_NAME) npm run test + docker run --rm --workdir="/usr/src/app" $(IMAGE_NAME) npm run test