Skip to content

Commit cd88ea8

Browse files
authored
feat(repo): add scarf to docker image (#3010)
* feat(repo): add scarf analytics tracking for docker image usage * fix: adjust dockerfile and scarf script * fix: update readme * fix: remove comment * fix: lint docs
1 parent 3a5c40c commit cd88ea8

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ FROM node:16-alpine
33
WORKDIR /usr/src/spectral
44

55
COPY scripts/install.sh /usr/src/spectral/
6+
COPY scripts/scarf-telemetry.js /usr/local/lib/scarf-telemetry.js
67
COPY packages/cli/package.json /usr/src/spectral/
8+
COPY packages/cli/package.json /usr/local/lib/package.json
79
RUN apk --no-cache add curl jq
810
RUN ./install.sh $(cat package.json | jq -r '.version') \
911
&& rm ./install.sh && rm ./package.json
1012
ENV NODE_ENV production
1113

12-
ENTRYPOINT [ "spectral" ]
14+
ENTRYPOINT ["sh", "-c", "node /usr/local/lib/scarf-telemetry.js & exec spectral \"$@\"", "sh"]

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ yarn global add @stoplight/spectral-cli
3434

3535
There are also [additional installation options](https://meta.stoplight.io/docs/spectral/ZG9jOjYyMDc0Mw-installation).
3636

37+
### Docker
38+
39+
<!-- make sure to update the value of `--ruleset` according to the actual location of your ruleset -->
40+
41+
```bash
42+
docker run --rm -it -v $(pwd):/tmp stoplight/spectral lint --ruleset "/tmp/.spectral.yaml" "/tmp/file.yaml"
43+
```
44+
45+
The Docker image sends a lightweight anonymous telemetry ping on startup (version + platform) to help us understand adoption. To opt out, set `DO_NOT_TRACK=1` or `SCARF_NO_ANALYTICS=true`:
46+
47+
```bash
48+
docker run --rm -it -e DO_NOT_TRACK=1 -v $(pwd):/tmp stoplight/spectral lint --ruleset "/tmp/.spectral.yaml" "/tmp/file.yaml"
49+
```
50+
3751
## 💻 Usage
3852

3953
### 1. Create a local ruleset

scripts/scarf-telemetry.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const https = require('https');
2+
3+
function reportToScarf() {
4+
if (process.env.DO_NOT_TRACK || process.env.SCARF_NO_ANALYTICS === 'true') {
5+
return;
6+
}
7+
8+
const version = require('./package.json').version;
9+
const platform = `${process.platform}-${process.arch}`;
10+
const url = `https://smartbear.gateway.scarf.sh/docker-runtime/${version}/${platform}`;
11+
12+
const req = https.get(url, { timeout: 2000 }, (res) => {
13+
res.resume();
14+
});
15+
req.on('error', () => {});
16+
req.on('timeout', () => req.destroy());
17+
}
18+
19+
reportToScarf();

0 commit comments

Comments
 (0)