add some tools to generate graphs and squash images
This commit is contained in:
1
bin/dockviz
Executable file
1
bin/dockviz
Executable file
@@ -0,0 +1 @@
|
||||
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz $*
|
||||
10
bin/dockviz-graphml
Executable file
10
bin/dockviz-graphml
Executable file
@@ -0,0 +1,10 @@
|
||||
DIR=`mktemp -d`
|
||||
cd $DIR
|
||||
wget -q https://bitbucket.org/dirkbaechle/dottoxml/raw/e285fccba8d51c6d814a83756935f3128972f0ea/src/X11Colors.py
|
||||
wget -q https://bitbucket.org/dirkbaechle/dottoxml/raw/e285fccba8d51c6d814a83756935f3128972f0ea/src/dottoxml.py
|
||||
wget -q https://bitbucket.org/dirkbaechle/dottoxml/raw/e285fccba8d51c6d814a83756935f3128972f0ea/src/dot.py
|
||||
$DOCKER_HOME/bin/dockviz images -d > dockviz.dot
|
||||
python dottoxml.py dockviz.dot dockviz.graphml
|
||||
cat dockviz.graphml
|
||||
cd - > /dev/null
|
||||
rm -rf $DIR
|
||||
2
bin/dockviz-xml
Normal file
2
bin/dockviz-xml
Normal file
@@ -0,0 +1,2 @@
|
||||
DIR=`mkdir -t`
|
||||
cd $DIR
|
||||
5
bin/make
5
bin/make
@@ -1,6 +1,5 @@
|
||||
FILE=$DOCKER_HOME/images/$1.mk
|
||||
if [ ! -e $FILE ]; then
|
||||
DELETE=true
|
||||
FILE="$(mktemp)"
|
||||
cat <<- EOF > $FILE
|
||||
include \$(DOCKER_HOME)/build/Makefile
|
||||
@@ -11,7 +10,5 @@ EOF
|
||||
fi
|
||||
make -f $FILE build
|
||||
CODE=$?
|
||||
if [ ! -z ${DELETE+x} ]; then
|
||||
rm $FILE
|
||||
fi
|
||||
rm $FILE
|
||||
exit $CODE
|
||||
15
bin/make-dependencies
Executable file
15
bin/make-dependencies
Executable file
@@ -0,0 +1,15 @@
|
||||
FILE=$DOCKER_HOME/images/$1.mk
|
||||
if [ ! -e $FILE ]; then
|
||||
FILE="$(mktemp)"
|
||||
cat <<- EOF > $FILE
|
||||
include \$(DOCKER_HOME)/build/Makefile
|
||||
FROM = base:squash
|
||||
NAME = $1
|
||||
VERSION = latest
|
||||
build: prepare $1
|
||||
EOF
|
||||
fi
|
||||
make -Bnd -f $FILE build > $1.mk
|
||||
cat $1.mk | make2graph | dot -Tpng -o $1.mk.png
|
||||
cat $1.mk | make2graph -f x > $1.mk.xml
|
||||
rm $FILE
|
||||
5
bin/squash
Executable file
5
bin/squash
Executable file
@@ -0,0 +1,5 @@
|
||||
TREEFILE="$(mktemp)"
|
||||
COMMANDFILE="$(mktemp)"
|
||||
$DOCKER_HOME/bin/make/dockviz images -t --no-trunc > $TREEFILE
|
||||
python3 $DOCKER_HOME/squash.py $TREEFILE $COMMANDFILE
|
||||
. $COMMANDFILE
|
||||
1
bin/total-size
Normal file
1
bin/total-size
Normal file
@@ -0,0 +1 @@
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz images -t | grep Tags: | cut -d':' -f3 | cut -d' ' -f2 | awk '{d+=$1} END {print d}'
|
||||
@@ -42,7 +42,9 @@ define arg
|
||||
endef
|
||||
|
||||
build:
|
||||
ifneq ($(CLEANUP),)
|
||||
$(call script,cleanup)
|
||||
endif
|
||||
@echo 'RUN chmod +x -R /opt/init.d' >> ${FILE}
|
||||
docker build -t $(NAME):$(VERSION) $(ARGS) -f $(FILE) $(DOCKER_HOME)/build
|
||||
@rm -f ${FILE}
|
||||
|
||||
5
images/base.mk
Normal file
5
images/base.mk
Normal file
@@ -0,0 +1,5 @@
|
||||
include $(DOCKER_HOME)/build/Makefile
|
||||
NAME = base
|
||||
VERSION = latest
|
||||
CLEANUP = false
|
||||
build: prepare $1
|
||||
4
setup
4
setup
@@ -49,4 +49,6 @@ if [ -z "$DOCKER_HOME" ]; then
|
||||
fi
|
||||
|
||||
mkdir -p $DOCKER_HOME
|
||||
docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
|
||||
docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
|
||||
docker pull nate/dockviz
|
||||
pip install docker-squash
|
||||
70
squash.py
Normal file
70
squash.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
# Command line arguments
|
||||
treefile = sys.argv[1]
|
||||
commandfile = sys.argv[2]
|
||||
|
||||
# File handling
|
||||
os.remove(commandfile)
|
||||
treefile = open(treefile, 'r', encoding='utf-8')
|
||||
commandfile = open(commandfile, 'a')
|
||||
|
||||
def proccess_end(name, tag):
|
||||
print('Deal with tag [{}]...'.format(tag, branches[-1]))
|
||||
if branches[-1]:
|
||||
print(' > Use branching image [%.7s]...' % branches[-1])
|
||||
commandfile.write('docker-squash -f {} -t {}:latest {}:{}\n'.format(branches[-1], name, name, tag))
|
||||
else:
|
||||
print(' > Branching image missing!')
|
||||
|
||||
# Caching
|
||||
previous_type = False
|
||||
previous_tag = False
|
||||
previous_depth = False
|
||||
|
||||
# Parse file
|
||||
branches = []
|
||||
for line in treefile:
|
||||
# Find image id
|
||||
match = re.search('sha256:([\w]+)', line)
|
||||
id = match.group(1) if match else False
|
||||
|
||||
# Find image tag
|
||||
match = re.search('Tags: ([\w/]+):([\w\.]+)', line)
|
||||
name = match.group(1) if match else False
|
||||
tag = match.group(2) if match else False
|
||||
|
||||
# Count depth
|
||||
depth = line.count('│')
|
||||
|
||||
# Parse tree
|
||||
match = re.search('([^s])─', line)
|
||||
type = match.group(1)
|
||||
if type == '└':
|
||||
if depth < previous_depth and previous_tag:
|
||||
# Reached an end
|
||||
proccess_end(previous_name, previous_tag)
|
||||
elif type == '├':
|
||||
if previous_type == '└' and previous_name:
|
||||
# Reached an end
|
||||
proccess_end(previous_name, previous_tag)
|
||||
|
||||
# Start new branch
|
||||
branches.append(id)
|
||||
|
||||
# Return to previous branch
|
||||
if depth < previous_depth:
|
||||
branches.pop()
|
||||
branches.append(id)
|
||||
|
||||
# Store current data
|
||||
previous_type = type
|
||||
previous_name = name
|
||||
previous_tag = tag
|
||||
previous_depth = depth
|
||||
|
||||
# Deal with very last end
|
||||
if previous_tag:
|
||||
proccess_end(previous_name, previous_tag)
|
||||
Reference in New Issue
Block a user