CircleCi Orbs sidlinux22/aws-code-deploy
This CircleCi Orb is designed to interact with AWS CodeDeploy and retrieve deployment-related information. It has several functions to perform different tasks related to CodeDeploy deployments.
-
Import Statements:
- The script imports necessary modules such as
os,sys,boto3,time,logging, andThreadPoolExecutorfrom theconcurrent.futuresmodule.
- The script imports necessary modules such as
-
Logging Configuration:
- The logging module is configured to log messages with a specific format and level.
-
fetch_target_deploymentFunction:- This function fetches information about a target deployment in CodeDeploy.
- It takes the
application_name,deployment_group_name, andpre_deploy_idas input parameters. - It uses the
boto3client for CodeDeploy to retrieve the deployment information. - The function waits for the deployment to start and checks for any errors or timeouts.
- It returns the
deploy_idandinstance_idsassociated with the deployment.
-
fetch_target_statusFunction:- This function retrieves the status of a specific target instance in a CodeDeploy deployment.
- It takes the
deploy_idandtarget_idas input parameters. - It uses the
boto3client for CodeDeploy to fetch the target's status. - It returns the
target_idandstatusof the target instance.
-
fetch_code_deploy_statusFunction:- This function fetches the status of all target instances in a CodeDeploy deployment.
- It calls the
fetch_target_deploymentfunction to get thedeploy_idandinstance_ids. - It continuously checks the status of each instance in the deployment until completion.
- It counts the instances in different status categories such as completed, in progress, failed, stopped, pending, ready, and skipped.
- It checks for various conditions such as completion, failure, timeouts, and returns appropriate exit codes.
-
fetch_deployment_idFunction:- This function retrieves the deployment ID for a specified application and deployment group.
- It takes the
application_nameanddeployment_group_nameas input parameters. - It uses the
boto3client for CodeDeploy to fetch the deployment ID. - It prints the deployment ID and logs the information.
-
Main Execution Block:
- The script checks the command-line arguments provided and validates them.
- It determines the appropriate action based on the provided flag (
--get-deployment-statusor--get-deployment-id). - It retrieves the
application_nameanddeployment_group_namefrom the command-line arguments. - If the flag is
--get-deployment-status, it
fetches the pre_deploy_id and calls the fetch_code_deploy_status function.
- If the flag is
--get-deployment-id, it calls thefetch_deployment_idfunction. - It handles any errors that occur during execution and logs them.
- It exits with an appropriate exit code based on the execution result.
This script is designed to be run from the command line and provides two main functionalities: fetching the status of a CodeDeploy deployment and retrieving the deployment ID. It utilizes the boto3 library to interact with AWS CodeDeploy and requires AWS credentials to be set up properly.
Please note that certain values in the script, such as AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION, are expected to be provided as environment variables. Additionally, when running the script, specific command-line arguments are required depending on the desired functionality.
For detailed usage instructions, you can refer to the comments in the __main__ block of the script, which provide usage examples for each flag.
- CircleCI Orb Registry Page - The official registry page of this orb for all versions, executors, commands, and jobs described.
- CircleCI Orb Docs - Docs for using, creating, and publishing CircleCI Orbs.
We welcome issues and pull requests to this repository!
- Merge pull requests with desired changes to the main branch.
- For the best experience, squash-and-merge and use Conventional Commit Messages.
- Find the current version of the orb.
- You can run
circleci orb info sidlinux22/aws-code-deploy | grep "Latest"to see the current version.
- You can run
- Create a new Release on GitHub.
- Click "Choose a tag" and create a new semantically versioned tag (e.g., v1.0.0).
- We will have an opportunity to change this before we publish if needed after the next step.
- Click "Choose a tag" and create a new semantically versioned tag (e.g., v1.0.0).
- Click "+ Auto-generate release notes".
- This will create a summary of all the merged pull requests since the previous release.
- If you have used Conventional Commit Messages, it will be easy to determine what types of changes were made, allowing you to ensure the correct version tag is being published.
- Ensure the selected version tag is semantically accurate based on the included changes.
- Click "Publish Release".
- This will push a new tag and trigger your publishing pipeline on CircleCI.