-
Notifications
You must be signed in to change notification settings - Fork 4
VED-1233: Replace manual release steps #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Thomas-Boyle
wants to merge
4
commits into
master
Choose a base branch
from
ved-1233-replace-manual-release-steps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f72ae9
Enhance blue/green deployment workflow for Lambda triggers
Thomas-Boyle 0174644
Refactor Lambda event source mappings and update deployment workflows
Thomas-Boyle 7cc77a6
Refactor environment variable validation in adopt_event_source_mappin…
Thomas-Boyle c807b68
Add delete_mapping function to manage event source mappings in adopt_…
Thomas-Boyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
utilities/scripts/manage_blue_green_event_source_mappings.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| mode="${1:-prepare-state}" | ||
| sub_environment="${SUB_ENVIRONMENT:-${sub_environment:-}}" | ||
|
|
||
| if [[ -z "${sub_environment}" ]]; then | ||
| echo "SUB_ENVIRONMENT must be set." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ ! "${sub_environment}" =~ -(blue|green)$ ]]; then | ||
|
Thomas-Boyle marked this conversation as resolved.
Outdated
|
||
| echo "Skipping Lambda trigger handoff for ${sub_environment}." | ||
| exit 0 | ||
| fi | ||
|
|
||
| current_colour="${BASH_REMATCH[1]}" | ||
| counterpart_colour="blue" | ||
| if [[ "${current_colour}" == "blue" ]]; then | ||
| counterpart_colour="green" | ||
| fi | ||
|
|
||
| counterpart_sub_environment="${sub_environment%-${current_colour}}-${counterpart_colour}" | ||
| current_workspace="$(terraform workspace show)" | ||
|
|
||
| if [[ "${current_workspace}" != "${sub_environment}" ]]; then | ||
| echo "Terraform workspace ${current_workspace} does not match SUB_ENVIRONMENT ${sub_environment}." | ||
| exit 1 | ||
| fi | ||
|
|
||
| lookup_mapping_uuid() { | ||
| local event_source_arn="$1" | ||
| local function_name="$2" | ||
| local mapping_uuid | ||
|
|
||
| mapping_uuid="$(aws lambda list-event-source-mappings \ | ||
| --event-source-arn "${event_source_arn}" \ | ||
| --function-name "${function_name}" \ | ||
| --query 'EventSourceMappings[0].UUID' \ | ||
| --output text)" | ||
|
|
||
| if [[ "${mapping_uuid}" == "None" ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| printf '%s' "${mapping_uuid}" | ||
| } | ||
|
|
||
| resolve_event_source_arns() { | ||
| id_sync_queue_arn="$(terraform output -raw id_sync_queue_arn)" | ||
| events_table_name="$(terraform output -raw dynamodb_table_name)" | ||
| delta_event_source_arn="$(aws dynamodb describe-table \ | ||
| --table-name "${events_table_name}" \ | ||
| --query 'Table.LatestStreamArn' \ | ||
| --output text)" | ||
|
|
||
| if [[ -z "${delta_event_source_arn}" || "${delta_event_source_arn}" == "None" ]]; then | ||
| echo "Unable to resolve the DynamoDB stream ARN for ${events_table_name}." | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| prepare_state() { | ||
| local address="$1" | ||
| local event_source_arn="$2" | ||
| local counterpart_function_name="$3" | ||
| local target_function_name="$4" | ||
| local mapping_uuid="" | ||
|
|
||
| mapping_uuid="$(lookup_mapping_uuid "${event_source_arn}" "${counterpart_function_name}")" | ||
|
Thomas-Boyle marked this conversation as resolved.
Outdated
|
||
| if [[ -z "${mapping_uuid}" ]]; then | ||
| mapping_uuid="$(lookup_mapping_uuid "${event_source_arn}" "${target_function_name}")" | ||
| fi | ||
|
|
||
| if [[ -z "${mapping_uuid}" ]]; then | ||
| echo "Unable to find an event source mapping for ${address}." | ||
| exit 1 | ||
| fi | ||
|
|
||
| terraform state rm "${address}" >/dev/null 2>&1 || true | ||
|
Thomas-Boyle marked this conversation as resolved.
Outdated
|
||
| terraform import "${address}" "${mapping_uuid}" >/dev/null | ||
|
|
||
| echo "Imported ${address} into workspace ${sub_environment} using ${mapping_uuid}." | ||
| } | ||
|
|
||
| cleanup_stale_mapping() { | ||
| local event_source_arn="$1" | ||
| local counterpart_function_name="$2" | ||
| local target_function_name="$3" | ||
| local counterpart_uuid="" | ||
| local target_uuid="" | ||
|
|
||
| counterpart_uuid="$(lookup_mapping_uuid "${event_source_arn}" "${counterpart_function_name}")" | ||
| target_uuid="$(lookup_mapping_uuid "${event_source_arn}" "${target_function_name}")" | ||
|
|
||
| if [[ -z "${target_uuid}" || "${target_uuid}" == "${counterpart_uuid}" ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| aws lambda delete-event-source-mapping --uuid "${target_uuid}" >/dev/null | ||
| echo "Deleted stale event source mapping ${target_uuid} for ${target_function_name}." | ||
| } | ||
|
|
||
| resolve_event_source_arns | ||
|
|
||
| target_delta_function="imms-${sub_environment}-delta-lambda" | ||
| counterpart_delta_function="imms-${counterpart_sub_environment}-delta-lambda" | ||
| target_id_sync_function="imms-${sub_environment}-id-sync-lambda" | ||
| counterpart_id_sync_function="imms-${counterpart_sub_environment}-id-sync-lambda" | ||
|
|
||
| case "${mode}" in | ||
| prepare-state) | ||
| prepare_state \ | ||
| "aws_lambda_event_source_mapping.delta_trigger" \ | ||
| "${delta_event_source_arn}" \ | ||
| "${counterpart_delta_function}" \ | ||
| "${target_delta_function}" | ||
| prepare_state \ | ||
| "aws_lambda_event_source_mapping.id_sync_sqs_trigger" \ | ||
| "${id_sync_queue_arn}" \ | ||
| "${counterpart_id_sync_function}" \ | ||
| "${target_id_sync_function}" | ||
| ;; | ||
| cleanup-stale) | ||
| cleanup_stale_mapping \ | ||
| "${delta_event_source_arn}" \ | ||
| "${counterpart_delta_function}" \ | ||
| "${target_delta_function}" | ||
| cleanup_stale_mapping \ | ||
| "${id_sync_queue_arn}" \ | ||
| "${counterpart_id_sync_function}" \ | ||
| "${target_id_sync_function}" | ||
| ;; | ||
| *) | ||
| echo "Unsupported mode: ${mode}. Use prepare-state or cleanup-stale." | ||
| exit 1 | ||
| ;; | ||
| esac | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.