Skip to main content
Version: 4.8

Node.js

Node.js Application Stack

The Node.js application stack is used to build and deploy Node.js applications and produce deployment-ready containers for the SCALE environment.

The containers produced in this application stack share common requirements with other application stacks deployed to the SCALE environment. These shared requirements include:

  • Security scanning for any vulnerabilities
  • Code coverage scanning for test quality
  • Staging of the application container in the appropriate Docker container repositories and tagged according to SCALE conventions
  • Completion of Unit Testing and User Acceptance Testing
  • Gated approvals before allowing deployments into pre-production and production environments
  • Audit trail and history of deployment within the SCALE CI/CD Pipeline

Because of the above-listed requirements, the Node.js application stack is provided in order to support the build and deployment of Node.js applications in a manner that integrates with SCALE requirements and processes. The flow of deployment includes first a Continuous Integration stage of processing in a pipeline prior to deployment in the Continuous Deployment stages. The Continuous Integration stage focuses on building the application, running scans to check for test coverage and security vulnerabilities, and staging the container in the appropriate Docker repository ready for deployment. Subsequent pipeline stages deploy the application to the appropriate target Kubernetes spaces.

For details on getting started, see getting started.

For details on repository structure, see repository structure.

The source directory contains boilerplate code creating a Node.js application using the 'hapi' framework. This can be changed to the user's preference by updating the package.json file.

For details on application configuration, see application configuration.

For details on CI/CD pipelines, see CI/CD pipelines.

Upgrading to Pipeline v4.7

Note: Please refer to v4.4 of the Nodejs documentation for details on Node upgrade. Please note this version of pipeline is backward compatible with all versions of Node.

For details on upgrading to Pipeline v4.7, see upgrading to Pipeline v4.7.

Custom Modules in the Application Build Process

The process of building a node.js application usually requires downloading, via the Node Package Manager (npm), various application modules which are normally public accessible modules housed in an internet-based registry at npmjs.org (or a mirror site). In some cases, it may be necessary to include modules developed and stored locally within the NetApp environment. In these cases, the configuration for npm must be modified to point to an npm registry within the NetApp network. As this application build takes place as part of the build of the container to be deployed into SCALE, a modification of the npm configuration within the Docker container is needed at build time.

In order to modify the npm configuration to point to a local npm registry, apply the following steps (all files referenced are in the top directory of the application's source code repository):

  1. Within the azure-pipelines.yml file, set the parameters.nodejs.npmrc to true, as follows (this section of the YAML code immediately follows the template reference to pipeline/nodejs/init.yml):
      parameters:
nodejs:
npmrc: true
  1. Update the application's Dockerfile to include the following line after the COPY command for the package.json file:
      COPY $SOURCE/npm.npmrc .npmrc
  1. Create a new file called npm.npmrc (again, in the same top-level directory of the source code repository) containing the instructions to modify the npm configuration, for example:
      registry=https://artifactory.devops.netapp.com/artifactory/api/npm/npm-ngdc/
always-auth=true

Note that the .npmrc file is a standard file used by npm to provide initial configuration settings to the npm command. It is generated automatically by the CI/CD pipeline in order, among other things, to set credentials for access to local repositories.

With the above-listed changes committed, the YAML changes in azure-pipelines.yml will instruct the Continuous Integration stage of the CI/CD pipeline to add to the .npmrc file within the Docker container the contents of the new npm.npmrc file. If there is a need to reference different npm registries within the same node.js build, expand the npm.npmrc file with additional configuration lines, npm scope references, etc. as needed and in keeping with standard npm configuration rules.

For details on pipeline definition, see pipeline definition.

Application-Specific Pipeline Configuration

The extends YAML object is a complex object consisting of additional YAML objects. This object is used to extend the pipeline logic (referenced by the repository defined in the resources object) by (a) referencing the correct appstack pipeline entry point and (b) passing a set of YAML objects as parameters to influence the behavior of the pipeline to meet an application teams specific needs.

The extends YAML object consists of 2 objects beneath it:

  • template
  • parameters

The template YAML object is a single value set to the initial entry point for the v4.7 pipeline for the Node.js appstack, so it should always be defined as follows:

extends:
template: devops/nodejs.yml@spaces

The parameters YAML object is defined immediately following the template object and at the same indentation level. This is the object that requires the most attention and definition to be set up.

The parameters YAML object includes multiple parameters which can be used to configure CI/CD pipeline. Primarily this object contains parameters used for application builds. A typical setting in here would be to define appVersion used to build the application, looking like the following (including all of the extends object preceding it):

extends:
template: devops/nodejs.yml@spaces
parameters:
appVersion: 4.7.x

Node.js version configuration

Generally, CI/CD pipeline uses latest LTS version of Node.js for building Node.js application. This can be overridden by configuring Node.js version as follows:

extends:
template: devops/nodejs.yml@spaces
parameters:
nodejs:
version: '18'

For details on defining hostspaces, see defining hostspaces.

For details on skipping deployments, see skipping deployments.

For details on Horizontal Pod Autoscaler, see Horizontal Pod Autoscaler.

For details on PVC for application stacks, see PVC for application stacks.

DR changes

With the introduction of pipeline v4.7, we have implemented DR capabilities that require changes in the Helm chart. Please refer to the document below for the necessary modifications and kindly update your Helm chart accordingly.

Getting Started with DR

Please refer to the following document to prepare your codebase for disaster recovery.

DR Config Map and Ingress Setup

For details on Pod Anti-Affinity, see Pod Anti-Affinity.

For details on detailed pipeline configuration, see detailed pipeline configuration.

For details on Kubernetes deployment objects, see Kubernetes deployment objects.

For details on troubleshooting, see troubleshooting.