o
    -wi%                     @   s
  d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZ ddlZddlmZmZmZmZmZmZ ddgZG d	d
 d
eeZG dd deeZG dd deeZG dd deeZG dd deZG dd deZG dd deZG dd deZdedefddZdS )z9Definition of the config object used by the Launch agent.    )Enum)ListOptional)	BaseModelFieldValidationErrorroot_validator	validatorN)AZURE_BLOB_REGEX"AZURE_CONTAINER_REGISTRY_URI_REGEX$ELASTIC_CONTAINER_REGISTRY_URI_REGEXGCP_ARTIFACT_REGISTRY_URI_REGEX
GCS_URI_RE	S3_URI_REr   AgentConfigc                   @      e Zd ZdZdZdZdZdS )EnvironmentTypez Enum of valid environment types.awsgcpazureN)__name__
__module____qualname____doc__r   r   r    r   r   Z/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/launch/agent/config.pyr      
    r   c                   @   r   )RegistryTypezEnum of valid registry types.ecracrgcrN)r   r   r   r   r   r   r    r   r   r   r   r   '   r   r   c                   @   r   )BuilderTypezEnum of valid builder types.dockerkanikonoopN)r   r   r   r   r"   r#   r$   r   r   r   r   r!   /   r   r!   c                   @   s   e Zd ZdZdZdZdS )TargetPlatformzEnum of valid target platforms.zlinux/amd64zlinux/arm64N)r   r   r   r   linux_amd64linux_arm64r   r   r   r   r%   7   s    r%   c                   @   s`   e Zd ZU dZedddZee ed< edddZ	ee
 ed< edede
de
fd	d
ZdS )RegistryConfiga4  Configuration for registry block.

    Note that we don't forbid extra fields here because:
    - We want to allow all fields supported by each registry
    - We will perform validation on the registry object itself later
    - Registry block is being deprecated in favor of destination field in builder
    NzThe type of registry to use.descriptiontypezThe URI of the registry.urireturnc                 C   s   t |S )Nvalidate_registry_uri)clsr,   r   r   r   validate_uriP   s   zRegistryConfig.validate_uri)r   r   r   r   r   r+   r   r   __annotations__r,   strr	   classmethodr1   r   r   r   r   r(   >   s   
 r(   c                   @   sp   e Zd ZU dZedddZee ed< edddZ	ee
 ed< G d	d
 d
ZeddededefddZdS )EnvironmentConfigz(Configuration for the environment block.NzThe type of environment to use.r)   r+   .zThe region to use.regionc                   @      e Zd ZdZdS )zEnvironmentConfig.ConfigallowNr   r   r   extrar   r   r   r   Config_       r;   Tprevaluesr-   c                 C   s(   |D ]}|dvrt d| d q|S )z+Check for extra fields and print a warning.)r+   r6   zUnrecognized field z5 in environment block. Please check your config file.)wandbtermwarn)r0   r?   keyr   r   r   check_extra_fieldsb   s   
z$EnvironmentConfig.check_extra_fields)r   r   r   r   r   r+   r   r   r2   r6   r3   r;   r   r4   dictrC   r   r   r   r   r5   V   s   
 r5   c                   @   sD  e Zd ZU edddZee ed< edddZee	 ed< edddZ
ee ed< edd	d
dZee	 ed< eddddZee	 ed< eddddZee	 ed< eddddZee	 ed< eddddZee	 ed< ededee	 dee	 fddZedded edefd!d"Zededee	 dee	 fd#d$ZdS )%BuilderConfigNzThe type of builder to use.r)   r+   zfThe destination to use for the built image. If not provided, the image will be pushed to the registry.destinationzfThe platform to use for the built image. If not provided, the platform will be detected automatically.platformz;The build context store to use. Required for kaniko builds.zbuild-context-store)r*   aliasbuild_context_storezwandb-launch-container-buildzName prefix of the build job.zbuild-job-namebuild_job_namez0The name of the secret to use for the build job.zsecret-namesecret_namez/The key of the secret to use for the build job.z
secret-key
secret_keyz%gcr.io/kaniko-project/executor:latestz)The image to use for the kaniko executor.zkaniko-imagekaniko_imager-   c                 C   s6   |du rdS t ttfD ]}||r|  S qtd)zHValidate that the build context store is a valid container registry URI.NzkInvalid build context store. Build context store must be a URI for an S3 bucket, GCS bucket, or Azure blob.)r   r   r
   match
