Skip to content
README.md 2.04 KiB
Newer Older
Ivan Artiukhov's avatar
Ivan Artiukhov committed
# Node
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
> Install, lint and test NodeJS modules
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Getting Started
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Include the following in `.gitlab-ci.yml`:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: "gitlab.arm.com/ci/component/node@<version>"
Ivan Artiukhov's avatar
Ivan Artiukhov committed
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Installs the NPM modules and caches them. Executes `npm run lint`. Executes `npm test` All of those are then combined together using the 
```yaml
    extends: .node-install
    script:
      - !reference [.node-fragment, lint]
      - !reference [.node-fragment, test]
Ivan Artiukhov's avatar
Ivan Artiukhov committed
```

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Purpose
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Node projects have a defined workflow through NPM. The components ease setting up the workflow.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Usage
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
### Image
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The `.node` job will use the `node` container from this repo for the same tag as the component version used.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The image can be overridden with the [image][image] keyword in the `.gitlab-ci.yml`:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
inputs: 
  image: registry.gitlab.arm.com/ci/component/node
  
job:
  extends: .node-install
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
### Global Installation
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The `node` image has rootless global package installs configured.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Global packages can be installed as the default unpriviledge `ci` user.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
### Configuration
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `SCOPES`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
A space separated list of GitLab CI scopes to add authentication for.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
It defaults to the current project group scope.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
To install packages from other GitLab scopes (groups) add them to this variable:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: "gitlab.arm.com/ci/component/node@<version>"
    inputs:
      SCOPES: "build some-other-group"
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
  install:
    extends: .node-install 
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `OMIT`/`INCLUDE`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
These space separated variables allow certain package groups to be installed:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: "gitlab.arm.com/ci/component/node@<version>"
    inputs:
      OMIT: "dev"
      INCLUDE: "optional prod"

  install:
    extends: .node-install
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
They correspond to the `--omit`/`--include` arguments to `npm`.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `CACHE_PREFIX`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The prefix to add to the NodeJS cache, which defaults to `nodejs-${VERSION}`.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
This can be used to create different caches.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
It will always be invalidated when `package-lock.json` changes.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
[image]: https://docs.gitlab.com/ee/ci/yaml/#image