HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/awscli/customizations/ecs/__pycache__/deploy.cpython-36.pyc
3

�T_�D�@s�ddlZddlZddlZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
ddlmZdZdZd	ZGd
d�de�ZGdd
�d
�ZGdd�d�ZGdd�d�ZdS)�N)�compat�config)�ClientError)�compat_open)�
exceptions�filehelpers)�BasicCommand�
�ihc	@s�eZdZdZdZdddd�dddd�d	d
dd�ddd
d�ddd
d�ddd
d�gZdZdZdZdZ	dd�Z
dd�Zdd�Zdd�Z
dd�Zd d!�Zd"d#�Zd$S)%�	ECSDeployZdeployaDeploys a new task definition to the specified ECS service. Only services that use CodeDeploy for deployments are supported. This command will register a new task definition, update the CodeDeploy appspec with the new task definition revision, create a CodeDeploy deployment, and wait for the deployment to successfully complete. This command will exit with a return code of 255 if the deployment does not succeed within 30 minutes by default or up to 10 minutes more than your deployment group's configured wait time (max of 6 hours).�servicezJThe short name or full Amazon Resource Name (ARN) of the service to updateT)�nameZ	help_textZrequiredztask-definitionz�The file path where your task definition file is located. The format of the file must be the same as the JSON output of: <codeblock>aws ecs register-task-definition --generate-cli-skeleton</codeblock>zcodedeploy-appspecaThe file path where your AWS CodeDeploy appspec file is located. The appspec file may be in JSON or YAML format. The <code>TaskDefinition</code> property will be updated within the appspec with the newly registered task definition ARN, overwriting any placeholder values in the file.�clusterz�The short name or full Amazon Resource Name (ARN) of the cluster that your service is running within. If you do not specify a cluster, the "default" cluster is assumed.Fzcodedeploy-applicationz�The name of the AWS CodeDeploy application to use for the deployment. The specified application must use the 'ECS' compute platform. If you do not specify an application, the application name <code>AppECS-[CLUSTER_NAME]-[SERVICE_NAME]</code> is assumed.zcodedeploy-deployment-groupa*The name of the AWS CodeDeploy deployment group to use for the deployment. The specified deployment group must be associated with the specified ECS service and cluster. If you do not specify a deployment group, the deployment group name <code>DgpECS-[CLUSTER_NAME]-[SERVICE_NAME]</code> is assumed.z6Successfully registered new ECS task definition {arn}
z%Successfully created deployment {id}
z8Successfully deployed {task_def} to service '{service}'
zcustomization/ecs-deploycCs�|j|j|j�\}}t|j|||j�}|j||�|_|jjd|j	|j
tj|jd�d�}|j
|�|jj�|_|j||�|_|j||�dS)NZ
codedeploy)�user_agent_extra)�region_name�verifyr)�_load_file_argsZtask_definitionZcodedeploy_appspec�	ECSClientZ_session�USER_AGENT_EXTRA�_get_resource_names�	resources�
create_client�region�
verify_sslr�Config�_validate_code_deploy_resources�
_cd_validator�get_deployment_wait_time�	wait_time�_register_task_def�task_def_arn�_create_and_wait_for_deployment)�self�parsed_args�parsed_globals�register_task_def_kwargs�appspec_objZecs_client_wrapperZcodedeploy_client�r'�/usr/lib/python3.6/deploy.py�	_run_mainrs 


zECSDeploy._run_maincCs�t||�}|j|j�|j|jd|jd�}tjj|jj	|d��|j
||j�|jd}tjj|jj	|j|d��tjj
�dS)N�app_name�deployment_group_name)�idr)Ztask_defr)�CodeDeployer�update_task_def_arnr �create_deploymentr�sys�stdout�write�MSG_CREATED_DEPLOYMENT�format�wait_for_deploy_successr�MSG_SUCCESS�flush)r"�clientZappspecZdeployer�
deployment_id�service_namer'r'r(r!�s


z)ECSDeploy._create_and_wait_for_deploymentcCsltjjtjj|��}yt|��
}|j�SQRXWn6tttfk
rf}zt	j
||d��WYdd}~XnXdS)N)�	file_path�error)�os�path�
expandvars�
expanduserr�read�OSError�IOError�UnicodeDecodeErrorrZ
FileLoadError)r"r;�	full_path�f�er'r'r(�_get_file_contents�s
zECSDeploy._get_file_contentscCsR|j�}|d}|d}tj|||j�}tj|||j�}||d||d||d�S)Nr:�cluster_name�service_arn�cluster_arn)rrJrrKr*r+)�get_service_detailsrZget_app_nameZcodedeploy_applicationZget_deploy_group_nameZcodedeploy_deployment_group)r"�args�
ecs_client�service_detailsr:rIZapplication_namer+r'r'r(r�szECSDeploy._get_resource_namescCs0|j|�}tj|�}|j|�}tj|�}||fS)N)rH�json�loadsrZ
parse_appspec)r"Ztask_def_argZappspec_argZtask_def_stringr%Zappspec_stringr&r'r'r(r�s




