From 7882541f8e4c03bdf36a728d50dda07568a73815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luismi=20Ram=C3=ADrez?= Date: Mon, 27 Dec 2021 12:33:27 +0100 Subject: [PATCH] Use extension to check running in container The runningInContainer check is now run through the extension. Removed the old code that made the checks using JS. --- ...ion-is-now-available-from-the-extension.md | 4 +-- ...tension-now-checks-running-in-container.md | 7 +++++ packages/nodejs/src/diagnose.ts | 26 +------------------ packages/nodejs/src/extension.ts | 7 +++++ 4 files changed, 17 insertions(+), 27 deletions(-) create mode 100644 packages/nodejs/.changesets/extension-now-checks-running-in-container.md diff --git a/packages/nodejs-ext/.changesets/runningincontainer-function-is-now-available-from-the-extension.md b/packages/nodejs-ext/.changesets/runningincontainer-function-is-now-available-from-the-extension.md index f4939d09..c4fd1573 100644 --- a/packages/nodejs-ext/.changesets/runningincontainer-function-is-now-available-from-the-extension.md +++ b/packages/nodejs-ext/.changesets/runningincontainer-function-is-now-available-from-the-extension.md @@ -3,5 +3,5 @@ bump: "patch" type: "add" --- -RunningInContainer function is now available from the extension. It checks if the agent is running -in a container. +Implement the `RunningInContainer` function available in the extension. It is +used to check if the agent is running in a container. diff --git a/packages/nodejs/.changesets/extension-now-checks-running-in-container.md b/packages/nodejs/.changesets/extension-now-checks-running-in-container.md new file mode 100644 index 00000000..3403facd --- /dev/null +++ b/packages/nodejs/.changesets/extension-now-checks-running-in-container.md @@ -0,0 +1,7 @@ +--- +bump: "patch" +type: "change" +--- + +The extension is now responsible of determining if the process is running in a container. This check +was previously made by the Node.js integration code. diff --git a/packages/nodejs/src/diagnose.ts b/packages/nodejs/src/diagnose.ts index e934d9a5..d7f2d3eb 100644 --- a/packages/nodejs/src/diagnose.ts +++ b/packages/nodejs/src/diagnose.ts @@ -86,10 +86,7 @@ export class DiagnoseTool { language_version: process.versions.node, heroku, root: process.getuid() === 0, - // @TODO: this is pretty much just a guess right now - // it assumes docker. no jails, lxc etc. - // we'll need to adjust this a little later - running_in_container: hasDockerEnv() || hasDockerCGroup() || heroku + running_in_container: this.#extension.runningInContainer() } } @@ -327,24 +324,3 @@ function readFileOptions(path: string, bytesToRead: number) { } } } - -/** - * the following lines are borrowed from https://github.com/sindresorhus/is-docker/ - * thanks sindre! <3 - */ -function hasDockerEnv(): boolean { - try { - fs.statSync("/.dockerenv") - return true - } catch (_) { - return false - } -} - -function hasDockerCGroup(): boolean { - try { - return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker") - } catch (_) { - return false - } -} diff --git a/packages/nodejs/src/extension.ts b/packages/nodejs/src/extension.ts index 721a57f9..bb495451 100644 --- a/packages/nodejs/src/extension.ts +++ b/packages/nodejs/src/extension.ts @@ -66,4 +66,11 @@ export class Extension { return {} } } + + /** + * Determines if the app is running inside a container + */ + public runningInContainer(): boolean { + return extension.runningInContainer() + } }