Module: Dkit

Defined in:
lib/dkit.rb,
lib/dkit/context.rb,
lib/dkit/project.rb,
lib/dkit/version.rb,
lib/dkit/commands.rb,
lib/dkit/container.rb,
lib/dkit/intercept.rb,
lib/dkit/shell_hook.rb

Defined Under Namespace

Modules: Commands, Container, Intercept, Project, ShellHook Classes: Context

Constant Summary collapse

DC_CONFIG =
".devcontainer/devcontainer.json"
DC_INTERCEPT =
".devcontainer/dkit-intercept"
SPECIAL_COMMANDS =
%w[code claude].freeze
VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.abort_err(msg) ⇒ Object



6
7
8
9
# File 'lib/dkit/context.rb', line 6

def abort_err(msg)
  warn "dkit: #{msg}"
  exit 1
end

.resolve!(quiet: false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dkit/context.rb', line 11

def resolve!(quiet: false)
  root = Project.find_root
  unless root
    quiet ? exit(1) : abort_err("no #{DC_CONFIG} found in #{Dir.pwd} or any parent directory")
  end

  cfg       = Container.load_dc_config(root)
  service   = cfg["service"]          || "app"
  workspace = cfg["workspaceFolder"]  || "/workspace"
  user      = cfg["remoteUser"]       || "root"

  container = Container.resolve_name(root, cfg)
  unless container
    quiet ? exit(1) : abort_err("could not determine container name for service '#{service}'")
  end

  unless Container.running?(container)
    quiet ? exit(1) : abort_err("container '#{container}' is not running. Try: dkit up")
  end

  compose_files = Array(cfg["dockerComposeFile"]).map do |f|
    File.expand_path(f, File.join(root, ".devcontainer"))
  end

  Context.new(
    project_root:  root,
    container:     container,
    user:          user,
    workspace:     workspace,
    cwd:           Container.cwd(root, workspace),
    compose_files: compose_files
  )
end