
    Cj>                     z    S SK r S SKrS SKrS SKrSSKJrJrJrJr  \R                  " \
5      r " S S5      rS rg)    N   )auth	constantserrorsutilsc                   h    \ rS rSr        SS jr\R                  " S5      S	S j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b5  [        R                  " U5      (       d  [        R                  " SU S35      eUR                  5        H1  nU[        R                  ;  d  M  [        R                  " SU S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$R1                  U5        U(       aF  U R2                  R5                  5       n%U%R7                  5        H  u  n&n'UR9                  U&U'5        M     U(       a'  U$R1                  S[:        R<                  " U5      05        U(       aP  [        R>                  " U R@                  S5      (       a  U$R1                  SU05        O[        RB                  " S5      eU(       ad  [        R>                  " U R@                  S5      (       a(  U$R1                  S[:        R<                  " U5      05        O[        RB                  " S5      eU(       ad  [        R>                  " U R@                  S5      (       a(  U$R1                  S[:        R<                  " U5      05        O[        RB                  " S5      eU(       aP  [        R>                  " U R@                  S5      (       a  U$R1                  SU05        O[        RB                  " S5      eU(       aP  [        R>                  " U R@                  S5      (       a  U$R1                  SU05        O[        RB                  " S5      eU(       aP  [        R>                  " U R@                  S5      (       a  U$R1                  SU05        O[        RB                  " S5      eUbz  [        RD                  " U R@                  S 5      (       a  [        RB                  " S!5      e[G        U[H        5      (       a  [        RJ                  " U5      nU$R1                  S"U05        UbA  [        RD                  " U R@                  S#5      (       a  [        RB                  " S$5      eUU$S%'   UbA  [        RD                  " U R@                  S&5      (       a  [        RB                  " S'5      eUU$S('   Ub  S)S*0nU	(       a  U	US+'   U RM                  U5        U RO                  U#UU$US,US-9n(Ub  U(       d  URQ                  5         U RS                  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 tag 'z': invalid reference formatz,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    b/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/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   DockerExceptionr   	match_tagkeysr   CONTAINER_LIMITS_KEYS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))selfr7   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   s   T  +1rO	<GOJKKH(((@  ???3'',,#C5(CD  $((*C)999,,#C5(CD  +
  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   -Y*
Y%$Y*%Y**
Y9z1.31c                 B   U R                  S5      nXU4S:w  a<  [        R                  " U R                  S5      (       a  [        R
                  " S5      e0 nUb  [        R                  " U5      US'   Ub  X%S'   Ub  X5S'   U R                  U R                  XES9S	5      $ )
a  
Delete the builder cache

Args:
    filters (dict): Filters to process on the prune list.
        Needs Docker API v1.39+
        Available filters:
        - dangling (bool):  When set to true (or 1), prune only
        unused and untagged images.
        - until (str): Can be Unix timestamps, date formatted
        timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
        relative to the daemon's local time.
    keep_storage (int): Amount of disk space in bytes to keep for cache.
        Needs Docker API v1.39+
    all (bool): Remove all types of build cache.
        Needs Docker API v1.39+

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/pruneNNNz1.39zS`filters`, `keep_storage`, and `all` args are only available for API version > 1.38filterszkeep-storageall)r*   T)	rC   r   rN   rL   r   rM   convert_filters_resultrS   )rV   ro   keep_storagerp   urlr*   s         r   prune_buildsBuildApiMixin.prune_builds  s    8 ii'3'+==$$T]]F;;'')   % 5 5g >F9#%1>"?5M||DJJsJ:DAAr   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SR                  S U 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 (%s)z, c              3   8   #    U  H  n[        U5      v   M     g 7f)N)repr).0rh   s     r   	<genexpr>2BuildApiMixin._set_auth_headers.<locals>.<genexpr>X  s     59a$q''9s   zX-Registry-ConfigzNo auth config found)logdebug_auth_configsis_emptyr   load_configrx   get_all_credentials	INDEX_URL
INDEX_NAMEgetr9   encode_header)rV   r+   	auth_datas      r   rR   BuildApiMixin._set_auth_headersA  s    		+, !!T%7%7%@%@IIJK!%!1!1"00"D **>>@I i/OOy0,5MM$//2,N	$..)II*		5955
 /3/A/A0+, 
 II,-r   )r   )NNFNFFNFNFFNNFNFNNNNNNNNNTrn   )
__name__
__module____qualname____firstlineno__rk   r   minimum_versionru   rR   __static_attributes__r   r   r   r	   r	      sH    >B/38=?C@DFJFJ#G<R 6")B #)BV.r   r	   c                    U (       d  gU n[         R                  R                  U 5      (       d  [         R                  R                  X5      n[        R
                  (       aq  UR                  [        R                  5      (       aM  [         R                  R                  U[        [        R                  5      S  5      n[        R                   U 3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)NNr   z..z.dockerfile.   r   )r6   r7   isabsr9   r   IS_WINDOWS_PLATFORMr5   WINDOWS_LONGPATH_PREFIXnormpathlen
splitdriverelpathr;   randomgetrandbitsr>   )r   r7   abs_dockerfiler   dfs        r   rA   rA   c  sJ   N77==$$d7((T__11.3 .3ww''s9#D#DEFGIH ) A AB8*MN
4 #rww'9'9.'I!'LLGGOON1<<TBB.!Rv11#6q9:	 "! # WW__^:
 "!s   *F44
G)rI   loggingr6   r   r   r   r   r   r   	getLoggerr   r~   r	   rA   r   r   r   <module>r      s9      	  - -!U. U.p
r   