Skip to content

Commit

Permalink
feat: speed up rollback process
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Feb 24, 2025
1 parent ba88e63 commit e620441
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions .github/workflows/rollback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ name: Rollback Production Deployment
on:
workflow_dispatch:

permissions:
id-token: write # allows the JWT to be requested from GitHub's OIDC provider
contents: read # This is required for actions/checkout

env:
NODE_OPTIONS: "--no-warnings"
CACHE_CONTROL_NO_STORE: "\"no-store\""
CACHE_CONTROL_MAX_AGE: "\"max-age=3600\""
LEGACY_DIR_NAME: "legacy"
MODERN_DIR_NAME: "modern"
INTEGRATIONS_DIR_NAME: "js-integrations"
PLUGINS_DIR_NAME: "plugins"
MAJOR_VERSION_DIR_NAME: "v3"
LEGACY_MAJOR_VERSION_DIR_NAME: "v1.1"

jobs:
validate-actor:
# Only allow to be deployed from tags and main branch
Expand All @@ -13,30 +28,8 @@ jobs:
secrets:
PAT: ${{ secrets.PAT }}

deploy:
needs: validate-actor
rollback:
name: Rollback production deployment
uses: ./.github/workflows/deploy.yml
with:
environment: 'production'
bugsnag_release_stage: 'production'
s3_dir_path: 'v3'
s3_dir_path_legacy: 'v1.1'
action_type: ' Rollback'
secrets:
AWS_ACCOUNT_ID: ${{ secrets.AWS_PROD_ACCOUNT_ID }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_PROD_S3_BUCKET_NAME }}
AWS_S3_SYNC_ROLE: ${{ secrets.AWS_PROD_S3_SYNC_ROLE }}
AWS_CF_DISTRIBUTION_ID: ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }}
BUGSNAG_API_KEY: ${{ secrets.RS_PROD_BUGSNAG_API_KEY }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_RELEASE_CHANNEL_ID: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}

# As we rollback to a previous version, we need to invalidate the CDN cache for the previous version's directory
# The above deploy action will invalidate the cache for the core SDK artifacts, so this step is needed for dependencies (plugins and integrations)
invalidate-cdn-cache:
needs: deploy
name: Invalidate CDN cache
runs-on: [self-hosted, Linux, X64]

steps:
Expand All @@ -61,14 +54,36 @@ jobs:
echo "CURRENT_VERSION_V1_VALUE=$current_version_v1" >> $GITHUB_ENV
echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV
- name: Invalidate CloudFront cache for all the SDK artifacts (versioned directory)
- name: Copy the core SDK artifacts from the previous version to the latest version directory
run: |
integrations_modern_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}"
integrations_legacy_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}"
plugins_modern_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.PLUGINS_DIR_NAME }}"
s3_path_prefix="s3://${{ secrets.AWS_PROD_S3_BUCKET_NAME }}"
# Copy from S3 bucket versioned directory to the same S3 bucket in the latest version directory
# Exclude the plugins and js-integrations directories
aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/ $s3_path_prefix/${{ env.MAJOR_VERSION_DIR_NAME }}/${{ env.LEGACY_DIR_NAME }}/ --recursive --exclude "$integrations_legacy_path_prefix/*" --exclude "$integrations_legacy_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }}"
aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/ $s3_path_prefix/${{ env.MAJOR_VERSION_DIR_NAME }}/${{ env.MODERN_DIR_NAME }}/ --recursive --exclude "$plugins_modern_path_prefix/*" --exclude "$plugins_modern_path_prefix/**" --exclude "$integrations_modern_path_prefix/*" --exclude "$integrations_modern_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }}"
- name: Invalidate CloudFront cache for the latest version directory
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_VALUE }}/*" --query "Invalidation.Id" --output text)
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.MAJOR_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text)
aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --id "$invalidation_id"
- name: Invalidate CloudFront cache for all the legacy SDK artifacts (versioned directory)
# Repeat the above steps for the legacy SDK artifacts
- name: Copy the legacy core SDK artifacts from the previous version to the latest version directory
run: |
s3_path_prefix="s3://${{ secrets.AWS_PROD_S3_BUCKET_NAME }}"
# Copy from S3 bucket versioned directory to the same S3 bucket in the latest version directory
aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_V1_VALUE }}/ $s3_path_prefix/${{ env.LEGACY_MAJOR_VERSION_DIR_NAME }}/ --recursive --cache-control ${{ env.CACHE_CONTROL_NO_STORE }}
- name: Invalidate CloudFront cache for the latest version directory (legacy SDK artifacts)
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_V1_VALUE }}/*" --query "Invalidation.Id" --output text)
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.LEGACY_MAJOR_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text)
aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --id "$invalidation_id"

0 comments on commit e620441

Please sign in to comment.