HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/customizations/ecs/__pycache__/deploy.cpython-310.pyc
o

.&�a�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)%�	ECSDeploy�deployaDeploys 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)�name�	help_text�requiredztask-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>�codedeploy-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�\}}t|j|||j�}|�||�|_|jjd|j	|j
tj|jd�d�}|�
|�|j��|_|�||�|_|�||�dS)N�
codedeploy��user_agent_extra)�region_name�verifyr)�_load_file_args�task_definition�codedeploy_appspec�	ECSClient�_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_obj�ecs_client_wrapper�codedeploy_client�r2�B/usr/lib/python3/dist-packages/awscli/customizations/ecs/deploy.py�	_run_mainrs,�����
�zECSDeploy._run_maincCs�t||�}|�|j�|�|jd|jd�}tj�|jj	|d��|�
||j�|jd}tj�|jj	|j|d��tj�
�dS)N�app_name�deployment_group_name)�idr
)�task_defr
)�CodeDeployer�update_task_def_arnr)�create_deploymentr�sys�stdout�write�MSG_CREATED_DEPLOYMENT�format�wait_for_deploy_successr'�MSG_SUCCESS�flush)r+�client�appspec�deployer�
deployment_id�service_namer2r2r3r*�s"
��
��z)ECSDeploy._create_and_wait_for_deploymentc
Csztj�tj�|��}zt|��
}|��Wd�WS1swYWdStttfy<}zt	j
||d��d}~ww)N)�	file_path�error)�os�path�
expandvars�
expanduserr�read�OSError�IOError�UnicodeDecodeErrorr�
FileLoadError)r+rI�	full_path�f�er2r2r3�_get_file_contents�s
(����zECSDeploy._get_file_contentscCsR|��}|d}|d}t�|||j�}t�|||j�}||d||d||d�S)NrH�cluster_name�service_arn�cluster_arn)r
rYrrZr5r6)�get_service_detailsr�get_app_name�codedeploy_application�get_deploy_group_name�codedeploy_deployment_group)r+�args�
ecs_client�service_detailsrHrX�application_namer6r2r2r3r�s ���zECSDeploy._get_resource_namescCs0|�|�}t�|�}|�|�}t�|�}||fS�N)rW�json�loadsr�
parse_appspec)r+�task_def_arg�appspec_arg�task_def_stringr.�appspec_stringr/r2r2r3r�s




zECSDeploy._load_file_argscCs:|�|�}|dd}tj�|jj|d��tj��|S)N�taskDefinition�taskDefinitionArn)�arn)�register_task_definitionr<r=r>�MSG_TASK_DEF_REGISTEREDr@rC)r+�task_def_kwargsra�responser)r2r2r3r(�s
�
zECSDeploy._register_task_defcCs&t||j�}|��|��||_dSrd)�CodeDeployValidatorr�describe_cd_resources�validate_allr%)r+rD�	validatorr2r2r3r$�s
z)ECSDeploy._validate_code_deploy_resourcesN)�__name__�
__module__�__qualname__�NAME�DESCRIPTION�	ARG_TABLErpr?rBrr4r*rWrrr(r$r2r2r2r3rsR���
��	���<�		rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)r9zKWaiting for {deployment_id} to succeed (will wait up to {wait} minutes)...
cC�||_||_dSrd)�_client�
_appspec_dict)r+�	cd_client�appspec_dictr2r2r3�__init__��
zCodeDeployer.__init__c
CsP|�||�}z|jjdi|��}W|dSty'}ztjd|d��d}~ww)Nzcreate deployment��actionrJ�deploymentIdr2)�_get_create_deploy_requestr~r;rr�ServiceClientError)r+r5�deploy_grp_name�request_objrrrVr2r2r3r;�s�����zCodeDeployer.create_deploymentcCs$t�|j�}t�|�}t�|���Srd)re�dumpsrr�ensure_bytes�hashlib�sha256�	hexdigest)r+�appspec_str�appspec_encodedr2r2r3�_get_appspec_hash�s
zCodeDeployer._get_appspec_hashcCs$||dt�|j�|��d�d�d�S)N�AppSpecContent)�contentr�)�revisionType�appSpecContent)�applicationName�deploymentGroupName�revision)rer�rr�)r+r5r�r2r2r3r��s
���z'CodeDeployer._get_create_deploy_requestcCs�|j}t�d|d�}g}||D]&}|D]}||}t�||d�}||}	t�||	d�}
||	|
<q|�|�q|||<||_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>
        rr�
propertiesrlN)rr�find_required_key�append)r+�new_arnr/�
resources_key�updated_resources�resourcer�resource_content�properties_key�properties_content�task_def_keyr2r2r3r:�s&���

