docklean 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e08fdae44e24ee61411f6415b09d2b4c08b78fc5
4
- data.tar.gz: 58057df00b5af5b57e762906c934d27238126fc3
3
+ metadata.gz: 349b9e4041f0ddbed4accca5c002570e37fe4219
4
+ data.tar.gz: b0d4225514974336fe241e9fa2e669ba3e01be2e
5
5
  SHA512:
6
- metadata.gz: 106f878dbfeeb6f962b2c7e7eb25a8c706a7192984115ed7cf3846423b3cc526c42cc6bfdd896e272b2b4b5ff28fec5c5187d9d28773526467ce7e23a8209a65
7
- data.tar.gz: 15343acbc4ca3aae7e8ffadc3cf9cbe063fb2182b4c1c8557289e67f9e2af9d84e5b710e2ac3d688008abb9cd1accbcd6fc2687c89b2b9bedd381b383604fd8f
6
+ metadata.gz: fb0c570dad3d748eff59399e7020de956fefda9fce1d096865f2fdc122294bd33cbe9463a0e86488639c22c5ad151e0542bde4463368b3c51c90098b63c17436
7
+ data.tar.gz: ece41b9225f29af640f9c5fec74c038ab7870e7ed6aaa11558135340bc0c4c052fb359cc2e985b2b0cf88b05a1788e1a049c43adb9cc18e207b97c783bb2aaae
@@ -1,3 +1,4 @@
1
1
  log_level: 'debug'
2
- docker_bin: '/usr/sbin/docker'
3
- max_age: 300
2
+ docker_bin: '/usr/bin/docker'
3
+ max_age: 86400 # 1 day
4
+ keep_filter: 'DATA_*' # do not delete containers matching regex
@@ -1,5 +1,21 @@
1
- #!/usr/bin/ruby
2
- require 'date'
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Author: Tom Llewellyn-Smith <tom@onixconsulting.co.uk>
4
+ # Copyright: © Onix Consulting Limited 2012-2015. All rights reserved.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
3
19
  require 'docklean'
4
20
  require 'optparse'
5
21
 
@@ -15,8 +31,5 @@ config = options[:config] ||= 'bin/config.yaml'
15
31
 
16
32
  docklean = Docklean.new(config)
17
33
 
18
- docklean.get_containers()
19
- docklean.cleanup_containers()
20
- docklean.cleanup_images()
21
-
22
- puts docklean.dump()
34
+ # cleans up all containers older than max_age and removes unused images
35
+ docklean.scrub()
@@ -16,6 +16,7 @@
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
+ require 'date'
19
20
  require 'docklean/base'
20
21
  require 'docklean/conf'
21
22
  require 'docklean/containers'
@@ -23,5 +23,11 @@ class Docklean
23
23
  puts msg.chomp
24
24
  end
25
25
  end
26
+
27
+ def scrub
28
+ # cleans up containers/images
29
+ self.cleanup_containers()
30
+ self.cleanup_images()
31
+ end
26
32
  end
27
33
  end
@@ -18,13 +18,13 @@
18
18
  #
19
19
  class Docklean
20
20
  module Containers
21
- ## containers = {cont_id: {image_id => '', status => ''}}
22
21
  def get_containers()
23
22
  @containers = Hash.new()
24
23
  %x{#{@docker_bin} ps --no-trunc=true -q -a}.split(/\n/).each do |container|
25
24
  container.chomp()
26
- image_id,is_running,start_at,end_at = %x{#{@docker_bin} inspect --format "{{.Image}};{{.State.Running}};{{.State.StartedAt}};{{.State.FinishedAt}}" #{container}}.split(/;/)
25
+ name,image_id,is_running,start_at,end_at = %x{#{@docker_bin} inspect --format "{{.Name}};{{.Image}};{{.State.Running}};{{.State.StartedAt}};{{.State.FinishedAt}}" #{container}}.split(/;/)
27
26
  @containers[container.to_sym] = {
27
+ :name => name.gsub(/^\//,''),
28
28
  :image_id => image_id.chomp(),
29
29
  :is_running => is_running.chomp(),
30
30
  :start_at => DateTime.parse(start_at.chomp().to_s).strftime('%s'),
@@ -43,8 +43,14 @@ class Docklean
43
43
  when 'false'
44
44
  # check it's older than MAX_AGE
45
45
  if meta[:age] >= @max_age then
46
- %x{#{@docker_bin} rm #{container.to_s.chomp}}
47
- puts "info: deleting #{container.to_s.chomp} (container)"
46
+ # only remove container if it doesn't match keep_filter
47
+ unless meta[:name].match(%r{#{self.get_conf('keep_filter')}}) then
48
+ %x{#{@docker_bin} rm #{container.to_s.chomp}}
49
+ puts "info: deleting #{container.to_s.chomp} (container)"
50
+ else
51
+ # do not delete this image_id
52
+ @images_to_keep.push(meta[:image_id])
53
+ end
48
54
  else
49
55
  # do not delete this image_id
50
56
  @images_to_keep.push(meta[:image_id])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docklean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Llewellyn-Smith