Class: Kamal::Dev::DevcontainerParser
- Inherits:
-
Object
- Object
- Kamal::Dev::DevcontainerParser
- Defined in:
- lib/kamal/dev/devcontainer_parser.rb
Overview
Parses VS Code devcontainer.json specifications into Docker configuration
Handles JSON with comments (// and /* */), extracts container properties, and transforms them into a standardized configuration hash for Docker deployment.
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#compose_file_path ⇒ String?
Get path to compose file if present.
-
#initialize(file_path) ⇒ DevcontainerParser
constructor
Initialize parser with devcontainer.json file path.
-
#parse ⇒ Hash
Parse devcontainer.json and return standardized config hash.
-
#uses_compose? ⇒ Boolean
Check if devcontainer uses Docker Compose.
Constructor Details
#initialize(file_path) ⇒ DevcontainerParser
Initialize parser with devcontainer.json file path
25 26 27 |
# File 'lib/kamal/dev/devcontainer_parser.rb', line 25 def initialize(file_path) @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
20 21 22 |
# File 'lib/kamal/dev/devcontainer_parser.rb', line 20 def file_path @file_path end |
Instance Method Details
#compose_file_path ⇒ String?
Get path to compose file if present
Returns path relative to .devcontainer/ directory
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kamal/dev/devcontainer_parser.rb', line 79 def compose_file_path return nil unless uses_compose? content = File.read(@file_path) clean_content = strip_comments(content) devcontainer_json = JSON.parse(clean_content) compose_file = devcontainer_json["dockerComposeFile"] return nil unless compose_file # Handle array of compose files (use first one) compose_file = compose_file.first if compose_file.is_a?(Array) # Resolve path relative to .devcontainer directory devcontainer_dir = File.dirname(@file_path) File.join(devcontainer_dir, compose_file) rescue nil end |
#parse ⇒ Hash
Parse devcontainer.json and return standardized config hash
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kamal/dev/devcontainer_parser.rb', line 43 def parse content = File.read(@file_path) clean_content = strip_comments(content) devcontainer_json = JSON.parse(clean_content) validate_required_properties!(devcontainer_json) { image: extract_image(devcontainer_json), ports: extract_ports(devcontainer_json), mounts: extract_mounts(devcontainer_json), env: extract_env(devcontainer_json), options: (devcontainer_json), user: extract_user(devcontainer_json), workspace: extract_workspace(devcontainer_json) } end |
#uses_compose? ⇒ Boolean
Check if devcontainer uses Docker Compose
64 65 66 67 68 69 70 71 72 |
# File 'lib/kamal/dev/devcontainer_parser.rb', line 64 def uses_compose? content = File.read(@file_path) clean_content = strip_comments(content) devcontainer_json = JSON.parse(clean_content) devcontainer_json.key?("dockerComposeFile") rescue false end |