Skip to content

Commit

Permalink
Merge pull request #1253 from GSA/maintenance-action
Browse files Browse the repository at this point in the history
 add github action for maintenance mode
  • Loading branch information
FuhuXia authored Feb 15, 2024
2 parents c90f7a0 + c86d206 commit 625ed38
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/maintenance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: 8 - Maintenance Mode

on:
workflow_dispatch:
inputs:
environ:
description: 'Environment:'
required: true
type: choice
options:
- development
- staging
- prod
app:
description: 'Catalog App:'
required: true
type: choice
options:
- catalog-web
- catalog-admin
- both
mode:
description: 'Operation Mode:'
required: true
type: choice
options:
- Normal
- Scheduled_Maintenance
- Unscheduled_Downtime
notification:
description: 'Notification to Slack?'
required: true
type: boolean
default: true

jobs:
set-maintenance-mode:
name: Set ${{inputs.environ}}:${{inputs.app}} to ${{inputs.mode}}
runs-on: ubuntu-latest
environment: ${{inputs.environ}}
steps:
- name: checkout datagov
uses: actions/checkout@v3
with:
path: './catalog'
- name: run task
uses: cloud-gov/cg-cli-tools@main
with:
command: catalog/tools/set_maintenance.sh ${{inputs.app}} ${{inputs.mode}}
cf_org: gsa-datagov
cf_space: ${{ inputs.environ }}
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}
- name: Send notification to Slack
if: ${{ inputs.notification }}
uses: slackapi/[email protected]
with:
payload: |
{
"text": "${{inputs.app}} catalog app in ${{inputs.environ}} space is now in ${{inputs.mode}} mode."
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
49 changes: 49 additions & 0 deletions tools/set_maintenance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# write usage
function usage {
echo "Usage: $0 catalog_app_name maintenance_mode"
exit 1
}

if [ $# -ne 2 ] ; then
usage
fi

# get mode value from maintenance_mode
case "$2" in
"Scheduled_Maintenance")
maintenance_mode="MAINTENANCE"
;;
"Unscheduled_Downtime")
maintenance_mode="DOWN"
;;
*)
maintenance_mode="NORMAL"
;;
esac

# set for catalog-web
if [ "$1" == "catalog-web" ] || [ "$1" == "both" ] ; then
# compare with existing env value, run cf set-env only if it's different or not set
current_mode=$(cf env catalog-proxy | grep CATALOG_WEB_MODE | awk '{print $2}')
if [ "$current_mode" != "$maintenance_mode" ] ; then
cf set-env catalog-proxy CATALOG_WEB_MODE $maintenance_mode
need_restart=true
fi
fi

# set for catalog-admin
if [ "$1" == "catalog-admin" ] || [ "$1" == "both" ] ; then
# compare with existing env value, run cf set-env only if it's different or not set
current_mode=$(cf env catalog-proxy | grep CATALOG_ADMIN_MODE | awk '{print $2}')
if [ "$current_mode" != "$maintenance_mode" ] ; then
cf set-env catalog-proxy CATALOG_ADMIN_MODE $maintenance_mode
need_restart=true
fi
fi

# restart catalog-proxy if needed
if [ "$need_restart" == "true" ] ; then
cf restart catalog-proxy --strategy rolling
fi

0 comments on commit 625ed38

Please sign in to comment.