Class: Docker::Cli::DockerRunLog
- Inherits:
-
Object
- Object
- Docker::Cli::DockerRunLog
- Includes:
- Singleton, TR::CondUtils
- Defined in:
- lib/docker/cli/docker_run_log.rb
Instance Method Summary collapse
- #all_logs ⇒ Object
- #delete_image(image, opts = {}) ⇒ Object
- #digest_file(path) ⇒ Object
- #dockerfile_images(df) ⇒ Object
- #has_dockerfile_built_to_image?(df) ⇒ Boolean
- #has_dockerfile_seen_before?(df) ⇒ Boolean
- #image_containers(image) ⇒ Object
- #image_has_containers?(image) ⇒ Boolean
- #log(image, container, opts = {}) ⇒ Object
- #log_dockerfile_image(df, image) ⇒ Object
- #update_last_run(image, cont) ⇒ Object
Instance Method Details
#all_logs ⇒ Object
124 125 126 |
# File 'lib/docker/cli/docker_run_log.rb', line 124 def all_logs logfile.freeze end |
#delete_image(image, opts = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/docker/cli/docker_run_log.rb', line 99 def delete_image(image, opts = {}) if logfile[image].nil? or is_empty?(logfile[image]) logfile.delete(image) elsif not_empty?(opts) and opts[:force] == true logfile.delete(image) else raise NonEmptyRecord, "Image #{image} has #{logfile[image].length} container(s). Remove image failed." end end |
#digest_file(path) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/docker/cli/docker_run_log.rb', line 87 def digest_file(path) if not_empty?(path) and File.exist?(path) Cli.digest_bin(File.read(path)) else "" end end |
#dockerfile_images(df) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docker/cli/docker_run_log.rb', line 57 def dockerfile_images(df) if File.exist?(df) d = digest_file(df) else d = df end if (logfile[:dockerfile_images].nil? or logfile[:dockerfile_images][d].nil?) [] else logfile[:dockerfile_images][d] end end |
#has_dockerfile_built_to_image?(df) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/docker/cli/docker_run_log.rb', line 45 def has_dockerfile_built_to_image?(df) if not_empty?(df) if File.exist?(df) d = digest_file(df) else d = df end not (logfile[:dockerfile_images].nil? or logfile[:dockerfile_images][d].nil?) end end |
#has_dockerfile_seen_before?(df) ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/docker/cli/docker_run_log.rb', line 71 def has_dockerfile_seen_before?(df) logger.debug "dockerfile_seen_before? #{df}" if not_empty?(df) and File.exist?(df) d = Cli.digest_bin(File.read(df)) logger.debug "Digest : #{d}" logger.debug "Record : #{logfile[:dockerfile_images]}" if not logfile[:dockerfile_images].nil? logfile[:dockerfile_images].include?(d) else false end else false end end |
#image_containers(image) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/docker/cli/docker_run_log.rb', line 116 def image_containers(image) if not logfile[image].nil? logfile[image] else [] end end |
#image_has_containers?(image) ⇒ Boolean
95 96 97 |
# File 'lib/docker/cli/docker_run_log.rb', line 95 def image_has_containers?(image) not logfile[image].nil? and logfile[image].length > 0 end |
#log(image, container, opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/docker/cli/docker_run_log.rb', line 14 def log(image, container, opts = {}) if not_empty?(image) and not_empty?(container) logfile[image] = [] if logfile[image].nil? cont = { container: container, created_at: Time.now.to_i, last_run: Time.now.to_i } cont = cont.merge(opts) if not_empty?(opts) logfile[image] << cont write end end |
#log_dockerfile_image(df, image) ⇒ Object
def log_dockerfile(df)
if not_empty?(df) and File.exist?(df)
logfile[:dockerfile_signature] = [] if logfile[:dockerfile_signature].nil?
d = digest_file(df)
if not logfile[:dockerfile_signature].include?(d)
logfile[:dockerfile_signature] << digest.hexdigest(File.read(df))
end
write
end
end
35 36 37 38 39 40 41 42 43 |
# File 'lib/docker/cli/docker_run_log.rb', line 35 def log_dockerfile_image(df, image) if not_empty?(df) and File.exist?(df) and not_empty?(image) logfile[:dockerfile_images] = { } if logfile[:dockerfile_images].nil? d = digest_file(df) logfile[:dockerfile_images][d] = [] if logfile[:dockerfile_images][d].nil? logfile[:dockerfile_images][d] << image write end end |
#update_last_run(image, cont) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/docker/cli/docker_run_log.rb', line 109 def update_last_run(image, cont) if not logfile[image].nil? and not logfile[image][cont].nil? logfile[image][cont][:last_run] = Time.now.to_i write end end |