Node
This guide provides a walkthrough of .razorops.yaml
for a typical Node.js based application. Our CI process is going to consist of following steps -
- Install dependencies (
npm install
ornpm ci
) - Caching dependencies for faster builds
- Execute test suite (
npm test
)
Installing dependencies¶
You can use razorci/node community docker image managed by us:
tasks:
build-deps:
runner: razorci/node # or node from official library/_node
steps:
- run: npm install --package-lock-only
tasks:
build-deps:
runner: razorci/node
steps:
- run: yarn ci
Read more how to use this image on dockerhub docs.
Tip
You can further speedup the workflow by caching npm dependencies so that every subsequent build then performs just incremental changes on top of that during npm install
which may lead to even faster builds.
Caching dependencies¶
Downloading node third-party packages/dependencies from the internet can be time-consuming, you can greatly speed up this process by caching it using an unique key. In future workflow runs, the cache will be restored so that dependencies don't need to be downloaded from remote (Yarn/Npm etc) repositories. For more information, see Caching dependencies.
tasks:
build-deps:
runner: razorci/node
steps:
# try to restore the cache by an unique key
- cache/pull: npm-cache-{{ checksum "package-lock.json" }}
- run: npm install --package-lock-only
...
# update the cache with an unique key
- cache/push:
key: npm-cache-{{ checksum "package-lock.json" }}
paths:
- node_modules
...
Execute test suite¶
This example shows two tasks running in parallel to execute unit-tests and e2e tests.
# Assuming you have `lint` and `test:e2e` defined in package.json
global:
variables:
- NODE_ENV=test
runner: razorci/node
tasks:
run-tests:
steps:
- commands:
- npm run lint
- npm test
e2e-test:
steps:
- run: npm run test:e2e
You can additionally provide environment variables and provide service dependencies to run your test suite.