Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat: enable Docker build npm cache (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Mar 16, 2021
1 parent 5376748 commit 912ee9d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:12-alpine
FROM node:12-alpine as node_modules

RUN apk update && \
apk --no-cache upgrade && \
Expand All @@ -8,37 +8,43 @@ RUN apk update && \
alpine-sdk \
zeromq-dev

# Install dependencies first, in a different location
# for easier app bind mounting for local development
WORKDIR /
# Enable node-gyp cache
RUN npm install -g node-gyp-cache@0.2.1 && \
npm config set node_gyp node-gyp-cache

# Copy node gyp cache
COPY docker/cache/.cache /root/.cache

# Copy NPM cache
COPY docker/cache/.npm /root/.npm

COPY package.json package-lock.json ./
# Install npm modules
ENV npm_config_zmq_external=true

COPY package.json package-lock.json /

RUN npm ci --production

FROM node:12-alpine

# While we're using this image for tests
# We have to run `npm i` and zeromq build fails
RUN apk add zeromq-dev
RUN echo npm_config_zmq_external=true >> /etc/environment
ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}

LABEL maintainer="Dash Developers <dev@dash.org>"
LABEL description="DAPI Node.JS"

RUN apk update && apk add --no-cache zeromq-dev

# Copy NPM modules
COPY package.json package-lock.json ./
COPY --from=0 /node_modules/ /node_modules
COPY --from=node_modules /node_modules/ /node_modules
COPY --from=node_modules /package.json /package.json
COPY --from=node_modules /package-lock.json /package-lock.json

ENV PATH /node_modules/.bin:$PATH

# Copy project files
WORKDIR /usr/src/app
COPY . ./

ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
COPY . .

RUN cp .env.example .env

EXPOSE 2500 2501 2510
2 changes: 2 additions & 0 deletions docker/cache/.cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
3 changes: 3 additions & 0 deletions docker/cache/.npm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore

0 comments on commit 912ee9d

Please sign in to comment.