docklean 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/config.yaml +3 -2
- data/bin/docklean.rb +20 -7
- data/lib/docklean.rb +1 -0
- data/lib/docklean/base.rb +6 -0
- data/lib/docklean/containers.rb +10 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349b9e4041f0ddbed4accca5c002570e37fe4219
|
4
|
+
data.tar.gz: b0d4225514974336fe241e9fa2e669ba3e01be2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0c570dad3d748eff59399e7020de956fefda9fce1d096865f2fdc122294bd33cbe9463a0e86488639c22c5ad151e0542bde4463368b3c51c90098b63c17436
|
7
|
+
data.tar.gz: ece41b9225f29af640f9c5fec74c038ab7870e7ed6aaa11558135340bc0c4c052fb359cc2e985b2b0cf88b05a1788e1a049c43adb9cc18e207b97c783bb2aaae
|
data/bin/config.yaml
CHANGED
data/bin/docklean.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
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
|
-
|
19
|
-
docklean.
|
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()
|
data/lib/docklean.rb
CHANGED
data/lib/docklean/base.rb
CHANGED
data/lib/docklean/containers.rb
CHANGED
@@ -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
|
-
|
47
|
-
|
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])
|