Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ workflows:
- orb-tools/continue:
pipeline_number: << pipeline.number >>
vcs_type: << pipeline.project.type >>
orb_name: aws-codeDeploy-status
orb_name: aws-code-deploy
requires: [orb-tools/lint, orb-tools/pack, orb-tools/review, shellcheck/check]
filters: *filters
16 changes: 13 additions & 3 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ orbs:
# Reference your orb's jobs and commands below as they will exist when built.
orb-tools: circleci/orb-tools@12.0
# The orb definition is intentionally not included here. It will be injected into the pipeline.
aws-codeDeploy-status: {}
aws-code-deploy: sidlinux22/aws-code-deploy@0.0.1

# Use this tag to ensure test jobs always run,
# even though the downstream publish job will only run on release tags.
Expand All @@ -28,7 +28,17 @@ jobs:
steps:
- checkout
# Run your orb's commands to validate them.
- aws-codeDeploy-status/get-deployment-id
- aws-code-deploy/get_deployment_id:
application_name: "change_to_codeDeploy_application_name"
deployment_group_name: "change_to_codeDeploy_deployment_group_name"
# Get the latest deployment ID for the specified application and deployment group
# Add CodeDeploy Steps like copying Artifcate to S3 etc...
# Fetch new CodeDeploy deployment ID status.
- aws-code-deploy/get_deployment_status:
application_name: "change_to_codeDeploy_application_name"
deployment_group_name: "change_to_codeDeploy_deployment_group_name"
deployment_start_timeout: 300
deployment_completion_timeout: 600
workflows:
test-deploy:
jobs:
Expand All @@ -40,7 +50,7 @@ workflows:
- orb-tools/pack:
filters: *release-filters
- orb-tools/publish:
orb_name: sidlinux22/aws-codeDeploy-status
orb_name: sidlinux22/aws-code-deploy
vcs_type: << pipeline.project.type >>
pub_type: production
# Ensure this job requires all test jobs and the pack job.
Expand Down
79 changes: 62 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,84 @@
# Orb Template

# CircleCi Orbs [sidlinux22/aws-code-deploy](https://circleci.com/developer/orbs/orb/sidlinux22/aws-code-deploy)