zECSDeploy._load_file_argscCs:|j|�}|dd}tjj|jj|d��tjj�|S)N�taskDefinitionZtaskDefinitionArn)Zarn)�register_task_definitionr0r1r2�MSG_TASK_DEF_REGISTEREDr4r7)r"Ztask_def_kwargsrN�responser r'r'r(r�s


zECSDeploy._register_task_defcCs&t||j�}|j�|j�||_dS)N)�CodeDeployValidatorr�describe_cd_resources�validate_allr)r"r8Z	validatorr'r'r(r�sz)ECSDeploy._validate_code_deploy_resourcesN)�__name__�
__module__�__qualname__�NAMEZDESCRIPTIONZ	ARG_TABLErTr3r6rr)r!rHrrrrr'r'r'r(rs>

		rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)r-zKWaiting for {deployment_id} to succeed (will wait up to {wait} minutes)...
cCs||_||_dS)N)�_client�
_appspec_dict)r"�	cd_clientZappspec_dictr'r'r(�__init__�szCodeDeployer.__init__cCsX|j||�}y|jjf|�}Wn0tk
rN}ztjd|d��WYdd}~XnX|dS)Nzcreate deployment)�actionr<�deploymentId)�_get_create_deploy_requestr]r/rr�ServiceClientError)r"r*�deploy_grp_nameZrequest_objrUrGr'r'r(r/�szCodeDeployer.create_deploymentcCs$tj|j�}tj|�}tj|�j�S)N)rP�dumpsr^rZensure_bytes�hashlib�sha256Z	hexdigest)r"Zappspec_strZappspec_encodedr'r'r(�_get_appspec_hash�s
zCodeDeployer._get_appspec_hashcCs$||dtj|j�|j�d�d�d�S)NZAppSpecContent)Zcontentrh)ZrevisionTypeZappSpecContent)�applicationName�deploymentGroupNameZrevision)rPrfr^ri)r"r*rer'r'r(rc�s

z'CodeDeployer._get_create_deploy_requestcCs�|j}tjd|d�}g}x\||D]P}x@|D]8}||}tj||d�}||}	tj||	d�}
||	|
<q,W|j|�q"W|||<||_dS)a�
        Inserts the ARN of the previously created ECS task definition
        into the provided appspec.

        Expected format of ECS appspec (YAML) is:
            version: 0.0
            resources:
              - <service-name>:
                  type: AWS::ECS::Service
                  properties:
                    taskDefinition: <value>  # replace this
                    loadBalancerInfo:
                      containerName: <value>
                      containerPort: <value>
        zcodedeploy-appspecrZ
