Class: GDKBox::Config

Inherits:
Object
  • Object
show all
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"
CONTAINER_PREFIX =
"gdkbox-"
HOST_ALIAS_PREFIX =
"gdkbox-"
SSH_USER =

Inside the official image GDK lives under the gdk user.

"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

Instance Method Summary collapse

Constructor Details

#initialize(home: nil) ⇒ Config

Returns a new instance of Config.



43
44
45
46
47
# File 'lib/gdkbox/config.rb', line 43

def initialize(home: nil)
  @home = File.expand_path(
    home || ENV["GDKBOX_HOME"] || File.join(Dir.home, ".gdkbox")
  )
end

Instance Attribute Details

#homeObject (readonly)

Returns the value of attribute home.



41
42
43
# File 'lib/gdkbox/config.rb', line 41

def home
  @home
end

Instance Method Details

#anthropic_api_keyObject

Back-compat convenience for the Anthropic key.



109
110
111
# File 'lib/gdkbox/config.rb', line 109

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.



103
104
105
106
# File 'lib/gdkbox/config.rb', line 103

def api_key(config_key)
  key = file_settings[config_key.to_s]
  key.to_s.strip.empty? ? nil : key.to_s
end

#boxes_dirObject



49
50
51
# File 'lib/gdkbox/config.rb', line 49

def boxes_dir
  File.join(home, "boxes")
end

#config_fileObject

Path to the optional user config file.



67
68
69
# File 'lib/gdkbox/config.rb', line 67

def config_file
  File.join(home, "config.yml")
end

#container_name(name) ⇒ Object



130
131
132
# File 'lib/gdkbox/config.rb', line 130

def container_name(name)
  "#{CONTAINER_PREFIX}#{name}"
end

#default_harnessObject

The default agent harness for gdkbox up, from config.yml.



94
95
96
97
# File 'lib/gdkbox/config.rb', line 94

def default_harness
  key = file_settings["harness"].to_s
  key.empty? ? Harness.default : key
end

#default_imageObject



146
147
148
# File 'lib/gdkbox/config.rb', line 146

def default_image
  ENV["GDKBOX_IMAGE"] || file_settings["image"] || DEFAULT_IMAGE
end

#default_skillsObject

Skill names/paths to transfer into every box by default, from config.yml.



89
90
91
# File 'lib/gdkbox/config.rb', line 89

def default_skills
  Array(file_settings["skills"]).map(&:to_s).reject(&:empty?)
end

#ensure_dirs!Object



125
126
127
128
# File 'lib/gdkbox/config.rb', line 125

def ensure_dirs!
  FileUtils.mkdir_p(boxes_dir)
  FileUtils.mkdir_p(keys_dir)
end

#file_settingsObject

Parsed contents of config.yml, or an empty hash when it is absent or unreadable. Memoized for the life of the Config instance.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gdkbox/config.rb', line 73

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_dirObject



53
54
55
# File 'lib/gdkbox/config.rb', line 53

def keys_dir
  File.join(home, "keys")
end

#lock_pathObject

Lock file guarding host-port allocation against concurrent gdkbox up.



62
63
64
# File 'lib/gdkbox/config.rb', line 62

def lock_path
  File.join(home, "create.lock")
end

#private_key_pathObject



113
114
115
# File 'lib/gdkbox/config.rb', line 113

def private_key_path
  File.join(keys_dir, "id_ed25519")
end

#public_key_pathObject



117
118
119
# File 'lib/gdkbox/config.rb', line 117

def public_key_path
  "#{private_key_path}.pub"
end

#remote_pathObject



142
143
144
# File 'lib/gdkbox/config.rb', line 142

def remote_path
  REMOTE_PATH
end

#ssh_config_pathObject



57
58
59
# File 'lib/gdkbox/config.rb', line 57

def ssh_config_path
  File.join(home, "ssh_config")
end

#ssh_host_alias(name) ⇒ Object



134
135
136
# File 'lib/gdkbox/config.rb', line 134

def ssh_host_alias(name)
  "#{HOST_ALIAS_PREFIX}#{name}"
end

#ssh_userObject



138
139
140
# File 'lib/gdkbox/config.rb', line 138

def ssh_user
  SSH_USER
end

#user_ssh_configObject



121
122
123
# File 'lib/gdkbox/config.rb', line 121

def user_ssh_config
  File.join(Dir.home, ".ssh", "config")
end