[![CircleCI Build Status](https://circleci.com/gh/sidlinux22/aws-codeDeploy-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/sidlinux22/aws-codeDeploy-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/sidlinux22/aws-codeDeploy-orb.svg)](https://circleci.com/developer/orbs/orb/sidlinux22/aws-codeDeploy-orb) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/sidlinux22/aws-codeDeploy-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)


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.

## Script Components

1. Import Statements:
- The script imports necessary modules such as `os`, `sys`, `boto3`, `time`, `logging`, and `ThreadPoolExecutor` from the `concurrent.futures` module.

2. Logging Configuration:
- The logging module is configured to log messages with a specific format and level.

3. `fetch_target_deployment` Function:
- This function fetches information about a target deployment in CodeDeploy.
- It takes the `application_name`, `deployment_group_name`, and `pre_deploy_id` as input parameters.
- It uses the `boto3` client 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_id` and `instance_ids` associated with the deployment.

4. `fetch_target_status` Function:
- This function retrieves the status of a specific target instance in a CodeDeploy deployment.
- It takes the `deploy_id` and `target_id` as input parameters.
- It uses the `boto3` client for CodeDeploy to fetch the target's status.
- It returns the `target_id` and `status` of the target instance.

A project template for Orbs.
5. `fetch_code_deploy_status` Function:
- This function fetches the status of all target instances in a CodeDeploy deployment.
- It calls the `fetch_target_deployment` function to get the `deploy_id` and `instance_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.

This repository is designed to be automatically ingested and modified by the CircleCI CLI's `orb init` command.
6. `fetch_deployment_id` Function:
- This function retrieves the deployment ID for a specified application and deployment group.
- It takes the `application_name` and `deployment_group_name` as input parameters.
- It uses the `boto3` client for CodeDeploy to fetch the deployment ID.
- It prints the deployment ID and logs the information.

_**Edit this area to include a custom title and description.**_
7. 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-status` or `--get-deployment-id`).
- It retrieves the `application_name` and `deployment_group_name` from 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 the `fetch_deployment_id` function.
- 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.

---

## Resources

[CircleCI Orb Registry Page](https://circleci.com/developer/orbs/orb/sidlinux22/aws-codeDeploy-orb) - The official registry page of this orb for all versions, executors, commands, and jobs described.

[CircleCI Orb Docs](https://circleci.com/docs/orb-intro/#section=configuration) - Docs for using, creating, and publishing CircleCI Orbs.
- [CircleCI Orb Registry Page](https://circleci.com/developer/orbs/orb/sidlinux22/aws-code-deploy) - The official registry page of this orb for all versions, executors, commands, and jobs described.
- [CircleCI Orb Docs](https://circleci.com/docs/orb-intro/#section=configuration) - Docs for using, creating, and publishing CircleCI Orbs.

### How to Contribute

We welcome [issues](https://github.com/sidlinux22/aws-codeDeploy-orb/issues) to and [pull requests](https://github.com/sidlinux22/aws-codeDeploy-orb/pulls) against this repository!
We welcome [issues](https://github.com/sidlinux22/aws-codeDeploy-orb/issues) and [pull requests](https://github.com/sidlinux22/aws-codeDeploy-orb/pulls) to this repository!

### How to Publish An Update

1. Merge pull requests with desired changes to the main branch.
- For the best experience, squash-and-merge and use [Conventional Commit Messages](https://conventionalcommits.org/).
2. Find the current version of the orb.
- You can run `circleci orb info sidlinux22/aws-code-deploy | grep "Latest"` to see the current version.
3. Create a [new Release](https://github.com/sidlinux22/aws-codeDeploy-orb/releases/new) on GitHub.
- Click "Choose a tag" and _create_ a new [semantically versioned](http://semver.org/) tag. (ex: v1.0.0)
3. Create a [new Release](https://github.com/sidlinux22/aws-code-deploy/releases/new) on GitHub.
- Click "Choose a tag" and create a new [semantically versioned](http://semver.org/) tag (e.g., v1.0.0).
- We will have an opportunity to change this before we publish if needed after the next step.
4. Click _"+ Auto-generate release notes"_.
- This will create a summary of all of the merged pull requests since the previous release.
- If you have used _[Conventional Commit Messages](https://conventionalcommits.org/)_ it will be easy to determine what types of changes were made, allowing you to ensure the correct version tag is being published.
5. Now ensure the version tag selected is semantically accurate based on the changes included.
6. Click _"Publish Release"_.
- This will push a new tag and trigger your publishing pipeline on CircleCI.
4. 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](https://conventionalcommits.org/), it will be easy to determine what types of changes were made, allowing you to ensure the correct version tag is being published.
5. Ensure the selected version tag is semantically accurate based on the included changes.
6. Click "Publish Release".
- This will push a new tag and trigger your publishing pipeline on CircleCI.
8 changes: 4 additions & 4 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2.1

description: >
Sample orb description
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.
# This information will be displayed in the orb registry and is not mandatory.
display:
home_url: "https://github.com/sidlinux22/aws-codeDeploy-orb/tree/main#readme"
source_url: "https://github.com/sidlinux22/aws-codeDeploy-orb"

# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
# orbs:
# hello: circleci/hello-build@0.0.5
# Orb requires other orbs, you can import them like this.
orbs:
aws-cli: circleci/aws-cli@4.0.0
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
description: >
This command is to get CodeDeploy latest deployment.
parameters:
application-name:
application_name:
type: string
description: "The name of the CodeDeploy application."
deployment-group-name:
deployment_group_name:
type: string
description: "The name of the CodeDeploy deployment group."
steps:
- run:
environment:
APP_NAME: <<parameters.application-name>>
DEPLOY_GROUP_NAME: <<parameters.deployment-group-name>>
name: CodeDeploy - Get the latest Deployment ID for <<parameters.deployment-group-name>>
command: <<include(scripts/get-deployment-id.sh)>>
APP_NAME: <<parameters.application_name>>
DEPLOY_GROUP_NAME: <<parameters.deployment_group_name>>
name: CodeDeploy - Get the latest Deployment ID for <<parameters.deployment_group_name>>
command: <<include(scripts/get_deployment_id.sh)>>
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
description: >
This command is to get CodeDeploy latest deployment.
parameters:
application-name:
application_name:
type: string
description: "The name of the CodeDeploy application."
deployment-group-name:
deployment_group_name:
type: string
description: "The name of the CodeDeploy deployment group."
deployment-start-timeout:
deployment_start_timeout:
type: integer
default: 180
description: "Timeout for deployment start."
deployment-completion-timeout:
deployment_completion_timeout:
type: integer
default: 600
description: "Timeout for deployment completion."
pre-deployment-id:
pre_deployment_id:
default: ''
type: string
description: "Latest previous deployment ID."
steps:
- run:
environment:
APP_NAME: <<parameters.application-name>>
DEPLOY_GROUP_NAME: <<parameters.deployment-group-name>>
DEPLOYMENT_START_TIMEOUT: <<parameters.deployment-start-timeout>>
DEPLOYMENT_COMPLETION_TIMEOUT: <<parameters.deployment-completion-timeout>>
name: CodeDeploy - Fetch <<parameters.deployment-group-name>> deployment status.
command: <<include(scripts/get-deployment-status.sh)>>
APP_NAME: <<parameters.application_name>>
DEPLOY_GROUP_NAME: <<parameters.deployment_group_name>>
DEPLOYMENT_START_TIMEOUT: <<parameters.deployment_start_timeout>>
DEPLOYMENT_COMPLETION_TIMEOUT: <<parameters.deployment_completion_timeout>>
name: CodeDeploy - Fetch <<parameters.deployment_group_name>> deployment status.
command: <<include(scripts/get_deployment_status.sh)>>
18 changes: 9 additions & 9 deletions src/examples/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ usage:
region: AWS_REGION
# Provide AWS access key, secret access key, and region as environment variables
# Fetch latest deployment ID before new deployment start.
- aws-code-deploy/get-deployment-id:
application-name: "change_to_codeDeploy_application-name"
deployment-group-name: "change_to_codeDeploy_deployment-group-name"
- aws-code-deploy/get_deployment_id:
application_name: "change_to_codeDeploy_application_name"
deployment_group_name: "change_to_codeDeploy_deployment_group_name"
# Get the latest deployment ID for the specified application and deployment group
# Add CodeDeploy Steps like copying Artifcate to S3 etc...
# Fetch new CodeDeploy deployment ID status.
- aws-code-deploy/get-deployment-status:
application-name: "change_to_codeDeploy_application-name"
deployment-group-name: "change_to_codeDeploy_deployment-group-name"
deployment-start-timeout: "Optional_change_to_codeDeploy_deployment-start-timeout"
deployment-completion-timeout: "Optional_change_to_codeDeploy_deployment-completion-timeout"
- aws-code-deploy/get_deployment_status:
application_name: "change_to_codeDeploy_application_name"
deployment_group_name: "change_to_codeDeploy_deployment_group_name"
deployment_start_timeout: "Optional_change_to_codeDeploy_deployment_start_timeout"
deployment_completion_timeout: "Optional_change_to_codeDeploy_deployment_completion_timeout"
# Get the status of the new CodeDeploy deployment using the latest deployment ID
workflows:
version: 2
Expand All @@ -44,4 +44,4 @@ usage:
filters:
branches:
ignore: /develop|master/
# Specify branch filters for the workflow execution
# Specify branch filters for the workflow execution
2 changes: 1 addition & 1 deletion src/executors/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ parameters:

docker:
- image: cimg/aws:<<parameters.tag>>
resource_class: <<parameters.resource_class>>
resource_class: <<parameters.resource_class>>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
description: >
A job to get CodeDeploy latest deployment.
parameters:
application-name:
application_name:
type: string
default: ''
description: "The name of the CodeDeploy application."
deployment-group-name:
deployment_group_name:
type: string
default: ''
description: "The name of the CodeDeploy deployment group."
Expand All @@ -15,6 +15,6 @@ parameters:
default: default
executor: << parameters.executor >>
steps:
- get-deployment-id:
application-name: << parameters.application-name >>
deployment-group-name: << parameters.deployment-group-name>>
- get_deployment_id:
application_name: << parameters.application_name >>
deployment_group_name: << parameters.deployment_group_name>>
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
description: >
A job to get CodeDeploy latest deployment.
parameters:
application-name:
application_name:
type: string
default: ''
description: "The name of the CodeDeploy application."
deployment-group-name:
deployment_group_name:
type: string
default: ''
description: "The name of the CodeDeploy deployment group."
deployment-start-timeout:
deployment_start_timeout:
type: integer
default: 180
description: "Timeout for deployment start."
deployment-completion-timeout:
deployment_completion_timeout:
type: integer
default: 600
description: "Timeout for deployment completion."
Expand All @@ -23,6 +23,6 @@ parameters:
default: default
executor: << parameters.executor >>
steps:
- get-deployment-status:
application-name: << parameters.application-name >>
deployment-group-name: << parameters.deployment-group-name>>
- get_deployment_status:
application_name: << parameters.application_name >>
deployment_group_name: << parameters.deployment_group_name>>
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def fetch_deployment_id(application_name, deployment_group_name):
if __name__ == "__main__":
try:
if len(sys.argv) < 2 or sys.argv[1] not in ["--get-deployment-status", "--get-deployment-id"]:
logger.error("Usage: python script.py --get-deployment-status <application-name> <deployment-group-name> <pre-deploy-id>")
logger.error(" python script.py --get-deployment-id <application-name> <deployment-group-name>")
logger.error("Usage: python script.py --get-deployment-status <application_name> <deployment_group_name> <pre-deploy-id>")
logger.error(" python script.py --get-deployment-id <application_name> <deployment_group_name>")
exit(1)

flag = sys.argv[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ if ! python3 -c "import boto3" >/dev/null 2>&1; then
fi

# Define the URL for the Python script
script_url="https://raw.githubusercontent.com/sidlinux22/aws-codeDeploy-orb/dev-0.0.1/src/scripts/aws-codeDeploy-orb.py"
script_url="https://raw.githubusercontent.com/sidlinux22/aws-codeDeploy-orb/dev-0.0.1/src/scripts/aws_codeDeploy_orb.py"

# Retrieve Python script from GitHub and save it as a file
curl -sSLJO "$script_url"

# Run the Python script with the parameters and capture the output
PRE_Deployment_ID=$(python3 aws-codeDeploy-orb.py --get-deployment-id "${APP_NAME}" "${DEPLOY_GROUP_NAME}")
PRE_Deployment_ID=$(python3 aws_codeDeploy_orb.py --get-deployment-id "${APP_NAME}" "${DEPLOY_GROUP_NAME}")

# Print the result
echo "Latest Deployment ID is $PRE_Deployment_ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ if [[ -z "${PRE_Deployment_ID}" ]]; then
fi

# Define the URL for the Python script
script_url="https://raw.githubusercontent.com/sidlinux22/aws-codeDeploy-orb/dev-0.0.1/src/scripts/aws-codeDeploy-orb.py"
script_url="https://raw.githubusercontent.com/sidlinux22/aws-codeDeploy-orb/dev-0.0.1/src/scripts/aws_codeDeploy_orb.py"

# Retrieve Python script from GitHub and save it as a file
curl -sSLJO "$script_url"

# Run the Python script with the parameters and capture the output
python3 aws-codeDeploy-orb.py --get-deployment-status "${APP_NAME}" "${DEPLOY_GROUP_NAME}" "${PRE_Deployment_ID}"
python3 aws_codeDeploy_orb.py --get-deployment-status "${APP_NAME}" "${DEPLOY_GROUP_NAME}" "${PRE_Deployment_ID}"