Class: GDKBox::Config
- Inherits:
-
Object
- Object
- GDKBox::Config
- Defined in:
- lib/gdkbox/config.rb
Overview
Central configuration: filesystem paths, defaults, and naming conventions.
The home directory can be overridden with the GDKBOX_HOME environment variable (useful for tests and for running multiple isolated setups).
User-tunable defaults can be set in <home>/config.yml (by default
~/.gdkbox/config.yml), for example:
# ~/.gdkbox/config.yml
image: registry.example.com/my-gdk:latest # default image for `up`
skills: # transferred into every box
- gdkbox-fleet
- code-history
Constant Summary collapse
- DEFAULT_IMAGE =
The official "GDK in a box" container image published by GitLab.
"registry.gitlab.com/gitlab-org/gitlab-development-kit/gitlab-gdk-in-a-box:main"- GDK_HOSTNAME =
The hostname GDK is configured for. It is set as the container's own hostname (so services inside the box can resolve it) and mapped to loopback in the host's /etc/hosts by HostsFile (so the host browser can follow GDK's redirects to it).
"gdk.local"- CONTAINER_PREFIX =
"gdkbox-"- HOST_ALIAS_PREFIX =
"gdkbox-"- SSH_USER =
Inside the official image GDK lives under the
gdkuser. "gdk"- REMOTE_PATH =
"/home/gdk/gitlab-development-kit"- SSH_CONTAINER_PORT =
Ports as seen from inside the container.
22- GDK_WEB_CONTAINER_PORT =
3000- SSH_PORT_BASE =
Starting points for the host-side published ports. Each new box claims the next free port at or above these bases.
2222- WEB_PORT_BASE =
3000
Instance Attribute Summary collapse
-
#home ⇒ Object
readonly
Returns the value of attribute home.
Instance Method Summary collapse
-
#anthropic_api_key ⇒ Object
Back-compat convenience for the Anthropic key.
-
#api_key(config_key) ⇒ Object
An API key read from config.yml under
config_key(e.g. "anthropic_api_key", "openai_api_key"), or nil. - #boxes_dir ⇒ Object
-
#config_file ⇒ Object
Path to the optional user config file.
- #container_name(name) ⇒ Object
-
#default_harness ⇒ Object
The default agent harness for
gdkbox up, from config.yml. - #default_image ⇒ Object
-
#default_skills ⇒ Object
Skill names/paths to transfer into every box by default, from config.yml.
- #ensure_dirs! ⇒ Object
-
#file_settings ⇒ Object
Parsed contents of config.yml, or an empty hash when it is absent or unreadable.
-
#initialize(home: nil) ⇒ Config
constructor
A new instance of Config.
- #keys_dir ⇒ Object
-
#lock_path ⇒ Object
Lock file guarding host-port allocation against concurrent
gdkbox up. - #private_key_path ⇒ Object
- #public_key_path ⇒ Object
- #remote_path ⇒ Object
- #ssh_config_path ⇒ Object
- #ssh_host_alias(name) ⇒ Object
- #ssh_user ⇒ Object
- #user_ssh_config ⇒ Object
Constructor Details
#initialize(home: nil) ⇒ Config
Returns a new instance of Config.
49 50 51 52 53 |
# File 'lib/gdkbox/config.rb', line 49 def initialize(home: nil) @home = File.( home || ENV["GDKBOX_HOME"] || File.join(Dir.home, ".gdkbox") ) end |
Instance Attribute Details
#home ⇒ Object (readonly)
Returns the value of attribute home.
47 48 49 |
# File 'lib/gdkbox/config.rb', line 47 def home @home end |
Instance Method Details
#anthropic_api_key ⇒ Object
Back-compat convenience for the Anthropic key.
115 116 117 |
# File 'lib/gdkbox/config.rb', line 115 def anthropic_api_key api_key("anthropic_api_key") end |
#api_key(config_key) ⇒ Object
An API key read from config.yml under config_key (e.g.
"anthropic_api_key", "openai_api_key"), or nil. This is a plaintext
secret on disk, so it is the lowest-priority source (a flag or the
provider's env var wins); keep config.yml mode 600 if you use it.
109 110 111 112 |
# File 'lib/gdkbox/config.rb', line 109 def api_key(config_key) key = file_settings[config_key.to_s] key.to_s.strip.empty? ? nil : key.to_s end |
#boxes_dir ⇒ Object
55 56 57 |
# File 'lib/gdkbox/config.rb', line 55 def boxes_dir File.join(home, "boxes") end |
#config_file ⇒ Object
Path to the optional user config file.
73 74 75 |
# File 'lib/gdkbox/config.rb', line 73 def config_file File.join(home, "config.yml") end |
#container_name(name) ⇒ Object
136 137 138 |
# File 'lib/gdkbox/config.rb', line 136 def container_name(name) "#{CONTAINER_PREFIX}#{name}" end |
#default_harness ⇒ Object
The default agent harness for gdkbox up, from config.yml.
100 101 102 103 |
# File 'lib/gdkbox/config.rb', line 100 def default_harness key = file_settings["harness"].to_s key.empty? ? Harness.default : key end |
#default_image ⇒ Object
152 153 154 |
# File 'lib/gdkbox/config.rb', line 152 def default_image ENV["GDKBOX_IMAGE"] || file_settings["image"] || DEFAULT_IMAGE end |
#default_skills ⇒ Object
Skill names/paths to transfer into every box by default, from config.yml.
95 96 97 |
# File 'lib/gdkbox/config.rb', line 95 def default_skills Array(file_settings["skills"]).map(&:to_s).reject(&:empty?) end |
#ensure_dirs! ⇒ Object
131 132 133 134 |
# File 'lib/gdkbox/config.rb', line 131 def ensure_dirs! FileUtils.mkdir_p(boxes_dir) FileUtils.mkdir_p(keys_dir) end |
#file_settings ⇒ Object
Parsed contents of config.yml, or an empty hash when it is absent or unreadable. Memoized for the life of the Config instance.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gdkbox/config.rb', line 79 def file_settings @file_settings ||= begin if File.file?(config_file) data = begin YAML.safe_load(File.read(config_file)) rescue StandardError nil end data.is_a?(Hash) ? data : {} else {} end end end |
#keys_dir ⇒ Object
59 60 61 |
# File 'lib/gdkbox/config.rb', line 59 def keys_dir File.join(home, "keys") end |
#lock_path ⇒ Object
Lock file guarding host-port allocation against concurrent gdkbox up.
68 69 70 |
# File 'lib/gdkbox/config.rb', line 68 def lock_path File.join(home, "create.lock") end |
#private_key_path ⇒ Object
119 120 121 |
# File 'lib/gdkbox/config.rb', line 119 def private_key_path File.join(keys_dir, "id_ed25519") end |
#public_key_path ⇒ Object
123 124 125 |
# File 'lib/gdkbox/config.rb', line 123 def public_key_path "#{private_key_path}.pub" end |
#remote_path ⇒ Object
148 149 150 |
# File 'lib/gdkbox/config.rb', line 148 def remote_path REMOTE_PATH end |
#ssh_config_path ⇒ Object
63 64 65 |
# File 'lib/gdkbox/config.rb', line 63 def ssh_config_path File.join(home, "ssh_config") end |
#ssh_host_alias(name) ⇒ Object
140 141 142 |
# File 'lib/gdkbox/config.rb', line 140 def ssh_host_alias(name) "#{HOST_ALIAS_PREFIX}#{name}" end |
#ssh_user ⇒ Object
144 145 146 |
# File 'lib/gdkbox/config.rb', line 144 def ssh_user SSH_USER end |
#user_ssh_config ⇒ Object
127 128 129 |
# File 'lib/gdkbox/config.rb', line 127 def user_ssh_config File.join(Dir.home, ".ssh", "config") end |