time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

index.js (431B)


      1 import fs from 'node:fs';
      2 import isDocker from 'is-docker';
      3 
      4 let cachedResult;
      5 
      6 // Podman detection
      7 const hasContainerEnv = () => {
      8 	try {
      9 		fs.statSync('/run/.containerenv');
     10 		return true;
     11 	} catch {
     12 		return false;
     13 	}
     14 };
     15 
     16 export default function isInsideContainer() {
     17 	// TODO: Use `??=` when targeting Node.js 16.
     18 	if (cachedResult === undefined) {
     19 		cachedResult = hasContainerEnv() || isDocker();
     20 	}
     21 
     22 	return cachedResult;
     23 }