A Docker image for NodeJS development, primarily for the benefit of The Greenhouse by providing the best tools and developer experience. https://hub.docker.com/r/thegreenhouse/nodejs-dev/tags/
In your own Dockerfile, use this project as your base image to get the full environment available to you.
FROM thegreenhouse/nodejs-dev:<version>
To see an example of this container being used for CI with all these features, see create-evergreen-app (.circleci/config.yml).
Tool | Version | Notes |
---|---|---|
NodeJS | 14.x | This is the current minimum active version |
Yarn | 1.x | |
npm | 7.x | This comes bundled with NodeJS |
Chrome Headless | N / A | Host packages needed to run Chrome Headless |
Chrome | Stable | Host packages needed to run Chrome browser (in headless mode) |
JRE | 8 | Java Runtime Environment (needed by Selenium) |
The following command line tools are available
vim git bzip2 ssh build-essential
Headless Chrome (Puppetter) is available and for example can be used with Karma by including this in karma.conf.js.
browsers: ['CustomChromeHeadless'],
customLaunchers: {
CustomChromeHeadless: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-setuid-sandbox'] // https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322852784
}
},
captureTimeout: 210000, // https://github.com/jasmine/jasmine/issues/1413#issuecomment-334247097
browserDisconnectTolerance: 3,
browserDisconnectTimeout: 210000,
browserNoActivityTimeout: 210000,
The Java Runtime Environment (JRE) is included for running tools like Web Component Tester can use Chrome by including this in wct.conf.json. This also supports running Selenium.
{
"plugins": {
"local": {
"disabled": true
},
"headless": {
"browsers": [
"chrome"
],
"browsersOptions": {
"chrome": [
"window-size=1920,1080",
"headless",
"disable-gpu",
"no-sandbox"
]
}
}
}
}
Common Docker commands used for the local development of this project.
docker build -t some-tag-name .
- build a Docker image from the project's Dockerfile with a name (-t
)docker run --name my-running-app -i -t some-tag-name
- start a Docker container from an image, giving it a name (--name
). The-i
tag will connect you to the container automatically.docker rm my-running-app
- destroy a running containerdocker images
- list available imagesdocker ps
- list available (running) containersexit
- quit a connection to a container
My general workflow for testing has looked something like:
- Make changes to Dockerfile
- Build the image
docker build -t nodejs-dev .
- Run and connect to the container
docker run --name nodejs-dev-app -i -t nodejs-dev
- Make a scratch space
mkdir workspace && cd workspace
- Clone a repo into the workspace
git clone https://github.com/thegreenhouseio/angular-webapp-seed.git
- Test things out, like
yarn install && yarn build
- Test another project (from the workspace)
npx create-evergreen-app my-app && cd my-app && npm install && npm run build && export NODE_ENV=production && npm test
- Disconnect from the contaier
exit
- Destroy the container
docker rm nodejs-dev-app
CircleCI is used to build the container on each PR. (TODO) It run a scripts that's based on the above developer workflow
- Clones a repo in the container
- Installs dependencies
- Runs unit tests
- Runs the build
Below are the steps to publish a new release of the image, based on this guide
- Export environment variable -
export DOCKER_ID_USER="username"
- Login -
docker login
- Hit Enter
- Enter Password
- Build the image
docker build -t nodejs-dev .
- Tag the image
docker tag nodejs-dev:latest thegreenhouse/nodejs-dev:x.y.z
- Push the image
docker push thegreenhouse/nodejs-dev:x.y.z
- Check the image exists in Docker Hub
- Create a git tag
git tag -a x.y.z -m "tagging x.y.z release"
- Push the tag
git push origin master --tags
- Create Release Notes