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`
gitlab_remote: gitlab-org/gitlab # repoint the GitLab checkout
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_gitlab_remote ⇒ Object
The git remote to point each box's GitLab checkout at, from config.yml (
gitlab_remote:), or nil to keep the image's default (the community mirror). -
#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.
-
#gitlab_checkout_path ⇒ Object
Where the GitLab repository lives inside the box.
-
#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.
50 51 52 53 54 |
# File 'lib/gdkbox/config.rb', line 50 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.
48 49 50 |
# File 'lib/gdkbox/config.rb', line 48 def home @home end |
Instance Method Details
#anthropic_api_key ⇒ Object
Back-compat convenience for the Anthropic key.
129 130 131 |
# File 'lib/gdkbox/config.rb', line 129 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.
123 124 125 126 |
# File 'lib/gdkbox/config.rb', line 123 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
56 57 58 |
# File 'lib/gdkbox/config.rb', line 56 def boxes_dir File.join(home, "boxes") end |
#config_file ⇒ Object
Path to the optional user config file.
74 75 76 |
# File 'lib/gdkbox/config.rb', line 74 def config_file File.join(home, "config.yml") end |
#container_name(name) ⇒ Object
150 151 152 |
# File 'lib/gdkbox/config.rb', line 150 def container_name(name) "#{CONTAINER_PREFIX}#{name}" end |
#default_gitlab_remote ⇒ Object
The git remote to point each box's GitLab checkout at, from config.yml
(gitlab_remote:), or nil to keep the image's default (the community
mirror). A URL or a "namespace/project" shorthand.
109 110 111 112 |
# File 'lib/gdkbox/config.rb', line 109 def default_gitlab_remote remote = file_settings["gitlab_remote"].to_s.strip remote.empty? ? nil : remote end |
#default_harness ⇒ Object
The default agent harness for gdkbox up, from config.yml.
101 102 103 104 |
# File 'lib/gdkbox/config.rb', line 101 def default_harness key = file_settings["harness"].to_s key.empty? ? Harness.default : key end |
#default_image ⇒ Object
166 167 168 |
# File 'lib/gdkbox/config.rb', line 166 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.
96 97 98 |
# File 'lib/gdkbox/config.rb', line 96 def default_skills Array(file_settings["skills"]).map(&:to_s).reject(&:empty?) end |
#ensure_dirs! ⇒ Object
145 146 147 148 |
# File 'lib/gdkbox/config.rb', line 145 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/gdkbox/config.rb', line 80 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 |
#gitlab_checkout_path ⇒ Object
Where the GitLab repository lives inside the box.
115 116 117 |
# File 'lib/gdkbox/config.rb', line 115 def gitlab_checkout_path File.join(remote_path, "gitlab") end |
#keys_dir ⇒ Object
60 61 62 |
# File 'lib/gdkbox/config.rb', line 60 def keys_dir File.join(home, "keys") end |
#lock_path ⇒ Object
Lock file guarding host-port allocation against concurrent gdkbox up.
69 70 71 |
# File 'lib/gdkbox/config.rb', line 69 def lock_path File.join(home, "create.lock") end |
#private_key_path ⇒ Object
133 134 135 |
# File 'lib/gdkbox/config.rb', line 133 def private_key_path File.join(keys_dir, "id_ed25519") end |
#public_key_path ⇒ Object
137 138 139 |
# File 'lib/gdkbox/config.rb', line 137 def public_key_path "#{private_key_path}.pub" end |
#remote_path ⇒ Object
162 163 164 |
# File 'lib/gdkbox/config.rb', line 162 def remote_path REMOTE_PATH end |
#ssh_config_path ⇒ Object
64 65 66 |
# File 'lib/gdkbox/config.rb', line 64 def ssh_config_path File.join(home, "ssh_config") end |
#ssh_host_alias(name) ⇒ Object
154 155 156 |
# File 'lib/gdkbox/config.rb', line 154 def ssh_host_alias(name) "#{HOST_ALIAS_PREFIX}#{name}" end |
#ssh_user ⇒ Object
158 159 160 |
# File 'lib/gdkbox/config.rb', line 158 def ssh_user SSH_USER end |
#user_ssh_config ⇒ Object
141 142 143 |
# File 'lib/gdkbox/config.rb', line 141 def user_ssh_config File.join(Dir.home, ".ssh", "config") end |