PK!docker_image_size_limit.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. Or ``0`` if image is less than limit. """ image_size = client.images.get(image).attrs['Size'] try: image_limit = int(limit) except ValueError: image_limit = parse_size(limit, binary=True) if image_size > image_limit: return image_size - image_limit return 0 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!Hu|*"658docker_image_size_limit-0.1.1.dist-info/entry_points.txtN+I/N.,()J,αMON-MLJeVdfX&fqqPK!R00/docker_image_size_limit-0.1.1.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.1.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HFG~ 0docker_image_size_limit-0.1.1.dist-info/METADATAVs8ߟB6I3 ѤǕ !!ۋQ-W!~+kz͔a޾]ޮEC}B2Vɞk$--1Kgolx1c D_!oD(>b+.i.8*n \M`rPOnڼ}!2j*ӌ9/vLx}5IW9j$)7#<@/ތj:YV6CmYFm嫇WN͘xi7mHm 0ȯ_w6,́ ́H E p]Tf!C#cmc($YYOyu%A![˺ZPK!HX3(.docker_image_size_limit-0.1.1.dist-info/RECORDιv@gC؊sEM΄AT>6t)8q< 0ӠB5ݛEX8t|},ljwP^;H|,'h6Iҟ%$j+mt-jF_Bbb{d W%W%:vN} 8O|NjNSepQkఌN? v.~o+7T7 AS