Skip to content

Instantly share code, notes, and snippets.

@scokmen
Created January 7, 2020 16:38
Show Gist options
  • Save scokmen/62a892372624eeffdcd8b6d46dfe2ac7 to your computer and use it in GitHub Desktop.
Save scokmen/62a892372624eeffdcd8b6d46dfe2ac7 to your computer and use it in GitHub Desktop.
FROM node:12-alpine AS BUILD_IMAGE
# couchbase sdk requirements
RUN apk update && apk add yarn curl bash python g++ make && rm -rf /var/cache/apk/*
# install node-prune (https://github.com/tj/node-prune)
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
# install dependencies
RUN yarn --frozen-lockfile
COPY . .
# lint & test
RUN yarn lint & yarn test
# build application
RUN yarn build
# remove development dependencies
RUN npm prune --production
# run node prune
RUN /usr/local/bin/node-prune
# remove unused dependencies
RUN rm -rf node_modules/rxjs/src/
RUN rm -rf node_modules/rxjs/bundles/
RUN rm -rf node_modules/rxjs/_esm5/
RUN rm -rf node_modules/rxjs/_esm2015/
RUN rm -rf node_modules/swagger-ui-dist/*.map
RUN rm -rf node_modules/couchbase/src/
FROM node:12-alpine
WORKDIR /usr/src/app
# copy from build image
COPY --from=BUILD_IMAGE /usr/src/app/dist ./dist
COPY --from=BUILD_IMAGE /usr/src/app/node_modules ./node_modules
EXPOSE 3030
CMD [ "node", "./dist/Main.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment