Containerizing a NodeJS application in TravisCI
• Mark Eschbach
We’ve crossed over the dev instance of our system. There are some interesting discussions I would like to have regarding security controls and practicing the companies value of trust and transparaency…but that is for another day. There was an acelary system we overlooked and so I need to move it over. The system is written in NodeJS and doesn’t have direct user facing access.
I was going to take the standard approach of testing the software first, then build the container and ship it. However I realized I could easily produce an image and just test that. Not like runtime cost of Docker will be too large here.
Dockerfile is rather simple for a NodeJS application:
FROM node:7.8.0-alpine LABEL maintainer email@example.com RUN apk upgrade --update --no-cache RUN mkdir /app WORKDIR /app ADD package.json /app/package.json RUN npm install ADD . /app ENV LOCAL_ENV docker EXPOSE 3000 #HEALTHCHECK CMD curl -f http://localhost:3000/ || exit 1 # TODO: Figure out a better method...maybe just write a simple script? CMD ["npm","start"]
The health check still needs to be done. I thought it was a long shot with
curl being installed on an Alpine image but you never know. It definitely wasn’t installed. Given the need to move forward I’m happy to punt that until another day.
I was on the fence about using an Alpine image since the application uses ImageMagick like stuff. I also didn’t install the build tools either…so we’ll see if not having native extensions is an issue.
Worked like a charm, however I’ll need to create a distributable release process in the future. I’m tired of copying and pasting large chunks of code between projects. Good
.dockerignore file for the future:
node_modules/ .git/ .nvmrc .dockerignore .travis.yml .gitignore .travis/ Dockerfile