ValueError)r0   rI   regexr   r   r   validate_build_context_store   s   
z*BuilderConfig.validate_build_context_storeTr=   r?   c                 C   s   |S )z9Right now there are no required fields for docker builds.r   )r0   r?   r   r   r   validate_docker   s   zBuilderConfig.validate_dockerc                 C   s   |du rdS t |S )z@Validate that the destination is a valid container registry URI.Nr.   )r0   rF   r   r   r   validate_destination   s   z"BuilderConfig.validate_destination)r   r   r   r   r+   r   r!   r2   rF   r3   rG   r%   rI   rJ   rK   rL   rM   r	   r4   rQ   r   rD   rR   rS   r   r   r   r   rE   n   sf   
 "rE   c                   @   s  e Zd ZU dZeg ddZee ed< eddZ	e
e ed< edd	dZe
e ed
< edddZe
e ed< edddZe
e ed< edddZe
e ed< edddZe
e ed< edddZe
e ed< edddZe
e ed< edddZe
e ed< G dd dZdS )r   z#Configuration for the Launch agent.z!The queues to use for this agent.)defaultr*   queuesz%The W&B entity to use for this agent.r)   entity   z/The maximum number of jobs to run concurrently.max_jobsz;The maximum number of sweep schedulers to run concurrently.max_schedulersFzWhether to use secure mode for this agent. If True, the agent will reject runs that attempt to override the entrypoint or image.secure_modeNzThe registry to use.registryzThe environment to use.environmentzThe builder to use.builderr   z@How verbose to print, 0 = default, 1 = verbose, 2 = very verbose	verbosity<   z[How many seconds to wait after receiving the stop command before forcibly cancelling a run.stopped_run_timeoutc                   @   r7   )zAgentConfig.ConfigforbidNr9   r   r   r   r   r;      r<   r;   )r   r   r   r   r   rU   r   r3   r2   rV   r   rX   intrY   rZ   boolr[   r(   r\   r5   r]   rE   r^   r`   r;   r   r   r   r   r      sT   
 r,   r-   c                 C   s   d}|  dr| dd } t| }|r/|dr$t|j|dd|ds-td| S t| }|rQ|drFt|j|dd|d	sOtd
| S t| }|rs|drht|j|dd|d	sqtd| S t	d|  d | S )av  Validate that the registry URI is a valid container registry URI.

    The URI should resolve to an image name in a container registry. The recognized
    formats are for ECR, ACR, and GCP Artifact Registry. If the URI does not match
    any of these formats, a warning is printed indicating the registry type is not
    recognized and the agent can't guarantee that images can be pushed.

    If the format is recognized but does not resolve to an image name, an
    error is raised. For example, if the URI is an ECR URI but does not include
    an image name or includes a tag as well as an image name, an error is raised.
    zDestination for built images may not include a tag, but the URI provided includes the suffix '{tag}'. Please remove the tag and try again. The agent will automatically tag each image with a unique hash of the source code.zhttps://   Ntag)re   
image_namezAn image name must be specified in the URI for a GCP Artifact Registry. Please provide a uri with the format 'https://<region>-docker.pkg.dev/<project>/<repository>/<image>'.
repositoryzA repository name must be specified in the URI for an Azure Container Registry. Please provide a uri with the format 'https://<registry-name>.azurecr.io/<repository>'.zA repository name must be specified in the URI for an Elastic Container Registry. Please provide a uri with the format 'https://<account-id>.dkr.ecr.<region>.amazonaws.com/<repository>'.z)Unable to recognize registry type in URI zN. You are responsible for ensuring the agent can push images to this registry.)

startswithr   rN   grouprO   formatr   r   r@   rA   )r,   tag_msgrN   r   r   r   r/      sF   










r/   )r   enumr   typingr   r   pydanticr   r   r   r   r	   r@   wandb.sdk.launch.utilsr
   r   r   r   r   r   __all__r3   r   r   r!   r%   r(   r5   rE   r   r/   r   r   r   r   <module>   s$     
N0