z CodeDeployer.update_task_def_arncCsn|j�d�}|dur|tkrt}n
|dus|dkrd}t}|d|}||d�}|�||�|j||d�dS)N�deployment_successful��<)�Delay�MaxAttempts)r��WaiterConfig)r~�
get_waiter�MAX_WAIT_MIN�DEFAULT_DELAY_SEC�_show_deploy_wait_msg�wait)r+r7�wait_min�waiter�	delay_sec�max_attemptsrr2r2r3rA(s�z$CodeDeployer.wait_for_deploy_successcCs&tj�|jj||d��tj��dS)N)rGr�)r<r=r>�MSG_WAITINGr@rC)r+r7r�r2r2r3r�;s��z"CodeDeployer._show_deploy_wait_msgN)rwrxryr�r�r;r�r�r:rAr�r2r2r2r3r9�s
+r9c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)rscCr}rd)r~�_resource_names)r+r�rr2r2r3r�Cr�zCodeDeployValidator.__init__c
Cs�z
|jj|jdd�|_Wnty }ztjd|d��d}~wwz|jd}|jd}|jj||d�|_WdStyJ}ztjd|d��d}~ww)Nr5)r�z describe Code Deploy applicationr�r6)r�r�z%describe Code Deploy deployment group)	r~�get_applicationr��app_detailsrrr��get_deployment_group�deployment_group_details)r+rV�dgp�appr2r2r3rtGs,����

����z)CodeDeployValidator.describe_cd_resourcescCsVt|d�r
|jdurdS|jd}|d}|dd}d}||d}||}|tS)Nr��deploymentGroupInfo� blueGreenDeploymentConfiguration�deploymentReadyOption�waitTimeInMinutes�)terminateBlueInstancesOnDeploymentSuccess�terminationWaitTimeInMinutes)�hasattrr��TIMEOUT_BUFFER_MIN)r+�dgp_info�blue_green_info�deploy_ready_wait_min�
terminate_key�termination_wait_min�configured_waitr2r2r3r&Xs



�
�z,CodeDeployValidator.get_deployment_wait_timecCs|��|��dSrd)�validate_application�validate_deployment_group)r+r2r2r3rulsz CodeDeployValidator.validate_allcCs.|jd}|jdddkrtjd|d��dS)Nr5�application�computePlatform�ECS�Application�r�r)r�r�r�InvalidPlatformError)r+r5r2r2r3r�ps
��z(CodeDeployValidator.validate_applicationcCs�|jd}|jd}|jd}|jd}|jd}|jd}|d}|dkr-tjd	|d
��|jdd}|D]*}	|	d}
|
|krL|
|krLtj|d|d
��|	d}||kr`||kr`tj|d|d
��q6dS)Nr6r
rYrrZr�r�r�zDeployment Groupr��ecsServices�serviceName)�dg_namer��
resource_name�clusterName)r�r�rr��InvalidProperyError)r+r�r
rYrrZ�grp_info�compute_platform�target_services�target�target_serv�target_clusterr2r2r3r�vs4





������z-CodeDeployValidator.validate_deployment_groupN)	rwrxryr�rtr&rur�r�r2r2r2r3rsBsrsc@s$eZdZdd�Zdd�Zdd�ZdS)rcCs6||_tj|d�|_|jd|j|j|j|jd�|_dS)Nr�ecs)r�endpoint_urlrr)	�_argsrr#�_custom_configr r!r�r"r~)r+�sessionr,r-rr2r2r3r��s�zECSClient.__init__c
Cs�|jj}|dus	nd}z
|jj||jjgd�}Wnty+}ztjd|d��d}~wwt|d�dkr=tj	|jj|d��|dd}t
�|d	�}|d
|d|d	|d�S)
N��default)r�serviceszdescribe ECS servicer�r�r)r
r�
clusterArn�
serviceArnr�)rYrHrZrX)r�rr~�describe_servicesr
rrr��len�InvalidServiceErrorr�get_cluster_name_from_arn)r+r�service_responserVrbrXr2r2r3r[�s6


��������zECSClient.get_service_detailsc
Cs@z|jjdi|��}W|Sty}ztjd|d��d}~ww)Nzregister ECS task definitionr�r2)r~rorrr�)r+�kwargsrrrVr2r2r3ro�s�����z"ECSClient.register_task_definitionN)rwrxryr�r[ror2r2r2r3r�s
r)r�rerKr<�botocorerr�botocore.exceptionsr�
awscli.compatr�awscli.customizations.ecsrr�awscli.customizations.commandsrr�r�r�rr9rsrr2r2r2r3�<module>s"
9lR