Class: NexusAPI::DockerManager
- Inherits:
-
Object
- Object
- NexusAPI::DockerManager
- Defined in:
- lib/nexus_api/docker_manager.rb
Instance Method Summary collapse
- #delete(image_name:, tag:) ⇒ Object
- #download(image_name:, tag:) ⇒ Object
- #exists?(image_name:, tag:) ⇒ Boolean
-
#initialize(docker:, options:) ⇒ DockerManager
constructor
A new instance of DockerManager.
- #upload(image_name:, tag:) ⇒ Object
Constructor Details
#initialize(docker:, options:) ⇒ DockerManager
Returns a new instance of DockerManager.
6 7 8 9 10 11 12 |
# File 'lib/nexus_api/docker_manager.rb', line 6 def initialize(docker:, options:) @docker = docker @username = ['username'] @password = ['password'] @pull_host = ['pull_host'] @push_host = ['push_host'] end |
Instance Method Details
#delete(image_name:, tag:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nexus_api/docker_manager.rb', line 48 def delete(image_name:, tag:) return false unless docker_valid? begin image = find_image(image_name(@pull_host, image_name, tag)) return false if image.nil? return false unless image.remove(:force => true) rescue StandardError => error puts "ERROR: #{error.inspect}" return false end true end |
#download(image_name:, tag:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nexus_api/docker_manager.rb', line 14 def download(image_name:, tag:) return false unless docker_valid? image_name = image_name(@pull_host, image_name, tag) begin @docker.pull_image(@username, @password, image_name) rescue Docker::Error::NotFoundError puts "ERROR: Failed to pull Docker image #{image_name}.\nDoes it exist in Nexus?" return false end true end |
#exists?(image_name:, tag:) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/nexus_api/docker_manager.rb', line 41 def exists?(image_name:, tag:) return false unless docker_valid? images = find_images(image_name(@pull_host, image_name, tag)) return false if images.empty? true end |
#upload(image_name:, tag:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nexus_api/docker_manager.rb', line 26 def upload(image_name:, tag:) return false unless docker_valid? begin return false unless login image = find_image(image_name(@pull_host, image_name, tag)) return false if image.nil? tag(image, @push_host, image_name, tag) image.push(nil, repo_tag: image_name(@push_host, image_name, tag)) rescue StandardError => error puts "ERROR: #{error.inspect}" return false end true end |