Class: Harbinger::Analyzers::DockerComposeDetector
- Inherits:
-
Object
- Object
- Harbinger::Analyzers::DockerComposeDetector
- Defined in:
- lib/harbinger/analyzers/docker_compose_detector.rb
Overview
Detects versions from docker-compose.yml and Dockerfile
Instance Attribute Summary collapse
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Instance Method Summary collapse
-
#docker_compose_exists? ⇒ Boolean
Check if docker-compose.yml exists.
-
#dockerfile_exists? ⇒ Boolean
Check if Dockerfile exists.
-
#image_version(image_pattern) ⇒ Object
Extract version from a Docker image in docker-compose.yml e.g., “postgres:16-alpine” => “16”, “mysql:8.0” => “8.0”.
-
#initialize(project_path) ⇒ DockerComposeDetector
constructor
A new instance of DockerComposeDetector.
-
#rails_version_from_dockerfile ⇒ Object
Extract Rails version from Dockerfile (rare, but possible).
-
#ruby_version_from_dockerfile ⇒ Object
Extract Ruby version from Dockerfile e.g., “FROM ruby:3.4.7-slim” => “3.4.7”.
Constructor Details
#initialize(project_path) ⇒ DockerComposeDetector
Returns a new instance of DockerComposeDetector.
11 12 13 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 11 def initialize(project_path) @project_path = project_path end |
Instance Attribute Details
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
9 10 11 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 9 def project_path @project_path end |
Instance Method Details
#docker_compose_exists? ⇒ Boolean
Check if docker-compose.yml exists
67 68 69 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 67 def docker_compose_exists? docker_compose_path != nil end |
#dockerfile_exists? ⇒ Boolean
Check if Dockerfile exists
72 73 74 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 72 def dockerfile_exists? File.exist?(File.join(project_path, "Dockerfile")) end |
#image_version(image_pattern) ⇒ Object
Extract version from a Docker image in docker-compose.yml e.g., “postgres:16-alpine” => “16”, “mysql:8.0” => “8.0”
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 17 def image_version(image_pattern) compose = parse_docker_compose return nil unless compose services = compose["services"] return nil unless services services.each_value do |service| image = service["image"] next unless image if image.match?(/^#{image_pattern}[:\d]/) version = extract_version_from_image(image) return version if version end end nil end |
#rails_version_from_dockerfile ⇒ Object
Extract Rails version from Dockerfile (rare, but possible)
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 52 def rails_version_from_dockerfile dockerfile = read_dockerfile return nil unless dockerfile # Match patterns like: # FROM rails:7.0 # ARG RAILS_VERSION=7.0.8 match = dockerfile.match(/^FROM\s+rails:(\d+\.\d+(?:\.\d+)?)/i) return match[1] if match match = dockerfile.match(/RAILS_VERSION[=:](\d+\.\d+(?:\.\d+)?)/i) match[1] if match end |
#ruby_version_from_dockerfile ⇒ Object
Extract Ruby version from Dockerfile e.g., “FROM ruby:3.4.7-slim” => “3.4.7”
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/harbinger/analyzers/docker_compose_detector.rb', line 39 def ruby_version_from_dockerfile dockerfile = read_dockerfile return nil unless dockerfile # Match patterns like: # FROM ruby:3.4.7 # FROM ruby:3.4.7-slim # FROM ruby:3.4.7-alpine match = dockerfile.match(/^FROM\s+ruby:(\d+\.\d+(?:\.\d+)?)/i) match[1] if match end |