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- VITE_PORT_BASE =
GDK's vite dev server default port. Unlike SSH/web, the vite port is published host:N -> container:N with the same number on both sides: GitLab embeds absolute asset URLs (http://gdk.local:<vite_port>/...) in its HTML, so the port the browser dials must be the port vite listens on inside the box. Each box gets the next free number from this base and its GDK is reconfigured to serve vite there.
3038- 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.
58 59 60 61 62 |
# File 'lib/gdkbox/config.rb', line 58 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.
56 57 58 |
# File 'lib/gdkbox/config.rb', line 56 def home @home end |
Instance Method Details
#anthropic_api_key ⇒ Object
Back-compat convenience for the Anthropic key.
137 138 139 |
# File 'lib/gdkbox/config.rb', line 137 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.
131 132 133 134 |
# File 'lib/gdkbox/config.rb', line 131 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
64 65 66 |
# File 'lib/gdkbox/config.rb', line 64 def boxes_dir File.join(home, "boxes") end |
#config_file ⇒ Object
Path to the optional user config file.
82 83 84 |
# File 'lib/gdkbox/config.rb', line 82 def config_file File.join(home, "config.yml") end |
#container_name(name) ⇒ Object
158 159 160 |
# File 'lib/gdkbox/config.rb', line 158 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.
117 118 119 120 |
# File 'lib/gdkbox/config.rb', line 117 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.
109 110 111 112 |
# File 'lib/gdkbox/config.rb', line 109 def default_harness key = file_settings["harness"].to_s key.empty? ? Harness.default : key end |
#default_image ⇒ Object
174 175 176 |
# File 'lib/gdkbox/config.rb', line 174 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.
104 105 106 |
# File 'lib/gdkbox/config.rb', line 104 def default_skills Array(file_settings["skills"]).map(&:to_s).reject(&:empty?) end |
#ensure_dirs! ⇒ Object
153 154 155 156 |
# File 'lib/gdkbox/config.rb', line 153 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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/gdkbox/config.rb', line 88 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.
123 124 125 |
# File 'lib/gdkbox/config.rb', line 123 def gitlab_checkout_path File.join(remote_path, "gitlab") end |
#keys_dir ⇒ Object
68 69 70 |
# File 'lib/gdkbox/config.rb', line 68 def keys_dir File.join(home, "keys") end |
#lock_path ⇒ Object
Lock file guarding host-port allocation against concurrent gdkbox up.
77 78 79 |
# File 'lib/gdkbox/config.rb', line 77 def lock_path File.join(home, "create.lock") end |
#private_key_path ⇒ Object
141 142 143 |
# File 'lib/gdkbox/config.rb', line 141 def private_key_path File.join(keys_dir, "id_ed25519") end |
#public_key_path ⇒ Object
145 146 147 |
# File 'lib/gdkbox/config.rb', line 145 def public_key_path "#{private_key_path}.pub" end |
#remote_path ⇒ Object
170 171 172 |
# File 'lib/gdkbox/config.rb', line 170 def remote_path REMOTE_PATH end |
#ssh_config_path ⇒ Object
72 73 74 |
# File 'lib/gdkbox/config.rb', line 72 def ssh_config_path File.join(home, "ssh_config") end |
#ssh_host_alias(name) ⇒ Object
162 163 164 |
# File 'lib/gdkbox/config.rb', line 162 def ssh_host_alias(name) "#{HOST_ALIAS_PREFIX}#{name}" end |
#ssh_user ⇒ Object
166 167 168 |
# File 'lib/gdkbox/config.rb', line 166 def ssh_user SSH_USER end |
#user_ssh_config ⇒ Object
149 150 151 |
# File 'lib/gdkbox/config.rb', line 149 def user_ssh_config File.join(Dir.home, ".ssh", "config") end |