Module: DocOpsLab::Dev::DockerAware

Defined in:
lib/docopslab/dev/docker_aware.rb

Overview

Detects and provides utilities for Docker container environments.

Class Method Summary collapse

Class Method Details

.cache_mount_accessible?Boolean

True if the Docker container can access the host’s cache mount. Checks if /home/docops/.cache/docopslab exists and is readable.

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/docopslab/dev/docker_aware.rb', line 25

def cache_mount_accessible?
  cache_path = File.expand_path('~/.cache/docopslab')
  File.exist?(cache_path) && File.directory?(cache_path) && File.readable?(cache_path)
rescue StandardError
  false
end

.docker_without_cache?Boolean

True if Docker but without access to host’s cache directory. This is the case when user runs: docker run -v “$(pwd):/workspace” … without explicitly mounting ~/.cache/docopslab

Returns:

  • (Boolean)


19
20
21
# File 'lib/docopslab/dev/docker_aware.rb', line 19

def docker_without_cache?
  running_in_docker? && !cache_mount_accessible?
end

.running_in_docker?Boolean

True if running inside a Docker container. Checks:

1. DOCOPSLAB_IN_DOCKER environment variable (set in Dockerfile)
2. /.dockerenv marker file (standard Docker indicator)

Returns:

  • (Boolean)


12
13
14
# File 'lib/docopslab/dev/docker_aware.rb', line 12

def running_in_docker?
  ENV['DOCOPSLAB_IN_DOCKER'] == 'true' || File.exist?('/.dockerenv')
end

.workspace_cache_pathObject

Workspace-relative cache path for Docker-only users. Returns path like /workspace/.docopslab-cache/



34
35
36
# File 'lib/docopslab/dev/docker_aware.rb', line 34

def workspace_cache_path
  File.join('/workspace', '.docopslab-cache')
end