
    K9                         S SK r S SKrS SKrS SKrSSKJr  SSKJr  SSKJr  SSKJr  \R                  " \
5      r " S S5      rS	 rg)
    N   )auth)	constants)errors)utilsc                   d    \ rS rSr        SS jr\R                  " S5      S 5       rS rSr	g)	BuildApiMixin   Nc                    S=nn0 nU=(       d    0 nU=(       d    0 nUc  Uc  [        S5      eU(       a  U	b  [        R                  " S5      eUR                  5        H0  nU[        R
                  ;  d  M  [        R                  " SU 35      e   U(       a  U(       d  [        S5      eUnGO<Ub  [        R                  " U5      nGO!UR                  S5      (       a  UnGO[        R                  R                  U5      (       d  [        S5      e[        R                  R                  US5      nSn [        R                  R                  U5      (       ae  [        U5       n![        [!        S	 U!R#                  5       R%                  5        V"s/ s H  n"U"R'                  5       PM     sn"5      5      n SSS5        [)        X5      n[        R*                  " UU UUS
9nU(       a  SOU	n	U R-                  S5      n#UUUUUUU
US.n$U$R/                  U5        U(       aF  U R0                  R3                  5       n%U%R5                  5        H  u  n&n'UR7                  U&U'5        M     U(       a'  U$R/                  S[8        R:                  " U5      05        U(       aP  [        R<                  " U R>                  S5      (       a  U$R/                  SU05        O[        R@                  " S5      eU(       ad  [        R<                  " U R>                  S5      (       a(  U$R/                  S[8        R:                  " U5      05        O[        R@                  " S5      eU(       ad  [        R<                  " U R>                  S5      (       a(  U$R/                  S[8        R:                  " U5      05        O[        R@                  " S5      eU(       aP  [        R<                  " U R>                  S5      (       a  U$R/                  SU05        O[        R@                  " S5      eU(       aP  [        R<                  " U R>                  S5      (       a  U$R/                  SU05        O[        R@                  " S5      eU(       aP  [        R<                  " U R>                  S5      (       a  U$R/                  SU05        O[        R@                  " S5      eUbz  [        RB                  " U R>                  S5      (       a  [        R@                  " S 5      e[E        U[F        5      (       a  [        RH                  " U5      nU$R/                  S!U05        UbA  [        RB                  " U R>                  S"5      (       a  [        R@                  " S#5      eUU$S$'   UbA  [        RB                  " U R>                  S%5      (       a  [        R@                  " S&5      eUU$S''   Ub  S(S)0nU	(       a  U	US*'   U RK                  U5        U RM                  U#UU$US+US,9n(Ub  U(       d  URO                  5         U RQ                  U(US-9$ s  sn"f ! , (       d  f       GN= f).a&  
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
needs to be set. ``path`` can be a local path (to a directory
containing a Dockerfile) or a remote URL. ``fileobj`` must be a
readable file-like object to a Dockerfile.

If you have a tar file for the Docker build context (including a
Dockerfile) already, pass a readable file-like object to ``fileobj``
and also pass ``custom_context=True``. If the stream is compressed
also, set ``encoding`` to the correct value (e.g ``gzip``).

Example:
    >>> from io import BytesIO
    >>> from docker import APIClient
    >>> dockerfile = '''
    ... # Shared Volume
    ... FROM busybox:buildroot-2014.02
    ... VOLUME /data
    ... CMD ["/bin/sh"]
    ... '''
    >>> f = BytesIO(dockerfile.encode('utf-8'))
    >>> cli = APIClient(base_url='tcp://127.0.0.1:2375')
    >>> response = [line for line in cli.build(
    ...     fileobj=f, rm=True, tag='yourname/volume'
    ... )]
    >>> response
    ['{"stream":" ---\u003e a9eb17255234\n"}',
     '{"stream":"Step 1 : VOLUME /data\n"}',
     '{"stream":" ---\u003e Running in abdc1e6896c6\n"}',
     '{"stream":" ---\u003e 713bca62012e\n"}',
     '{"stream":"Removing intermediate container abdc1e6896c6\n"}',
     '{"stream":"Step 2 : CMD [\"/bin/sh\"]\n"}',
     '{"stream":" ---\u003e Running in dba30f2a1a7e\n"}',
     '{"stream":" ---\u003e 032b8b2855fc\n"}',
     '{"stream":"Removing intermediate container dba30f2a1a7e\n"}',
     '{"stream":"Successfully built 032b8b2855fc\n"}']

Args:
    path (str): Path to the directory containing the Dockerfile
    fileobj: A file object to use as the Dockerfile. (Or a file-like
        object)
    tag (str): A tag to add to the final image
    quiet (bool): Whether to return the status
    nocache (bool): Don't use the cache when set to ``True``
    rm (bool): Remove intermediate containers. The ``docker build``
        command now defaults to ``--rm=true``, but we have kept the old
        default of `False` to preserve backward compatibility
    timeout (int): HTTP timeout
    custom_context (bool): Optional if using ``fileobj``
    encoding (str): The encoding for a stream. Set to ``gzip`` for
        compressing
    pull (bool): Downloads any updates to the FROM image in Dockerfiles
    forcerm (bool): Always remove intermediate containers, even after
        unsuccessful builds
    dockerfile (str): path within the build context to the Dockerfile
    gzip (bool): If set to ``True``, gzip compression/encoding is used
    buildargs (dict): A dictionary of build arguments
    container_limits (dict): A dictionary of limits applied to each
        container created by the build process. Valid keys:

        - memory (int): set memory limit for build
        - memswap (int): Total memory (memory + swap), -1 to disable
            swap
        - cpushares (int): CPU shares (relative weight)
        - cpusetcpus (str): CPUs in which to allow execution, e.g.,
            ``"0-3"``, ``"0,1"``
    decode (bool): If set to ``True``, the returned stream will be
        decoded into dicts on the fly. Default ``False``
    shmsize (int): Size of `/dev/shm` in bytes. The size must be
        greater than 0. If omitted the system uses 64MB
    labels (dict): A dictionary of labels to set on the image
    cache_from (:py:class:`list`): A list of images used for build
        cache resolution
    target (str): Name of the build-stage to build in a multi-stage
        Dockerfile
    network_mode (str): networking mode for the run commands during
        build
    squash (bool): Squash the resulting images layers into a
        single layer.
    extra_hosts (dict): Extra hosts to add to /etc/hosts in building
        containers, as a mapping of hostname to IP address.
    platform (str): Platform in the format ``os[/arch[/variant]]``
    isolation (str): Isolation technology used during build.
        Default: `None`.
    use_config_proxy (bool): If ``True``, and if the docker client
        configuration file (``~/.docker/config.json`` by default)
        contains a proxy configuration, the corresponding environment
        variables will be set in the container being built.

Returns:
    A generator for the build output.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
    ``TypeError``
        If neither ``path`` nor ``fileobj`` is specified.
Nz,Either path or fileobj needs to be provided.z.Can not use custom encoding if gzip is enabledzInvalid container_limits key z,You must specify fileobj with custom_context)zhttp://zhttps://zgit://zgithub.com/zgit@z-You must specify a directory to build in pathz.dockerignorec                 *    U S:g  =(       a    U S   S:g  $ )N r   # )xs    #lib/third_party/docker/api/build.py<lambda>%BuildApiMixin.build.<locals>.<lambda>   s    !r'"9adck"9    )exclude
dockerfilegzipr   z/build)tremoteqnocachermforcermpullr   	buildargsz1.22shmsizez/shmsize was only introduced in API version 1.22z1.23labelsz.labels was only introduced in API version 1.23z1.25	cachefromz2cache_from was only introduced in API version 1.25z1.29targetz.target was only introduced in API version 1.29networkmodez4network_mode was only introduced in API version 1.25squashz.squash was only introduced in API version 1.25z1.27z3extra_hosts was only introduced in API version 1.27
extrahostsz1.32z0platform was only introduced in API version 1.32platformz1.24z1isolation was only introduced in API version 1.24	isolationzContent-Typezapplication/tarzContent-EncodingT)dataparamsheadersstreamtimeout)decode))	TypeErrorr   DockerExceptionkeysr   CONTAINER_LIMITS_KEYSr   mkbuildcontext
startswithospathisdirjoinexistsopenlistfilterread
splitlinesstripprocess_dockerfiletar_urlupdate_proxy_configsget_environmentitems
setdefaultjsondumpsversion_gte_versionInvalidVersion
version_lt
isinstancedictformat_extra_hosts_set_auth_headers_postclose_stream_helper))selfr6   tagquietfileobjr   r   r-   custom_contextencodingr   r   r   container_limitsr.   r   r   r    r!   
cache_fromr#   network_moder%   extra_hostsr'   r(   use_config_proxyr   contextr+   keydockerignorer   flineur*   
proxy_argskvresponses)                                            r   buildBuildApiMixin.build   sS   T  +1rO	<GOJKKH(((@  $((*C)999,,3C59  +  NOOG **73G__ ? @ @Ft$$KLL77<<o>LGww~~l++,'1"6923&&(2E2E2GH2G$2GH$ G (
 ,J=Jiig*4G "&v8HIIh$	
 	&',,<<>J"((*1$$Q* +MM;

9(=>?  77y'23++E    77xF);<=++D    77{DJJz,BCD++H    77x01++D    77}l;<++J    77x01++D  "v66++I  +t,,#66{CMM<56v66++F  "*F: v66++G  #,F;%'89G.6*+w'::  
 ~MMO""8F";;o I ('s   $-X1X,+X1,X11
Y z1.31c                 f    U R                  S5      nU R                  U R                  U5      S5      $ )a4  
Delete the builder cache

Returns:
    (dict): A dictionary containing information about the operation's
            result. The ``SpaceReclaimed`` key indicates the amount of
            bytes of disk space reclaimed.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/build/pruneT)rB   _resultrR   )rU   urls     r   prune_buildsBuildApiMixin.prune_builds  s+     ii'||DJJsOT22r   c           	         [         R                  S5        U R                  (       a  U R                  R                  (       a8  [         R                  S5        [        R
                  " U R                  S9U l        U R                  (       a  U R                  R                  5       n[        R                  U;  aE  [        R                  U;   a1  UR                  [        R                  0 5      U[        R                  '   [         R                  SR                  SR                  S UR                  5        5       5      5      5        U(       a  [        R                  " U5      US'   g g [         R                  S5        g )	NzLooking for auth configz2No auth config in memory - loading from filesystem)credstore_envzSending auth config ({})z, c              3   8   #    U  H  n[        U5      v   M     g 7f)N)repr).0rg   s     r   	<genexpr>2BuildApiMixin._set_auth_headers.<locals>.<genexpr>>  s     @/?!d1gg/?s   zX-Registry-ConfigzNo auth config found)logdebug_auth_configsis_emptyr   load_configrr   get_all_credentials	INDEX_URL
INDEX_NAMEgetformatr8   r1   encode_header)rU   r+   	auth_datas      r   rQ   BuildApiMixin._set_auth_headers'  s   		+, !!T%7%7%@%@IIJK!%!1!1"00"D **>>@I i/OOy0,5MM$//2,N	$..)II*11II@y~~/?@@ /3/A/A0+, 
 II,-r   )rz   )NNFNFFNFNFFNNFNFNNNNNNNNNT)
__name__
__module____qualname____firstlineno__rj   r   minimum_versionro   rQ   __static_attributes__r   r   r   r	   r	      sE    >B/38=?C@DFJFJ#D<L 6"3 #3  .r   r	   c           	         U (       d  gU n[         R                  R                  U 5      (       d  [         R                  R                  X5      n[        R
                  (       a{  UR                  [        R                  5      (       aW  SR                  [        R                  [         R                  R                  U[        [        R                  5      S  5      5      n[         R                  R                  U5      S   [         R                  R                  U5      S   :w  d3  [         R                  R                  X!5      R                  S5      (       a?  [        U5       nS[        R                  " S5      S 3UR!                  5       4sS S S 5        $ X:X  a  [         R                  R                  X!5      n U S 4$ ! , (       d  f       N6= f)N)NNz{}{}r   z..z.dockerfile.   r   )r5   r6   isabsr8   r   IS_WINDOWS_PLATFORMr4   WINDOWS_LONGPATH_PREFIXr   normpathlen
splitdriverelpathr:   randomgetrandbitsr=   )r   r6   abs_dockerfiledfs       r   r@   r@   J  sK   N77==$$d7((T__11.3 .3#]]11  "3y'H'H#I#JKN 	4 #rww'9'9.'I!'LLGGOON1<<TBB.!Rv11#6q9:	 "! # WW__^:
 "!s   "*F>>
G)rH   loggingr5   r   r   r   r   r   r   	getLoggerr   rx   r	   r@   r   r   r   <module>r      sA      	      !x. x.v	r   