Skip to content

Commit

Permalink
ci: multi-stage build, including lint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwalther committed Sep 18, 2017
1 parent df40bf4 commit edf65b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules
/scripts
/test
.circleci
.editorconfig
.gitignore
Expand Down
2 changes: 1 addition & 1 deletion .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ $ curl http://localhost:3004/cmd-cron?def=echo%20foo&cron=*%20*%20*%20*%20*
**References:**
- https://capgemini.github.io/development/multi-stage-builds-in-docker/
- https://codefresh.io/blog/node_docker_multistage/
- https://blog.alexellis.io/mutli-stage-docker-builds/
- Using multi-stage builds to reduce Go images: https://blog.alexellis.io/mutli-stage-docker-builds/
- https://github.com/yamalight/node-docker-pkg-demo
## Todo
Expand Down
40 changes: 38 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# --------------------------------------
# BASE NODE
# --------------------------------------
FROM node:8.5.0-alpine as BASE

ARG PORT=3000
Expand All @@ -7,14 +10,47 @@ ENV HOME=/app
RUN mkdir -p $HOME
WORKDIR $HOME

COPY ./package.json ./index.js ./
COPY package.json package-lock.json ./

RUN npm install --production
# --------------------------------------
# DEPENDENCIES
# --------------------------------------
FROM BASE as DEPENDENCIES

RUN npm install --only=production

# copy production node_modules aside
RUN cp -R node_modules prod_node_modules

# install ALL node_modules, including 'devDependencies'
RUN npm install


# --------------------------------------
# TEST
# --------------------------------------
# run linters, setup and tests
FROM dependencies AS TEST

COPY .eslintrc.json .

COPY /src ./src/

COPY /test ./test/

RUN npm run lint && npm run test

# --------------------------------------
# RELEASE
# --------------------------------------
FROM BASE as RELEASE

# copy production node_modules
COPY --from=dependencies /app/prod_node_modules ./node_modules

# copy app sources
COPY /src ./src/

EXPOSE $PORT

CMD ["npm", "run", "start"]
Expand Down

0 comments on commit edf65b9

Please sign in to comment.