propertiesrRN)r^rZfind_required_key�append)r"Znew_arnr&Z
resources_keyZupdated_resources�resourcer
Zresource_contentZproperties_keyZproperties_contentZtask_def_keyr'r'r(r.�s 



z CodeDeployer.update_task_def_arncCsn|jjd�}|dk	r"|tkr"t}n|dks2|dkr6d}t}|d|}||d�}|j||�|j||d�dS)NZdeployment_successful��<)ZDelayZMaxAttempts)rbZWaiterConfig)r]Z
get_waiter�MAX_WAIT_MIN�DEFAULT_DELAY_SEC�_show_deploy_wait_msg�wait)r"r,�wait_minZwaiterZ	delay_secZmax_attemptsrr'r'r(r5(sz$CodeDeployer.wait_for_deploy_successcCs&tjj|jj||d��tjj�dS)N)r9rs)r0r1r2�MSG_WAITINGr4r7)r"r,rtr'r'r(rr;s
z"CodeDeployer._show_deploy_wait_msgN)rYrZr[rur`r/rircr.r5rrr'r'r'r(r-�s
+r-c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)rVcCs||_||_dS)N)r]�_resource_names)r"r_rr'r'r(r`CszCodeDeployValidator.__init__cCs�y|jj|jdd�|_Wn0tk
rJ}ztjd|d��WYdd}~XnXy*|jd}|jd}|jj||d�|_Wn0tk
r�}ztjd|d��WYdd}~XnXdS)Nr*)rjz describe Code Deploy application)rar<r+)rjrkz%describe Code Deploy deployment group)	r]Zget_applicationrv�app_detailsrrrdZget_deployment_group�deployment_group_details)r"rG�dgpZappr'r'r(rWGs

z)CodeDeployValidator.describe_cd_resourcescCs\t|d�s|jdkrdS|jd}|d}|dd}d}||d}||}|tSdS)Nrx�deploymentGroupInfoZ blueGreenDeploymentConfigurationZdeploymentReadyOptionZwaitTimeInMinutesZ)terminateBlueInstancesOnDeploymentSuccessZterminationWaitTimeInMinutes)�hasattrrx�TIMEOUT_BUFFER_MIN)r"Zdgp_infoZblue_green_infoZdeploy_ready_wait_minZ
terminate_keyZtermination_wait_minZconfigured_waitr'r'r(rXs

z,CodeDeployValidator.get_deployment_wait_timecCs|j�|j�dS)N)�validate_application�validate_deployment_group)r"r'r'r(rXlsz CodeDeployValidator.validate_allcCs.|jd}|jdddkr*tjd|d��dS)Nr*Zapplication�computePlatform�ECSZApplication)rmr
)rvrwr�InvalidPlatformError)r"r*r'r'r(r}ps
z(CodeDeployValidator.validate_applicationcCs�|jd}|jd}|jd}|jd}|jd}|jd}|d}|dkrZtjd	|d
��|jdd}x\|D]T}	|	d}
|
|kr�|
|kr�tj|d|d
��|	d}||krn||krntj|d|d
��qnWdS)Nr+rrJrrKrzrr�zDeployment Group)rmr
ZecsServices�serviceName)Zdg_namermZ
resource_nameZclusterName)rvrxrr�ZInvalidProperyError)r"ryrrJrrKZgrp_infoZcompute_platformZtarget_services�targetZtarget_servZtarget_clusterr'r'r(r~vs(







z-CodeDeployValidator.validate_deployment_groupN)	rYrZr[r`rWrrXr}r~r'r'r'r(rVBsrVc@s$eZdZdd�Zdd�Zdd�ZdS)rcCs6||_tj|d�|_|jd|j|j|j|jd�|_dS)N)rZecs)r�endpoint_urlrr)	�_argsrrZ_custom_configrrr�rr])r"Zsessionr#r$rr'r'r(r`�szECSClient.__init__cCs�|jj}|dksdrd}y|jj||jjgd�}Wn0tk
rb}ztjd|d��WYdd}~XnXt|d�dkr�tj	|jj|d��|dd}t
j|d	�}|d
|d|d	|d�S)
N��default)r�serviceszdescribe ECS service)rar<r�r)rrZ
clusterArnZ
serviceArnr�)rJr:rKrI)r�rr]Zdescribe_servicesrrrrd�lenZInvalidServiceErrorrZget_cluster_name_from_arn)r"rZservice_responserGrOrIr'r'r(rL�s&
zECSClient.get_service_detailscCsHy|jjf|�}Wn0tk
rB}ztjd|d��WYdd}~XnX|S)Nzregister ECS task definition)rar<)r]rSrrrd)r"�kwargsrUrGr'r'r(rS�sz"ECSClient.register_task_definitionN)rYrZr[r`rLrSr'r'r'r(r�s
r)rgrPr=r0ZbotocorerrZbotocore.exceptionsrZ
awscli.compatrZawscli.customizations.ecsrrZawscli.customizations.commandsrr|rqrprr-rVrr'r'r'r(�<module>s 9lR