Class: Aidp::Utils::DevcontainerDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/utils/devcontainer_detector.rb

Overview

Detects if AIDP is running inside a devcontainer

Uses multiple heuristics to determine container environment:

  • Environment variables (REMOTE_CONTAINERS, CODESPACES)

  • Filesystem markers (/.dockerenv, /run/.containerenv)

  • Hostname patterns

  • cgroup information

Examples:

if DevcontainerDetector.in_devcontainer?
  puts "Running in devcontainer with elevated permissions"
end

Class Method Summary collapse

Class Method Details

.container_infoHash

Get detailed container information

Returns:

  • (Hash)

    container information



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/aidp/utils/devcontainer_detector.rb', line 62

def container_info
  {
    in_devcontainer: in_devcontainer?,
    in_container: in_container?,
    container_type: container_type,
    hostname: hostname,
    docker_env: File.exist?("/.dockerenv"),
    container_env: File.exist?("/run/.containerenv"),
    cgroup_docker: cgroup_contains?("docker"),
    cgroup_containerd: cgroup_contains?("containerd"),
    remote_containers_env: ENV["REMOTE_CONTAINERS"],
    codespaces_env: ENV["CODESPACES"]
  }
end

.container_typeSymbol

Get container type (docker, podman, codespaces, vscode, unknown)

Returns:

  • (Symbol)

    container type



50
51
52
53
54
55
56
57
# File 'lib/aidp/utils/devcontainer_detector.rb', line 50

def container_type
  return :codespaces if in_codespaces?
  return :vscode if in_vscode_remote?
  return :docker if docker_container?
  return :podman if podman_container?
  return :unknown if in_container?
  :none
end

.in_codespaces?Boolean

Check if running in GitHub Codespaces

Returns:

  • (Boolean)

    true if in Codespaces



36
37
38
# File 'lib/aidp/utils/devcontainer_detector.rb', line 36

def in_codespaces?
  ENV["CODESPACES"] == "true"
end

.in_container?Boolean

Check if running inside any container (Docker, Podman, etc.)

Returns:

  • (Boolean)

    true if inside any container



29
30
31
# File 'lib/aidp/utils/devcontainer_detector.rb', line 29

def in_container?
  @in_container ||= detect_container
end

.in_devcontainer?Boolean

Check if running inside a devcontainer

Returns:

  • (Boolean)

    true if inside a devcontainer



22
23
24
# File 'lib/aidp/utils/devcontainer_detector.rb', line 22

def in_devcontainer?
  @in_devcontainer ||= detect_devcontainer
end

.in_vscode_remote?Boolean

Check if running in VS Code Remote Containers

Returns:

  • (Boolean)

    true if in VS Code Remote Containers



43
44
45
# File 'lib/aidp/utils/devcontainer_detector.rb', line 43

def in_vscode_remote?
  ENV["REMOTE_CONTAINERS"] == "true" || ENV["VSCODE_REMOTE_CONTAINERS"] == "true"
end

.reset!Object

Reset cached detection (useful for testing)



78
79
80
81
# File 'lib/aidp/utils/devcontainer_detector.rb', line 78

def reset!
  @in_devcontainer = nil
  @in_container = nil
end