Class: Kamal::Dev::Devcontainer
- Inherits:
-
Object
- Object
- Kamal::Dev::Devcontainer
- Defined in:
- lib/kamal/dev/devcontainer.rb
Overview
Represents a single devcontainer instance with its parsed configuration
Provides methods to access Docker configuration and generate Docker run commands.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#mounts ⇒ Object
readonly
Returns the value of attribute mounts.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
-
#secrets ⇒ Object
readonly
Returns the value of attribute secrets.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
-
#docker_run_command(name:) ⇒ Array<String>
Generate full Docker run command array.
-
#docker_run_flags ⇒ Array<String>
Generate Docker run flags from configuration.
-
#initialize(config) ⇒ Devcontainer
constructor
Initialize devcontainer with parsed configuration.
Constructor Details
#initialize(config) ⇒ Devcontainer
Initialize devcontainer with parsed configuration
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kamal/dev/devcontainer.rb', line 35 def initialize(config) @image = config[:image] @ports = config[:ports] || [] @mounts = config[:mounts] || [] @env = config[:env] || {} = config[:options] || [] @user = config[:user] @workspace = config[:workspace] @secrets = config[:secrets] || {} end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def env @env end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def image @image end |
#mounts ⇒ Object (readonly)
Returns the value of attribute mounts.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def mounts @mounts end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def ports @ports end |
#secrets ⇒ Object (readonly)
Returns the value of attribute secrets.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def secrets @secrets end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def user @user end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
22 23 24 |
# File 'lib/kamal/dev/devcontainer.rb', line 22 def workspace @workspace end |
Instance Method Details
#docker_run_command(name:) ⇒ Array<String>
Generate full Docker run command array
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/kamal/dev/devcontainer.rb', line 102 def docker_run_command(name:) command = ["docker", "run"] # Run in detached mode command << "-d" # Container name command << "--name" command << name # Add all flags command.concat(docker_run_flags) # Image must be last command << @image command end |
#docker_run_flags ⇒ Array<String>
Generate Docker run flags from configuration
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kamal/dev/devcontainer.rb', line 49 def docker_run_flags flags = [] # Port mappings (-p HOST:CONTAINER) @ports.each do |port| flags << "-p" flags << "#{port}:#{port}" end # Volume mounts (-v SOURCE:TARGET) @mounts.each do |mount| flags << "-v" flags << "#{mount[:source]}:#{mount[:target]}" end # Environment variables (-e KEY=VALUE) @env.each do |key, value| flags << "-e" flags << "#{key}=#{value}" end # Secrets (Base64-encoded) (-e KEY_B64=encoded_value) @secrets.each do |key, encoded_value| flags << "-e" flags << "#{key}_B64=#{encoded_value}" end # Docker run options (--cpus=2, --memory=4g, etc.) flags.concat() # Remote user (--user USER) if @user flags << "--user" flags << @user end # Workspace folder (-w /workspace) if @workspace flags << "-w" flags << @workspace end flags end |