PK!M1#docker_image_size_limit/__init__.py# -*- coding: utf-8 -*- import argparse import sys from typing import NoReturn import pkg_resources from docker import DockerClient, from_env from humanfriendly import format_size, parse_size _version = pkg_resources.get_distribution( 'docker_image_size_limit', ).version def main() -> NoReturn: """Main CLI entrypoint.""" client = from_env() arguments = _parse_args() oversize = check_image_size(client, arguments.image, arguments.size) exit_code = 0 if oversize > 0: print('{0} exceeds {1} limit by {2}'.format( # noqa: T001 arguments.image, arguments.size, format_size(oversize, binary=True), )) exit_code = 1 sys.exit(exit_code) def check_image_size(client: DockerClient, image: str, limit: str) -> int: """ Checks the image size of given image name. Compares it to the given size in bytes or in human readable format. Returns: Tresshold overflow in bytes. Can be negative in case ``image_limit`` is bigger than the actual image. We only care for values ``> 0``. """ image_size = client.images.get(image).attrs['Size'] try: image_limit = int(limit) except ValueError: image_limit = parse_size(limit, binary=True) return image_size - image_limit def _parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( description='Keep your docker images small', ) parser.add_argument( '--version', action='version', version=_version, ) parser.add_argument( 'image', type=str, help='Docker image name to be checked', ) parser.add_argument( 'size', type=str, help='Human-readable size limit: 102 MB, 1GB', ) return parser.parse_args() PK! docker_image_size_limit/py.typedPK!Hu|*"658docker_image_size_limit-0.2.0.dist-info/entry_points.txtN+I/N.,()J,αMON-MLJeVdfX&fqqPK!R00/docker_image_size_limit-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 wemake.services Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU-docker_image_size_limit-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H԰_ 0docker_image_size_limit-0.2.0.dist-info/METADATAWs6ߟb/LlȏKZzo !\k2C؋Q-ג!ޕlBH2 ѳgWbgL%q =EX_x3Lmmyĕ:NdQe 3SYTDTY`fD{(+/_l,sc}B\yYWY;+]Of,jiW|ŰM+yX̧b'Bf&n6T)"AFaK觃❣W8Xq#鉁Kq#5qR ϥ눮s+e2Z'\(VN2"Oțy}W@iw){ؿA!r J/剢 I_$&e,'B:" ܺ}s~yrG#C_:\T_1v< .~s;I4L~ntv \z] 0^7K-.߸\kqO3~:ugz`Cq`QvռO|}-:'"KaFX\'0zyV;V Pǒ65;@E݌,E{OS'gfe}zPYv@658@]TCorQS8QKLĜ>+ &RUBVUbBƴbI@ eJ_ A "ícrB}y$70H$OCָչtۭzUmgYV}04c;[| l{"RRPo΀99gcz ޽Jy`BٰJ*}{:eeethdRV1NLFH_sn^Sh@j QoPz =V4>h7&KFi>T2\I6̽y'^O HBzbU^?g&Ԭ|l^M(y% ]f.՞G$ڒGE;g/|IΪwّm7jBCĺD2k<<e9\tj#^c@ q 8%7PK!M1#docker_image_size_limit/__init__.pyPK! Adocker_image_size_limit/py.typedPK!Hu|*"658docker_image_size_limit-0.2.0.dist-info/entry_points.txtPK!R00/ docker_image_size_limit-0.2.0.dist-info/LICENSEPK!HڽTU- docker_image_size_limit-0.2.0.dist-info/WHEELPK!H԰_ 0' docker_image_size_limit-0.2.0.dist-info/METADATAPK!Hzn.docker_image_size_limit-0.2.0.dist-info/RECORDPKw