Skip to content

thegreenhouseio/docker-nodejs-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-nodejs-dev

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/

Usage

In your own Dockerfile, use this project as your base image to get the full environment available to you.

FROM thegreenhouse/nodejs-dev:<version>

Features

To see an example of this container being used for CI with all these features, see create-evergreen-app (.circleci/config.yml).

Environment

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)

Command Line tools

The following command line tools are available

vim git bzip2 ssh build-essential

Headless Chrome

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,

JRE (Selenium / Web Component Tester)

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"
        ]
      }
    }
  }
}

Development

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 container
  • docker images - list available images
  • docker ps - list available (running) containers
  • exit - quit a connection to a container

Workflow

My general workflow for testing has looked something like:

  1. Make changes to Dockerfile
  2. Build the image docker build -t nodejs-dev .
  3. Run and connect to the container docker run --name nodejs-dev-app -i -t nodejs-dev
  4. Make a scratch space mkdir workspace && cd workspace
  5. Clone a repo into the workspace git clone https://github.com/thegreenhouseio/angular-webapp-seed.git
  6. Test things out, like yarn install && yarn build
  7. 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
  8. Disconnect from the contaier exit
  9. Destroy the container docker rm nodejs-dev-app

Continuous Integration

CircleCI is used to build the container on each PR. (TODO) It run a scripts that's based on the above developer workflow

  1. Clones a repo in the container
  2. Installs dependencies
  3. Runs unit tests
  4. Runs the build

Publish Procedure

Below are the steps to publish a new release of the image, based on this guide

  1. Export environment variable - export DOCKER_ID_USER="username"
  2. Login - docker login
    • Hit Enter
    • Enter Password
  3. Build the image docker build -t nodejs-dev .
  4. Tag the image docker tag nodejs-dev:latest thegreenhouse/nodejs-dev:x.y.z
  5. Push the image docker push thegreenhouse/nodejs-dev:x.y.z
  6. Check the image exists in Docker Hub
  7. Create a git tag git tag -a x.y.z -m "tagging x.y.z release"
  8. Push the tag git push origin master --tags
  9. Create Release Notes