Skip to content

Base nodeJS images for HMCTS applications

License

Notifications You must be signed in to change notification settings

ernestman28/cnp-node-base

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cnp-nodejs-base

Build Status

Images list

Tag OS NodeJS version
hmctspublic.azurecr.io/base/node:8-alpine Alpine LTS 8
hmctspublic.azurecr.io/base/node:10-alpine Alpine LTS 10
hmctspublic.azurecr.io/base/node:12-alpine Alpine LTS 12
hmctspublic.azurecr.io/base/node:8-stretch-slim Debian stretch LTS 8
hmctspublic.azurecr.io/base/node:10-stretch-slim Debian stretch LTS 10
hmctspublic.azurecr.io/base/node:12-stretch-slim Debian stretch LTS 12

Background

These images are based on nodeJS official ones using LTS versions, with the addition of a specific hmcts user, used for consistent runtime parameters.

Here are the defaults properties you inherit from using those base images:

Directive Default Values
WORKDIR /opt/app, accessible as $WORKDIR as well
CMD ["yarn", "start"]
USER hmcts

Nota Bene:

  • These images are primarily aimed at application runtimes, nothing prevents the use of other intermediate images to build your projects.
  • By default when the image is initially launched it will run under the context of the hmcts user. However you may have to switch to the root user to install OS dependencies.
  • The distroless nodeJS base image has been ruled out as it is still pretty experimental

Sample use

### base image ###
FROM hmctspublic.azurecr.io/base/node:8-stretch-slim as base
COPY package.json yarn.lock ./
RUN yarn install

### runtime image ###
FROM base as runtime
COPY . .
# make sure you use the hmcts user
USER hmcts

You can also leverage on alpine distributions to create smaller runtime images:

Simple:

# ---- Dependencies image ----
FROM hmctspublic.azurecr.io/base/node:10-alpine as base
COPY --chown=hmcts:hmcts package.json yarn.lock ./
RUN yarn install --production

# ---- Runtime image ----
FROM base as runtime
COPY . .
EXPOSE 3000

More complex example:

FROM hmctspublic.azurecr.io/base/node:10-alpine as base

COPY package.json yarn.lock ./

FROM base as build

USER root
RUN apk add python2 make g++
USER hmcts

RUN yarn && npm rebuild node-sass

COPY . .
RUN yarn setup && rm -r node_modules/ && yarn install --production && rm -r ~/.cache/yarn

FROM base as runtime
COPY --from=build $WORKDIR ./
USER hmcts
EXPOSE 3000

Troubleshooting

Permission issues when I install apk/apt dependencies

Apk/apt packages installation requires the root user so you may switch temporarily to this user. e.g.:

### build image (Debian) ###
FROM hmctspublic.azurecr.io/base/node:10-stretch-slim as base

USER root
RUN apt-get update && apt-get install ...
USER hmcts

COPY package.json yarn.lock ./
...

Yarn install fails because of permission issues

Depending on the post-installation steps, some script might need permissions on files owned by the root user. If this is the case, you can copy files from the host as hmcts user:

...
COPY --chown=hmcts:hmcts package.json yarn.lock .
...

Building images locally

$ make

This will generate the right tags so that you can use those images to build other nodejs-based projects by HMCTS.

Building images for sandbox

Sandbox is as its named, a sandbox registry. Thus, the base images are not automatically pushed in the sandbox registry hmctssandbox.

However you can still push them from your workstation using the following command:

$ make sandbox

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Base nodeJS images for HMCTS applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile 41.7%
  • Shell 29.5%
  • Makefile 28.8%