-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1253 from GSA/maintenance-action
add github action for maintenance mode
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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 }} |
This file contains 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,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 |