push
github
498 of 687 branches covered (72.49%)
Branch coverage included in aggregate %.
0 of 27 new or added lines in 2 files covered. (0.0%)
293 existing lines in 26 files now uncovered.2828 of 3611 relevant lines covered (78.32%)
28.46 hits per line
1 |
import fs from "fs/promises";
|
2✔ |
2 |
|
|
3 |
let containerEnv: boolean | undefined; |
2✔ |
4 |
|
|
5 |
export async function detectContainerEnv(): Promise<boolean> {
|
|
6 |
if (containerEnv !== undefined) {
|
|
7 |
return containerEnv;
|
17✔ |
8 |
} |
17✔ |
9 |
|
|
10 |
const detect = async function (): Promise<boolean> {
|
|
11 |
if (process.platform !== "linux") { |
|
12 |
return false; // we only support linux containers for now |
× |
UNCOV
13
|
} |
× |
14 |
|
|
15 |
if (process.env.container) {
|
|
16 |
return true; |
× |
UNCOV
17
|
} |
× |
18 |
|
|
19 |
const exists = await Promise.all(
|
30✔ |
20 |
["/.dockerenv", "/run/.containerenv", "/var/run/.containerenv"].map(async (file) => { |
|
21 |
try {
|
90✔ |
22 |
await fs.access(file); |
|
23 |
return true; |
× |
24 |
} catch {
|
90✔ |
25 |
return false; |
90✔ |
26 |
} |
90✔ |
27 |
}) |
30✔ |
28 |
); |
30✔ |
29 |
|
|
30 |
return exists.includes(true); |
30✔ |
31 |
}; |
30✔ |
32 |
|
|
33 |
containerEnv = await detect(); |
30✔ |
34 |
return containerEnv;
|
30✔ |
35 |
} |
30✔ |