Class: Dash::Commands::Registry

Inherits:
Base
  • Object
show all
Defined in:
lib/dash/commands/registry.rb

Constant Summary collapse

LOCAL_CONTAINER_NAME =
"dash-docker-registry"
LEGACY_LOCAL_CONTAINER_NAME =
"kamal-docker-registry"

Constants inherited from Base

Base::DOCKER_HEALTH_STATUS_FORMAT, Base::NO_HEALTHCHECK

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for, #ensure_docker_installed, #ensure_run_directory, #initialize, #make_directory, #make_directory_for, #read_file, #remove_directory, #remove_file, #run_over_ssh

Constructor Details

This class inherits a constructor from Dash::Commands::Base

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/dash/commands/registry.rb', line 41

def local?
  config.registry.local?
end

#login(registry_config: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/dash/commands/registry.rb', line 5

def (registry_config: nil)
  registry_config ||= config.registry

  return if registry_config.local?

  docker :login,
    registry_config.server,
    "-u", sensitive(Dash::Utils.escape_shell_value(registry_config.username)),
    "-p", sensitive(Dash::Utils.escape_shell_value(registry_config.password))
end

#logout(registry_config: nil) ⇒ Object



16
17
18
19
20
# File 'lib/dash/commands/registry.rb', line 16

def logout(registry_config: nil)
  registry_config ||= config.registry

  docker :logout, registry_config.server
end

#removeObject

The legacy container is torn down alongside the current one so an operator's laptop doesn't keep a stray kamal-docker-registry holding the local port after upgrading. Dash::Cli::Registry#remove already runs this with raise_on_non_zero_exit: false, so a missing container of either name is fine.



35
36
37
38
39
# File 'lib/dash/commands/registry.rb', line 35

def remove
  chain \
    combine(docker(:stop, LOCAL_CONTAINER_NAME), docker(:rm, LOCAL_CONTAINER_NAME)),
    combine(docker(:stop, LEGACY_LOCAL_CONTAINER_NAME), docker(:rm, LEGACY_LOCAL_CONTAINER_NAME))
end

#setup(registry_config: nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/dash/commands/registry.rb', line 22

def setup(registry_config: nil)
  registry_config ||= config.registry

  combine \
    docker(:start, LOCAL_CONTAINER_NAME),
    docker(:run, "--detach", "-p", "127.0.0.1:#{registry_config.local_port}:5000", "--name", LOCAL_CONTAINER_NAME, "registry:3"),
    by: "||"
end