Skip to content

Commit

Permalink
Use extension to check running in container
Browse files Browse the repository at this point in the history
The runningInContainer check is now run through the extension.

Removed the old code that made the checks using JS.
  • Loading branch information
luismiramirez committed Jan 4, 2022
1 parent 1f67da7 commit 7882541
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 1 addition & 25 deletions packages/nodejs/src/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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
}
}
7 changes: 7 additions & 0 deletions packages/nodejs/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ export class Extension {
return {}
}
}

/**
* Determines if the app is running inside a container
*/
public runningInContainer(): boolean {
return extension.runningInContainer()
}
}

0 comments on commit 7882541

Please sign in to comment.