docker-utils 0.1.33 → 0.1.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/share/scripts/exposed +46 -0
- data/share/scripts/gc +51 -20
- data/share/scripts/instances +51 -0
- data/share/scripts/ip +3 -0
- data/share/scripts/tags +79 -0
- data/share/scripts/up? +3 -0
- metadata +7 -4
- data/share/scripts/bootstrap +0 -25
- data/share/scripts/provision-volume +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca2be09a117367fb3ed4b4d9b1d071f1eb44c186
|
4
|
+
data.tar.gz: f6832ac00be7b852cdec01a2752a7e9d2b62b8b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ec8a28f5049794aebde5f254516749e848d8d431b5df28f61dc913d523fd4fd49f2aa8a9f55274749f732da9d47d6223ae0d8fa9210f964e5340cc9f50e1ffb
|
7
|
+
data.tar.gz: e9747a85ebd68a2aa5733d4d54b4e3db8d19a4ffaff2e682180bdc6bf242693c5aade676a4b886800b6e2b5b86c8850b55087ac63751fcf3e5cfe5c76859e6e4
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
DockerBinaryLocation = `which docker`.chomp
|
4
|
+
|
5
|
+
def cmd(*args)
|
6
|
+
io = IO.popen(args, err: [:child, :out])
|
7
|
+
io.read.split("\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
def docker(*args)
|
11
|
+
cmd(DockerBinaryLocation, *args).first
|
12
|
+
end
|
13
|
+
|
14
|
+
if ARGV.delete('-p') or ARGV.delete('--ports')
|
15
|
+
print = :ports
|
16
|
+
elsif ARGV.delete('-o') or ARGV.delete('--origins')
|
17
|
+
print = :ip_and_port_pairs
|
18
|
+
else
|
19
|
+
print = :connstrings
|
20
|
+
end
|
21
|
+
|
22
|
+
unless container = ARGV[0]
|
23
|
+
$stderr.puts "invalid argument"
|
24
|
+
Kernel.exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
ip = docker 'inspect', '--format', '{{.NetworkSettings.IPAddress}}', container
|
28
|
+
ports_and_transports = docker 'inspect', '--format', '{{range $port, $v := .NetworkSettings.Ports}}{{$port}} {{end}}', container
|
29
|
+
|
30
|
+
conns = ports_and_transports.split(' ').map do |port_and_transport|
|
31
|
+
port, transport = port_and_transport.split('/')
|
32
|
+
port = port.to_i
|
33
|
+
{port: port, transport: transport, ip: ip}
|
34
|
+
end
|
35
|
+
|
36
|
+
conns.each do |conn|
|
37
|
+
case print
|
38
|
+
when :ports
|
39
|
+
puts conn[:port]
|
40
|
+
when :ip_and_port_pairs
|
41
|
+
puts "#{conn[:ip]}:#{conn[:port]}"
|
42
|
+
when :connstrings
|
43
|
+
puts "#{conn[:transport]}://#{conn[:ip]}:#{conn[:port]}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/share/scripts/gc
CHANGED
@@ -1,39 +1,70 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
DockerBinaryLocation = `which docker`.chomp
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def cmd(*args)
|
6
|
+
io = IO.popen(args, err: '/dev/null')
|
7
|
+
io.read.split("\n")
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
containers = containers - running_containers
|
10
|
+
def docker(*args)
|
11
|
+
cmd(DockerBinaryLocation, *args)
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
tasks = [:remove_containers, :remove_volumes, :remove_images]
|
15
|
+
container_filter = [:running]
|
16
|
+
image_filter = [:untagged]
|
17
|
+
|
18
|
+
while task_pattern = ARGV.shift
|
19
|
+
case task_pattern.intern
|
20
|
+
when :all
|
21
|
+
container_filter = []
|
22
|
+
image_filter = []
|
23
|
+
when :running
|
24
|
+
container_filter -= [:running]
|
25
|
+
when :volumes
|
26
|
+
#
|
27
|
+
when :images
|
28
|
+
image_filter -= [:untagged]
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
32
|
+
|
33
|
+
containers = docker('ps', '-a', '-q').sort
|
34
|
+
|
35
|
+
if container_filter.include? :running
|
36
|
+
running_containers = docker('ps', '-q').sort
|
37
|
+
containers = containers - running_containers
|
25
38
|
end
|
26
39
|
|
27
|
-
|
40
|
+
|
41
|
+
images = docker('images')[1..-1].map do |ln|
|
28
42
|
parts = ln.split(' ').map{ |part| part unless part == '<none>' }
|
29
43
|
image_name = (parts[0] and parts[1]) ? "#{parts[0]}:#{parts[1]}" : nil
|
30
44
|
{id: parts[2], name: image_name}
|
31
45
|
end
|
32
46
|
|
33
|
-
|
47
|
+
if image_filter.include? :untagged
|
34
48
|
images = images.delete_if{ |image| image[:name] }
|
35
49
|
end
|
36
50
|
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
|
52
|
+
|
53
|
+
if tasks.include? :remove_containers and containers.length.nonzero?
|
54
|
+
puts "removing containers"
|
55
|
+
containers.each do |cid|
|
56
|
+
docker 'kill', cid
|
57
|
+
docker 'rm', cid
|
58
|
+
|
59
|
+
puts " #{cid}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if tasks.include? :remove_images and images.length.nonzero?
|
64
|
+
puts "removing image layers"
|
65
|
+
images.each do |image|
|
66
|
+
docker 'rmi', '-f', image[:id]
|
67
|
+
|
68
|
+
puts " #{image[:name]} #{image[:id]}"
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
DockerBinaryLocation = `which docker`.chomp
|
4
|
+
|
5
|
+
def cmd(*args)
|
6
|
+
io = IO.popen(args, err: '/dev/null')
|
7
|
+
io.read.split("\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
def docker(*args)
|
11
|
+
cmd(DockerBinaryLocation, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
output_type = (ARGV.delete('-n') or ARGV.delete('--by-name')) ? :name : :id
|
15
|
+
show_only_running = not(ARGV.delete('-a') or ARGV.delete('--all'))
|
16
|
+
|
17
|
+
unless pattern = ARGV.shift
|
18
|
+
$stderr.puts "usage: #{$0} /search-pattern/"
|
19
|
+
Kernel.exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
if pattern.index(':')
|
23
|
+
pattern_name, pattern_tag = pattern.split(':')
|
24
|
+
pattern = {name: pattern_name, tag: pattern_tag}
|
25
|
+
else
|
26
|
+
pattern = {name: pattern, tag: 'latest'}
|
27
|
+
end
|
28
|
+
|
29
|
+
images = docker('images', '--no-trunc', pattern[:name])[1..-1].map do |ln|
|
30
|
+
parts = ln.split(' ').map{ |part| part unless part == '<none>' }
|
31
|
+
{tag: parts[1], ref: parts[2]}
|
32
|
+
end
|
33
|
+
|
34
|
+
pattern[:ref] = images.find{ |image| image[:tag] == pattern[:tag] }[:ref]
|
35
|
+
pattern[:tags] = images.find_all{ |image| image[:ref] == pattern[:ref] }.map{ |image| image[:tag] }
|
36
|
+
|
37
|
+
only_running_stanza = show_only_running ? [] : ['-a']
|
38
|
+
containers = docker('ps', *only_running_stanza, '--no-trunc')[1..-1].map do |ln|
|
39
|
+
parts = ln.split(' ').map{ |part| part unless part == '<none>' }
|
40
|
+
image_repo = parts[1]
|
41
|
+
image_name, image_tag = image_repo.split(':')
|
42
|
+
{id: parts[0], name: parts[-1], image: {repo: image_repo, name: image_name, tag: image_tag}}
|
43
|
+
end
|
44
|
+
|
45
|
+
containers = containers.find_all do |cont|
|
46
|
+
(pattern[:name] == cont[:image][:name]) and pattern[:tags].include?(cont[:image][:tag])
|
47
|
+
end
|
48
|
+
|
49
|
+
containers.each do |cont|
|
50
|
+
puts cont[output_type]
|
51
|
+
end
|
data/share/scripts/ip
ADDED
data/share/scripts/tags
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
DockerBinaryLocation = `which docker`.chomp
|
4
|
+
|
5
|
+
def cmd(*args)
|
6
|
+
io = IO.popen(args, err: '/dev/null')
|
7
|
+
io.read.split("\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
def docker(*args)
|
11
|
+
cmd(DockerBinaryLocation, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
output_format = (ARGV.delete('-f') or ARGV.delete('--full')) ? :name_and_tag : :tag
|
15
|
+
group_by_ref = (ARGV.delete('-g') or ARGV.delete('--group-by-ref'))
|
16
|
+
|
17
|
+
unless pattern_str = ARGV.shift
|
18
|
+
prefix = "usage: #{$0}"
|
19
|
+
spacer = " " * prefix.length
|
20
|
+
$stderr.puts "#{prefix} image-name"
|
21
|
+
$stderr.puts "#{spacer} image-name:tag"
|
22
|
+
$stderr.puts "#{spacer} layer-id"
|
23
|
+
Kernel.exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
if pattern_str.index(':')
|
27
|
+
pattern_name, pattern_tag = pattern_str.split(':')
|
28
|
+
pattern = {name: pattern_name, tag: pattern_tag}
|
29
|
+
elsif pattern_str =~ /^[0-9a-f]+$/i and [12, 64].include?(pattern_str.length)
|
30
|
+
pattern = {ref: pattern_str}
|
31
|
+
else
|
32
|
+
pattern = {name: pattern_str}
|
33
|
+
end
|
34
|
+
|
35
|
+
pattern[:effective_tag] = pattern[:tag] || 'latest'
|
36
|
+
|
37
|
+
images = docker('images', '-a', '--no-trunc')[1..-1].map do |ln|
|
38
|
+
parts = ln.split(' ').map{ |part| part unless part == '<none>' }
|
39
|
+
{name: parts[0], tag: parts[1], ref: parts[2]}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
if pattern[:ref]
|
44
|
+
ref_rxp = /^#{pattern[:ref]}([0-9a-f]{52})?$/
|
45
|
+
pattern[:name] = images.find{ |image| image[:ref] =~ ref_rxp }[:name]
|
46
|
+
elsif pattern[:name]
|
47
|
+
pattern[:ref] = images.find{ |image| image[:tag] == pattern[:effective_tag] }[:ref]
|
48
|
+
end
|
49
|
+
|
50
|
+
images = images.find_all{ |image| image[:name] == pattern[:name] }
|
51
|
+
|
52
|
+
if pattern[:explicit_tag]
|
53
|
+
images = images.find_all{ |image| image[:tag] == pattern[:explicit_tag] }
|
54
|
+
end
|
55
|
+
|
56
|
+
format_tag = lambda do |tag|
|
57
|
+
case output_format
|
58
|
+
when :name_and_tag
|
59
|
+
"#{pattern[:name]}:#{tag}"
|
60
|
+
when :tag
|
61
|
+
tag
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if group_by_ref
|
66
|
+
image_groups = images.group_by{ |image| image[:ref] }.map{ |(_, v)| v }
|
67
|
+
image_groups.each do |image_set|
|
68
|
+
synonyms = image_set.map{ |image| image[:tag] }.sort
|
69
|
+
synonym_strs = synonyms.map(&format_tag)
|
70
|
+
|
71
|
+
main_name_str = synonym_strs.shift
|
72
|
+
puts "#{main_name_str}: #{synonym_strs.join(', ')}"
|
73
|
+
end
|
74
|
+
else
|
75
|
+
images.map{ |image| image[:tag] }.each do |tag|
|
76
|
+
puts format_tag.call(tag)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/share/scripts/up?
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Levi Aul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-uuid
|
@@ -35,16 +35,19 @@ files:
|
|
35
35
|
- "./Rakefile"
|
36
36
|
- "./bin/docker-utils"
|
37
37
|
- "./docker-utils.gemspec"
|
38
|
-
- "./share/scripts/bootstrap"
|
39
38
|
- "./share/scripts/container-links-for"
|
40
39
|
- "./share/scripts/define-ambassador-service"
|
41
40
|
- "./share/scripts/define-service"
|
41
|
+
- "./share/scripts/exposed"
|
42
42
|
- "./share/scripts/gc"
|
43
43
|
- "./share/scripts/get"
|
44
44
|
- "./share/scripts/get-host-uuid"
|
45
|
+
- "./share/scripts/instances"
|
46
|
+
- "./share/scripts/ip"
|
45
47
|
- "./share/scripts/make-ref"
|
46
|
-
- "./share/scripts/
|
48
|
+
- "./share/scripts/tags"
|
47
49
|
- "./share/scripts/toolchain"
|
50
|
+
- "./share/scripts/up?"
|
48
51
|
- bin/docker-utils
|
49
52
|
homepage: https://github.com/tsutsu/docker-utils
|
50
53
|
licenses:
|
data/share/scripts/bootstrap
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
if [ -b "/dev/xvdc" ]; then
|
3
|
-
docker-utils provision-volume "/dev/xvdc" "/var/lib/docker"
|
4
|
-
fi
|
5
|
-
|
6
|
-
if [ -b "/dev/xvdd" ]; then
|
7
|
-
docker-utils provision-volume "/dev/xvdd" "/var/lib/docker/vfs/dir"
|
8
|
-
fi
|
9
|
-
|
10
|
-
if ! hash docker; then
|
11
|
-
echo "installing docker..."
|
12
|
-
echo 'deb http://get.docker.io/ubuntu docker main' > /etc/apt/sources.list.d/docker.list
|
13
|
-
apt-key adv --keyserver 'hkp://pgp.mit.edu:80' --recv-keys '36A1D7869245C8950F966E92D8576A8BA88D21E9'
|
14
|
-
apt-get update
|
15
|
-
apt-get install -qy lxc-docker
|
16
|
-
gpasswd -a ubuntu docker
|
17
|
-
fi
|
18
|
-
|
19
|
-
echo "logging into ${DOCKER_REGISTRY_URL}..."
|
20
|
-
cat >"$HOME/.dockercfg" <<EOF
|
21
|
-
{"${DOCKER_REGISTRY_URL}": {
|
22
|
-
"auth": "${DOCKER_REGISTRY_AUTH}",
|
23
|
-
"email": "${DOCKER_REGISTRY_EMAIL}"
|
24
|
-
}}
|
25
|
-
EOF
|
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
device="$1"; shift
|
4
|
-
mntpt="$1"; shift
|
5
|
-
|
6
|
-
mkfs.btrfs "${device}" 2>/dev/null || :
|
7
|
-
|
8
|
-
mount "${device}" /mnt 2>/dev/null || :
|
9
|
-
btrfs filesystem resize max /mnt 2>/dev/null || :
|
10
|
-
umount /mnt 2>/dev/null || :
|
11
|
-
|
12
|
-
mkdir -p "${mntpt}"
|
13
|
-
mount -t btrfs -o "rw,noatime,space_cache" "${device}" "${mntpt}"
|