Class: Dockly::Docker::Registry
- Inherits:
-
Object
- Object
- Dockly::Docker::Registry
- Includes:
- Util::DSL, Util::Logger::Mixin
- Defined in:
- lib/dockly/docker/registry.rb
Constant Summary collapse
- DEFAULT_SERVER_ADDRESS =
'https://index.docker.io/v1/'
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #config_file ⇒ Object
- #default_server_address? ⇒ Boolean
- #generate_config_file! ⇒ Object
- #to_h ⇒ Object
Instance Method Details
#authenticate! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dockly/docker/registry.rb', line 17 def authenticate! return unless authentication_required? @password ||= ENV['DOCKER_REGISTRY_PASSWORD'] ensure_present! :email, :password, :server_address, :username debug "Attempting to authenticate at #{server_address}" ::Docker.authenticate!(self.to_h) info "Successfully authenticated at #{server_address} with username #{username}" rescue ::Docker::Error::AuthenticationError raise "Could not authenticate at #{server_address} with username #{username}" end |
#config_file ⇒ Object
34 35 36 |
# File 'lib/dockly/docker/registry.rb', line 34 def config_file @config_file ||= File.join('build', 'docker', 'registry', '.dockercfg') end |
#default_server_address? ⇒ Boolean
30 31 32 |
# File 'lib/dockly/docker/registry.rb', line 30 def default_server_address? server_address == DEFAULT_SERVER_ADDRESS end |
#generate_config_file! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dockly/docker/registry.rb', line 38 def generate_config_file! return unless authentication_required? @password ||= ENV['DOCKER_REGISTRY_PASSWORD'] ensure_present! :username, :password, :email, :server_address auth = { server_address => { :auth => Base64.encode64("#{username}:#{password}"), :email => email.to_s } }.to_json FileUtils.mkdir_p(File.dirname(config_file)) File.open(config_file, 'w') { |file| file.write(auth) } end |
#to_h ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/dockly/docker/registry.rb', line 54 def to_h { 'serveraddress' => server_address, 'email' => email, 'username' => username, 'password' => password } end |