Skip to content

Commit

Permalink
add script to flip the prod bluegreen defelctor service
Browse files Browse the repository at this point in the history
  • Loading branch information
sjahl committed Nov 1, 2024
1 parent d6166d1 commit 9d45090
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .cloudbuild/bluegreen-flip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -euo pipefail

# Ensure that our cloudbuild has everything we need
for cmd in git yq; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is not installed." >&2
exit 1
fi
done


mkdir -p /root/.ssh && chmod 0700 /root/.ssh
echo "$DEPLOY_KEY" > /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
git clone git@github.com:broadinstitute/gnomad-deployments.git

cd gnomad-deployments/browser-test/prod-deflector

CURRENT_DEPLOYMENT=$(yq '.spec.selector.deployment' < gnomad-bluegreen.service.yaml)

echo "Current deployment is: $CURRENT_DEPLOYMENT"

if [[ "$CURRENT_DEPLOYMENT" != "blue" && "$CURRENT_DEPLOYMENT" != "green" ]]; then
echo "Error: Current deployment is not either green or blue, unknown state. Exiting."
exit 1
fi

if [[ "$CURRENT_DEPLOYMENT" == "blue" ]]; then
TARGET_DEPLOYMENT="green"
else
TARGET_DEPLOYMENT="blue"
fi

yq -i ".spec.selector.deployment = \"${TARGET_DEPLOYMENT}\"" gnomad-bluegreen.service.yaml

git add gnomad-bluegreen.service.yaml
git -c user.name="TGG Automation" -c user.email="tgg-automation@broadinstitute.org" commit -m "Updating gnomad-browser active service to $TARGET_DEPLOYMENT"
git show

git push origin main
11 changes: 11 additions & 0 deletions .cloudbuild/flip-browser-bluegreen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- name: 'us-central1-docker.pkg.dev/${PROJECT_ID}/tgg-sre-images/tgg-deploykit:testing-4'
entrypoint: 'bash'
args: ['./bluegreen-flip.sh']
dir: '.cloudbuild'
secretEnv:
- 'DEPLOY_KEY'
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/GITHUB_DEPLOY_KEY/versions/latest
env: 'DEPLOY_KEY'

0 comments on commit 9d45090

Please sign in to comment.