Skip to content

Commit

Permalink
chore: Added documentation for musl libc systems (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr authored Aug 19, 2024
1 parent 34eff77 commit 869e524
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,62 @@ $ npm install @newrelic/native-metrics --build-from-source

For more information, please see the agent [installation guide][install-node] and [compatibility and requirements][compatibility].

### Musl Libc Systems

As noted above, this module ships pre-built binaries for most standard systems,
i.e. systems based on the [GNU C Library](https://en.wikipedia.org/wiki/Glibc).
As of August 2024, Node.js does not provide "official" releases that are based
on [musl libc](https://en.wikipedia.org/wiki/Musl); such builds are only
available via the [unofficial builds](https://github.com/nodejs/unofficial-builds)
project. Therefore, if deploying to musl based systems, e.g. Alpine Linux, you
must provide a [node-gyp](https://github.com/nodejs/node-gyp) compatible build
environment.

As an example, to install and use this module on an Alpine Linux based Docker
image, we can utilize the [multi-stage build](https://docs.docker.com/build/building/multi-stage/)
pattern to build a compatible image:

**package.json**:
```json
{
"dependencies": {
"@newrelic/native-metrics": "^11.0.0"
}
}
```

**index.js**:
```js
'use strict'

const metrics = require('@newrelic/native-metrics')
console.log("gcEnabled:", metrics().gcEnabled)
```

**Dockerfile**:
```Dockerfile
FROM node:20-alpine AS builder

WORKDIR /app
COPY index.js package.json .

RUN apk add g++ make py3-pip
RUN npm install --production

FROM node:20-alpine
COPY --from=builder app/ /app/
WORKDIR /app
CMD node index.js
```

With those files in place, we can build and run the image:

```sh
$ docker build --tag demo .
$ docker run --rm -it demo
gcEnabled: true
```

## Usage

```js
Expand Down

0 comments on commit 869e524

Please sign in to comment.