How to use is-docker - 8 common examples

To help you get started, we’ve selected a few is-docker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erikengervall / dockest / packages / dockest / src / test-helper / index.ts View on Github external
import isDocker from 'is-docker' // eslint-disable-line import/default
import { DockerComposeFile } from '../@types'
import { DOCKEST_ATTACH_TO_PROCESS, DOCKEST_HOST_ADDRESS, DEFAULT_HOST_NAME } from '../constants'
import { DockestError } from '../Errors'

const isInsideDockerContainer = isDocker()
const dockestConfig = process.env[DOCKEST_ATTACH_TO_PROCESS]

if (!dockestConfig) {
  throw new DockestError('Config not attached to process: Not executed inside dockest context')
}

const config: DockerComposeFile = JSON.parse(dockestConfig)

export const getHostAddress = () => {
  if (!isInsideDockerContainer) {
    return DEFAULT_HOST_NAME
  }

  return DOCKEST_HOST_ADDRESS
}
github zeit / next.js / packages / next / telemetry / anonymous-meta.ts View on Github external
}

  const cpus = os.cpus() || []
  const { NOW_REGION } = process.env
  traits = {
    // Software information
    systemPlatform: os.platform(),
    systemRelease: os.release(),
    systemArchitecture: os.arch(),
    // Machine information
    cpuCount: cpus.length,
    cpuModel: cpus.length ? cpus[0].model : null,
    cpuSpeed: cpus.length ? cpus[0].speed : null,
    memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)),
    // Environment information
    isDocker: isDockerFunction(),
    isNowDev: NOW_REGION === 'dev1',
    isWsl: isWslBoolean,
    isCI: ciEnvironment.isCI,
    ciName: (ciEnvironment.isCI && ciEnvironment.name) || null,
    nextVersion: process.env.__NEXT_VERSION as string,
  }

  return traits
}
github fwouts / react-screenshot-test / src / lib / renderer.tsx View on Github external
constructor(
    options: {
      port?: number;
      mode?: "default" | "local" | "docker";
    } = {}
  ) {
    this.server = new ReactComponentServer(options.port || 3037);
    switch (options.mode || "default") {
      case "local":
        this.mode = "local";
        break;
      case "docker":
        this.mode = "docker";
        break;
      default:
        this.mode = isDocker() ? "local" : "docker";
    }
    this.browser =
      this.mode === "local" ? new LocalChromeRenderer() : new DockerRenderer();
  }
github fwouts / react-screenshot-test / src / lib / screenshot-server / config.ts View on Github external
function getScreenshotMode(): "local" | "docker" | "percy" {
  if (process.env.SCREENSHOT_MODE) {
    switch (process.env.SCREENSHOT_MODE) {
      case "local":
      case "docker":
      case "percy":
        return process.env.SCREENSHOT_MODE;
      default:
        throw new Error(
          `Valid values for SCREENSHOT_MODE are 'local', 'docker' and 'percy'. Received '${process.env.SCREENSHOT_MODE}'.`
        );
    }
  }
  return isDocker() ? "local" : "docker";
}
github erikengervall / dockest / packages / dockest / src / index.ts View on Github external
public run = async (dockestServices: DockestService[]) => {
    this.config.$.perfStart = Date.now()
    this.config.$.isInsideDockerContainer = isDocker()
    this.config.$.dockestServices = dockestServices

    await bootstrap(this.config)
    await startServices(this.config)
    await waitForServices(this.config)
    await debugMode(this.config)
    const { success } = await runJest(this.config)
    await teardown(this.config)
    success ? process.exit(0) : process.exit(1)
  }
}
github miscord / miscord / src / config / FileConfig.ts View on Github external
export function getConfigDir () {
  if (isDocker()) return '/config'
  switch (process.platform) {
    case 'win32':
      return path.join(process.env.APPDATA!!, 'Miscord')
    case 'linux':
      return path.join(os.homedir(), '.config', 'Miscord')
    case 'darwin':
      return path.join(os.homedir(), 'Library', 'Application Support', 'Miscord')
    default:
      return path.join(os.homedir(), '.miscord')
  }
}
github miscord / miscord / src / logger / Logger.ts View on Github external
import timezonedDate from './timezonedDate'
import util from 'util'
import chalk from 'chalk'
import is_docker from 'is-docker'
const isDocker = is_docker()

export type Level = 'fatal' | 'error' | 'warn' | 'info' | 'start' | 'success' | 'debug' | 'trace'

const levelBadges = {
  fatal: chalk.bgWhite.red('  FATAL  '),
  error: chalk.bgRed.white('  ERROR  '),
  warn: chalk.bgYellow.black('  WARN   '),
  info: chalk.bgBlue.black('  INFO   '),
  start: chalk.bgBlue.black('  START  '),
  success: chalk.bgGreen.black(' SUCCESS '),
  debug: chalk.bgCyan.black('  DEBUG  '),
  trace: chalk.bgWhite.black('  TRACE  ')
}

const levelArrows = {
  fatal: chalk.white('›'),
github zeit / next.js / packages / next / telemetry / storage.ts View on Github external
function getStorageDirectory(distDir: string): string | undefined {
  const isLikelyEphemeral = ciEnvironment.isCI || isDockerFunction()

  if (isLikelyEphemeral) {
    return path.join(distDir, 'cache')
  }

  return undefined
}

is-docker

Check if the process is running inside a Docker container

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis

Popular is-docker functions