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']
|
|
|
|
image_id = c.inspect_container(id_)['Image']
|
2015-09-27 08:30:30 +02:00
|
|
|
|
2016-07-15 18:14:07 +02:00
|
|
|
print('-' * 75)
|
2015-09-27 09:08:48 +02:00
|
|
|
print('Container: {}'.format(name))
|
|
|
|
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,
|
|
|
|
'/bin/bash', '-c',
|
2015-09-27 09:08:48 +02:00
|
|
|
|
2018-01-05 13:41:56 +01:00
|
|
|
'dnf -q check-update;' +
|
|
|
|
'if [ $? == 100 ]; then echo "Updates available"; fi'
|
|
|
|
])
|
|
|
|
print(output.decode())
|