2018-01-05 13:41:56 +01:00
|
|
|
#!/usr/bin/python3
|
2015-09-27 08:30:30 +02:00
|
|
|
"""Check Docker images for security/distro updates. Assumes DNF."""
|
|
|
|
|
|
|
|
from __future__ import division, print_function
|
2017-10-27 08:14:56 +02:00
|
|
|
import docker
|
2015-09-27 08:30:30 +02:00
|
|
|
import subprocess
|
|
|
|
|
2017-10-27 08:14:56 +02:00
|
|
|
c = docker.APIClient(base_url='unix://var/run/docker.sock')
|
2015-09-27 08:30:30 +02:00
|
|
|
for container in c.containers():
|
2015-09-27 09:08:48 +02:00
|
|
|
name = container['Names'][0]
|
|
|
|
id_ = container['Id']
|
2016-07-15 18:14:07 +02:00
|
|
|
print('-' * 75)
|
2015-09-27 09:08:48 +02:00
|
|
|
print('Container: {}'.format(name))
|
2021-04-18 17:43:51 +02:00
|
|
|
|
|
|
|
image_id = c.inspect_container(id_)['Image']
|
2015-09-27 09:08:48 +02:00
|
|
|
print('Image: {} '.format(image_id))
|
2015-09-27 08:30:30 +02:00
|
|
|
|
2015-09-27 09:08:48 +02:00
|
|
|
# Not using the API here for simplicity (for now)
|
2018-01-05 13:41:56 +01:00
|
|
|
output = subprocess.check_output([
|
|
|
|
'docker', 'run', '-t', '--rm',
|
|
|
|
image_id,
|
2019-09-20 15:49:56 +02:00
|
|
|
'/bin/sh', '-c',
|
2015-09-27 09:08:48 +02:00
|
|
|
|
2019-09-20 15:49:56 +02:00
|
|
|
# Note the semicolons and the string concatenation here!
|
|
|
|
'if [ ! -x /usr/bin/dnf ]; then echo "dnf not available"; exit 0; fi;' +
|
|
|
|
'/usr/bin/dnf -q check-update;' +
|
|
|
|
'if [ $? == 100 ]; then echo "Updates available"; fi;'
|
2018-01-05 13:41:56 +01:00
|
|
|
])
|
|
|
|
print(output.decode())
|