Last active
October 13, 2020 07:57
-
-
Save achimnol/11fd2b379ad186cf624307b2c7e0953f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> python test-pull.py | |
---begin--- | |
{'status': 'Pulling from library/nginx', 'id': 'mainline'} | |
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': 'd121f8d1c412'} | |
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': '66a200539fd6'} | |
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': 'e9738820db15'} | |
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': 'd74ea5811e8a'} | |
{'status': 'Pulling fs layer', 'progressDetail': {}, 'id': 'ffdacbba6928'} | |
{'status': 'Waiting', 'progressDetail': {}, 'id': 'd74ea5811e8a'} | |
{'status': 'Waiting', 'progressDetail': {}, 'id': 'ffdacbba6928'} | |
{'status': 'Downloading', 'progressDetail': {'current': 601, 'total': 601}, 'progress': '[==================================================>] 601B/601B', 'id': 'e9738820db15'} | |
{'status': 'Download complete', 'progressDetail': {}, 'id': 'e9738820db15'} | |
{'status': 'Downloading', 'progressDetail': {'current': 277510, 'total': 26488730}, 'progress': '[> ] 277.5kB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 277510, 'total': 27092161}, 'progress': '[> ] 277.5kB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 1670150, 'total': 27092161}, 'progress': '[===> ] 1.67MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 3570140, 'total': 26488730}, 'progress': '[======> ] 3.57MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 4397532, 'total': 26488730}, 'progress': '[========> ] 4.398MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 3357148, 'total': 27092161}, 'progress': '[======> ] 3.357MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 7428572, 'total': 26488730}, 'progress': '[==============> ] 7.429MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 425, 'total': 899}, 'progress': '[=======================> ] 425B/899B', 'id': 'd74ea5811e8a'} | |
{'status': 'Downloading', 'progressDetail': {'current': 899, 'total': 899}, 'progress': '[==================================================>] 899B/899B', 'id': 'd74ea5811e8a'} | |
{'status': 'Verifying Checksum', 'progressDetail': {}, 'id': 'd74ea5811e8a'} | |
{'status': 'Download complete', 'progressDetail': {}, 'id': 'd74ea5811e8a'} | |
{'status': 'Downloading', 'progressDetail': {'current': 4205020, 'total': 27092161}, 'progress': '[=======> ] 4.205MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 5904860, 'total': 27092161}, 'progress': '[==========> ] 5.905MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 9898460, 'total': 26488730}, 'progress': '[==================> ] 9.898MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 9263580, 'total': 27092161}, 'progress': '[=================> ] 9.264MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 425, 'total': 666}, 'progress': '[===============================> ] 425B/666B', 'id': 'ffdacbba6928'} | |
{'status': 'Downloading', 'progressDetail': {'current': 666, 'total': 666}, 'progress': '[==================================================>] 666B/666B', 'id': 'ffdacbba6928'} | |
{'status': 'Verifying Checksum', 'progressDetail': {}, 'id': 'ffdacbba6928'} | |
{'status': 'Download complete', 'progressDetail': {}, 'id': 'ffdacbba6928'} | |
{'status': 'Downloading', 'progressDetail': {'current': 12106204, 'total': 26488730}, 'progress': '[======================> ] 12.11MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 10373596, 'total': 27092161}, 'progress': '[===================> ] 10.37MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 12610012, 'total': 27092161}, 'progress': '[=======================> ] 12.61MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 15137244, 'total': 26488730}, 'progress': '[============================> ] 15.14MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 17615324, 'total': 26488730}, 'progress': '[=================================> ] 17.62MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 15960540, 'total': 27092161}, 'progress': '[=============================> ] 15.96MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 20904412, 'total': 26488730}, 'progress': '[=======================================> ] 20.9MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 17918428, 'total': 27092161}, 'progress': '[=================================> ] 17.92MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 21182940, 'total': 26488730}, 'progress': '[=======================================> ] 21.18MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 20437468, 'total': 27092161}, 'progress': '[=====================================> ] 20.44MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 23951836, 'total': 26488730}, 'progress': '[=============================================> ] 23.95MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Verifying Checksum', 'progressDetail': {}, 'id': '66a200539fd6'} | |
{'status': 'Download complete', 'progressDetail': {}, 'id': '66a200539fd6'} | |
{'status': 'Downloading', 'progressDetail': {'current': 21277148, 'total': 27092161}, 'progress': '[=======================================> ] 21.28MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Downloading', 'progressDetail': {'current': 23800284, 'total': 27092161}, 'progress': '[===========================================> ] 23.8MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Verifying Checksum', 'progressDetail': {}, 'id': 'd121f8d1c412'} | |
{'status': 'Download complete', 'progressDetail': {}, 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 294912, 'total': 27092161}, 'progress': '[> ] 294.9kB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 3244032, 'total': 27092161}, 'progress': '[=====> ] 3.244MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 6782976, 'total': 27092161}, 'progress': '[============> ] 6.783MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 9437184, 'total': 27092161}, 'progress': '[=================> ] 9.437MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 12091392, 'total': 27092161}, 'progress': '[======================> ] 12.09MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 14745600, 'total': 27092161}, 'progress': '[===========================> ] 14.75MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 17399808, 'total': 27092161}, 'progress': '[================================> ] 17.4MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 20348928, 'total': 27092161}, 'progress': '[=====================================> ] 20.35MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 23298048, 'total': 27092161}, 'progress': '[==========================================> ] 23.3MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 25067520, 'total': 27092161}, 'progress': '[==============================================> ] 25.07MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 25952256, 'total': 27092161}, 'progress': '[===============================================> ] 25.95MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 26836992, 'total': 27092161}, 'progress': '[=================================================> ] 26.84MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 27092161, 'total': 27092161}, 'progress': '[==================================================>] 27.09MB/27.09MB', 'id': 'd121f8d1c412'} | |
{'status': 'Pull complete', 'progressDetail': {}, 'id': 'd121f8d1c412'} | |
{'status': 'Extracting', 'progressDetail': {'current': 294912, 'total': 26488730}, 'progress': '[> ] 294.9kB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 3833856, 'total': 26488730}, 'progress': '[=======> ] 3.834MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 7667712, 'total': 26488730}, 'progress': '[==============> ] 7.668MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 11206656, 'total': 26488730}, 'progress': '[=====================> ] 11.21MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 15040512, 'total': 26488730}, 'progress': '[============================> ] 15.04MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 18284544, 'total': 26488730}, 'progress': '[==================================> ] 18.28MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 21528576, 'total': 26488730}, 'progress': '[========================================> ] 21.53MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 24182784, 'total': 26488730}, 'progress': '[=============================================> ] 24.18MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 26488730, 'total': 26488730}, 'progress': '[==================================================>] 26.49MB/26.49MB', 'id': '66a200539fd6'} | |
{'status': 'Pull complete', 'progressDetail': {}, 'id': '66a200539fd6'} | |
{'status': 'Extracting', 'progressDetail': {'current': 601, 'total': 601}, 'progress': '[==================================================>] 601B/601B', 'id': 'e9738820db15'} | |
{'status': 'Extracting', 'progressDetail': {'current': 601, 'total': 601}, 'progress': '[==================================================>] 601B/601B', 'id': 'e9738820db15'} | |
{'status': 'Pull complete', 'progressDetail': {}, 'id': 'e9738820db15'} | |
{'status': 'Extracting', 'progressDetail': {'current': 899, 'total': 899}, 'progress': '[==================================================>] 899B/899B', 'id': 'd74ea5811e8a'} | |
{'status': 'Extracting', 'progressDetail': {'current': 899, 'total': 899}, 'progress': '[==================================================>] 899B/899B', 'id': 'd74ea5811e8a'} | |
{'status': 'Pull complete', 'progressDetail': {}, 'id': 'd74ea5811e8a'} | |
{'status': 'Extracting', 'progressDetail': {'current': 666, 'total': 666}, 'progress': '[==================================================>] 666B/666B', 'id': 'ffdacbba6928'} | |
{'status': 'Extracting', 'progressDetail': {'current': 666, 'total': 666}, 'progress': '[==================================================>] 666B/666B', 'id': 'ffdacbba6928'} | |
{'status': 'Pull complete', 'progressDetail': {}, 'id': 'ffdacbba6928'} | |
{'status': 'Digest: sha256:14be3265d8be0300aa10dbb911cb299fe7c0bbea8e5cb02fd940f856b8f61f5d'} | |
{'status': 'Status: Downloaded newer image for nginx:mainline'} | |
---done--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import aiodocker | |
import tqdm | |
async def pull(docker: aiodocker.Docker, imgref: str) -> None: | |
print('---begin---') | |
downloading_layers = {} | |
extracting_layers = {} | |
with tqdm.tqdm(total=100, unit='%') as pbar: | |
async for msg in docker.images.pull(imgref, stream=True): | |
if msg['status'] == 'Downloading': | |
downloading_layers[msg['id']] = msg['progressDetail'] | |
elif msg['status'] == 'Extracting': | |
extracting_layers[msg['id']] = msg['progressDetail'] | |
elif msg['status'] == 'Pulling fs layer': | |
# we can detect the layer IDs upfront here. | |
pass | |
elif msg['status'].startswith('Digest: '): | |
# done | |
pass | |
current = ( | |
sum(p['current'] for p in downloading_layers.values()) | |
+ sum(p['current'] for p in extracting_layers.values()) | |
) | |
total = ( | |
sum(p['total'] for p in downloading_layers.values()) | |
+ sum(p['total'] for p in extracting_layers.values()) | |
) | |
if total > 0: | |
pbar.n = round(current / total * 100.0, 2) | |
pbar.update(0) | |
pbar.n = 100 | |
pbar.update(0) | |
print('---done---') | |
async def main() -> None: | |
docker = aiodocker.Docker() | |
await pull(docker, 'nginx:mainline') | |
await docker.close() | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment