Giter Site home page Giter Site logo

knode's Introduction

KNode

This is an image optimized for the Krysalead projects. It has the best practices in terms of Node for Docker. It can be used as well in other project but I put also my way of doing node in docker. Feel free to comment or fork if you need.

The base image avoid to recompile the entire image preparation, the images in example folder gives the rest of the operation to produce DEV images and PROD images. It includes a build script to build and check your images.

The starter script allows to start various processes in the docker image according to the TASK_NAME env variable.

    dev) nodemon index.js --watch dist;;
    debug) nodemon --watch dist --debug --debug-brk=5858 index.js;;
    *) node index.js;;

dev

FROM dknode-dev:14.10-alpine
# Copy the package.json isolated to avoid recompilation on source change
COPY "package.json" "package-lock.json" ./
RUN npm install --quiet
# Copy the full content of your source
COPY . .
# This is only if you require it (Typescript or packaging)
RUN npm run build
# This will start wait (to wait for another server) and then start the process according to the env variable TASK_NAME
CMD /wait && ./start.sh

Running the image with a runtime compiled source that will reload each time the compiled source change

docker run -ti -v ${PWD}/dist/:/app/dist/ -e TASK_NAME=dev MY_IMAGE_NAME

production

will run in a production environement

FROM dknode:14.10-alpine AS build
COPY --chown=node:node "package.json" "package-lock.json" ./
# download only the dependencies from package-lock
RUN npm ci --quiet && npm cache clean --force
# copy the source code
COPY --chown=node:node . .
# build the code in ./dist
RUN npm run build

FROM build as prod
# Do not run as root
USER node
# get the previous stage compilation
COPY --from=build /dist /dist
CMD /wait && ./start.sh

Build

You need a username and password on DockerHub

./build.sh DOCKER_HUB_USERNAME DOCKER_HUB_PASS

knode's People

Contributors

krysalead avatar odaumas avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.