Skip to content

Commit

Permalink
Added debian:jessie to base.yml
Browse files Browse the repository at this point in the history
- Fixed the reporting for docker exec commands so execution errors are
seen in stdout
- Changed some formatting in report.py
- Fixed some bugs in commands.py and common.py so an invocation list
using a delimiter that isn't a newline character can be handled

Signed-off-by: Nisha K <[email protected]>
  • Loading branch information
Nisha K committed Oct 6, 2017
1 parent ce2ce03 commit 473ba1c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 60 deletions.
84 changes: 32 additions & 52 deletions command_lib/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,6 @@
# 2:
# host: <list of commands> (if the environment is the host)
# delimiter: <the delimiter for the commands>
debian:
latest: jessie
tags:
jessie:
shell: '/bin/bash'
# either enter the package names as a list or a snippet to invoke either within or outside the container
names:
invoke:
1:
# Currently two types of environments are supported - host or container
container:
- "dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'"
delimiter: '\n'
# the length of this list should be the same as the names or else there will be a mismatch
versions:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do echo $p; dpkg -l $p | awk 'NR>5 {print $3}'; echo END; done"
delimiter: 'END'
licenses:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do echo $p; cat /usr/share/doc/$package/copyright; echo END; done"
delimiter: 'END'
src_urls: ''
jessie-backports:
shell: '/bin/bash'
names:
invoke:
1:
container:
- "dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'"
delimiter: '\n'
versions:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do echo $p; dpkg -l $p | awk 'NR>5 {print $3}'; echo END; done"
delimiter: 'END'
licenses:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do echo $p; cat /usr/share/doc/$package/copyright; echo END; done"
delimiter: 'END'
src_urls: ''

# vmware/photon
vmware/photon:
Expand Down Expand Up @@ -104,3 +52,35 @@ vmware/photon:
- 'pkgs=`tdnf list installed | cut -f1 -d"."`'
- 'for p in $pkgs; do tdnf info $p | head -9 | tail -1 | cut -f2-3 -d":" | xargs; done'
delimiter: "\n"

# debian -------------------------------------------------------------------------------------------------------------------------------
debian:
latest: jessie
tags:
jessie:
shell: '/bin/bash'
# either enter the package names as a list or a snippet to invoke either within or outside the container
names:
invoke:
1:
# Currently two types of environments are supported - host or container
container:
- "dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'"
delimiter: "\n"
# the length of this list should be the same as the names or else there will be a mismatch
versions:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do dpkg -l $p | awk 'NR>5 {print $3}'; done"
delimiter: "\n"
licenses:
invoke:
1:
container:
- "pkgs=`dpkg --get-selections | cut -f1 -d':' | awk '{print $1}'`"
- "for p in $pkgs; do cat /usr/share/doc/$p/copyright; echo EOF; done"
delimiter: 'EOF'
src_urls: ''

13 changes: 11 additions & 2 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ def get_info_list(info_dict, info, image_tag_string):
info_list = process_base_invoke(info_dict[info]['invoke'],
image_tag_string,
info_dict['shell'])
info_list = info_list[:-1]
if 'delimiter' in info_dict[info]:
info_list = info_list.split(info_dict[info]['delimiter'])[:-1]
info_list = info_list.split(info_dict[info]['delimiter'])
if info_list[-1] == '':
info_list.pop()
else:
info_list = info_dict[info]
return info_list
Expand Down Expand Up @@ -261,9 +264,15 @@ def get_dockerfile_packages():
installed with it
2. All of the packages that are recognized would be unconfirmed
because there is no container to run the snippets against
All the unrecognized commands will be returned as is'''
All the unrecognized commands will be returned as is
Since there will be nothing more to do - recognized is just a list
of packages that may have been installed in the dockerfile'''
pkg_dict = cmds.remove_uninstalled(cmds.get_package_listing(
docker_commands))
recognized_list = []
for command in pkg_dict['recognized'].keys():
recognized_list.extend(pkg_dict['recognized'][command])
pkg_dict.update({'recognized': recognized_list})
return pkg_dict


Expand Down
2 changes: 1 addition & 1 deletion report.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def execute(args):
report = report + 'Packages from parsing Dockerfile RUN commands:\n'
for pkg in pkg_dict['recognized']:
report = report + ' ' + pkg
report = report + 'Unregonized RUN commands in Dockerfile:\n'
report = report + '\nUnregonized RUN commands in Dockerfile:\n'
for cmd in pkg_dict['unrecognized']:
report = report + cmd + '\n'
write_report(report)
Expand Down
16 changes: 11 additions & 5 deletions utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_package_listing(docker_commands):
if sub == command_lib['snippets'][name]['install']:
is_package_op = True
installed_dict['installed'] = command_obj['arguments']
if sub == command_lib['snippets'][name]['removed']:
if sub == command_lib['snippets'][name]['remove']:
is_package_op = True
installed_dict['removed'] = command_obj['arguments']
# add only if there are some packages installed or removed
Expand Down Expand Up @@ -289,8 +289,12 @@ def invoke_in_container(snippet_list, shell, package='', override=''):
# construct the full command
full_cmd = ''
while len(snippet_list) > 1:
full_cmd = full_cmd + snippet_list.pop(0).format(package=package) + \
'&&'
cmd = snippet_list.pop(0)
try:
cmd = cmd.format(package=package)
except KeyError:
pass
full_cmd = full_cmd + cmd + '&&'
full_cmd = full_cmd + snippet_list[0]
try:
if override:
Expand All @@ -302,9 +306,11 @@ def invoke_in_container(snippet_list, shell, package='', override=''):
result = result.decode('utf-8')
except AttributeError:
pass
except:
return result
except subprocess.CalledProcessError as error:
print("Error executing command inside the container")
return result
raise subprocess.CalledProcessError(
1, cmd=full_cmd, output=error.output.decode('utf-8'))


def get_image_id(image_tag_string):
Expand Down

0 comments on commit 473ba1c

Please sign in to comment.