HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/docker/api/__pycache__/build.cpython-310.pyc
o

�2.a�8�@stddlZddlZddlZddlZddlmZddlmZddlmZddlmZe�	e
�ZGdd�d�Zd	d
�Z
dS)�N�)�auth)�	constants)�errors)�utilsc@s@eZdZ								ddd�Ze�d�dd��Zd	d
�ZdS)�
BuildApiMixinNFTc(	Cs�d}}i}|
p	i}
|p
i}|dur|durtd��|r%|	dur%t�d��|
��D]}|tjvr8t�d|����q)|rD|sAtd��|}ne|durNt�|�}n[|�d�rV|}nSt	j
�|�s`td��t	j
�|d�}d} t	j
�
|�r�t|��}!ttd	d
�dd�|!����D���} Wd�n1s�wYt||�}tj|| ||d
�}|r�dn|	}	|�d�}"|||||||
|d�}#|#�|
�|r�|j��}$|$��D]
\}%}&|�|%|&�q�|r�|#�dt�|�i�|r�t�|jd�r�|#�d|i�nt�d��|�rt�|jd��r|#�dt�|�i�nt�d��|�r,t�|jd��r'|#�dt�|�i�nt�d��|�rDt�|jd��r?|#�d|i�nt�d��|�r\t�|jd��rW|#�d|i�nt�d��|�rtt�|jd��ro|#�d |i�nt�d!��|du�r�t� |jd"��r�t�d#��t!|t"��r�t�#|�}|#�d$|i�|du�r�t� |jd%��r�t�d&��||#d'<|du�r�t� |jd(��r�t�d)��||#d*<|du�r�d+d,i}|	�r�|	|d-<|�$|�|j%|"||#|d.|d/�}'|du�r�|�s�|�&�|j'|'|d0�S)1a�
        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
            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 enabledzInvalid container_limits key z,You must specify fileobj with custom_context)zhttp://zhttps://zgit://zgithub.com/zgit@z-You must specify a directory to build in pathz
.dockerignorecSs|dko	|ddkS)N�r�#�)�xr
r
�2/usr/lib/python3/dist-packages/docker/api/build.py�<lambda>��z%BuildApiMixin.build.<locals>.<lambda>cSsg|]}|���qSr
)�strip)�.0�lr
r
r�
<listcomp>�rz'BuildApiMixin.build.<locals>.<listcomp>)�exclude�
dockerfile�gziprz/build)�t�remote�q�nocache�rm�forcerm�pullr�	buildargsz1.22�shmsizez/shmsize was only introduced in API version 1.22z1.23�labelsz.labels was only introduced in API version 1.23z1.25�	cachefromz2cache_from was only introduced in API version 1.25z1.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.25z1.27z3extra_hosts was only introduced in API version 1.27�
extrahostsz1.32z0platform was only introduced in API version 1.32�platformz1.24z1isolation was only introduced in API version 1.24�	isolationzContent-Typezapplication/tarzContent-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�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)(�selfr4�tag�quiet�fileobjrrr+�custom_context�encodingrrr�container_limitsr,rrrr�
cache_fromr!�network_moder#�extra_hostsr%r&�use_config_proxyr�contextr)�key�dockerignorer�f�ur(�
proxy_args�k�v�responser
r
r�buildsi�
��

��
�
�


������
�

�
�

�	zBuildApiMixin.buildz1.31cCs|�d�}|�|�|�d�S)a|
        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)r?�_resultrO)rR�urlr
r
r�prune_buildss
zBuildApiMixin.prune_buildsc	Cs�t�d�|jr|jjrt�d�tj|jd�|_|jrT|j��}tj|vr5tj	|vr5|�
tj	i�|tj<t�d�d�dd�|�
�D����|rRt�|�|d<dSdSt�d	�dS)
NzLooking for auth configz2No auth config in memory - loading from filesystem)�
credstore_envzSending auth config ({})z, css�|]}t|�VqdS)N)�repr)rrcr
r
r�	<genexpr>=s�z2BuildApiMixin._set_auth_headers.<locals>.<genexpr>zX-Registry-ConfigzNo auth config found)�log�debug�
_auth_configs�is_emptyr�load_configrj�get_all_credentials�	INDEX_URL�
INDEX_NAME�get�formatr6r/�
encode_header)rRr)�	auth_datar
r
rrN&s,

�


����zBuildApiMixin._set_auth_headers)NNFNFFNFNFFNNFNFNNNNNNNNNT)�__name__�
__module__�__qualname__rfr�minimum_versionrirNr
r
r
rrs
�
rcCs�|sdS|}tj�|�s.tj�||�}tjr.|�tj�r.d�tjtj�	|t
tj�d���}tj�|�dtj�|�dksHtj�||��d�rit
|��}dt�d�d��|��fWd�S1sdwY||krttj�||�}|dfS)N)NNz{}{}rz..z.dockerfile.�r)r3r4�isabsr6r�IS_WINDOWS_PLATFORMr2�WINDOWS_LONGPATH_PREFIXrv�normpath�len�
splitdrive�relpathr8�random�getrandbitsr;)rr4�abs_dockerfile�dfr
r
rr=Is2
��� �
� �r=)rE�loggingr3r�rrrrr�	getLoggerryrmrr=r
r
r
r�<module>s
<