Restart Backend and Doc-Gen Deployments #111
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
| name: Restart Backend and Doc-Gen Deployments | |
| on: | |
| schedule: | |
| - cron: '30 8 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Choose target environment' | |
| required: true | |
| default: prod | |
| type: choice | |
| options: | |
| - dev | |
| - test | |
| - prod | |
| jobs: | |
| restart: | |
| runs-on: ubuntu-latest | |
| environment: ${{ inputs.environment || 'prod' }} | |
| env: | |
| OC_NAMESPACE: ${{ vars.oc_namespace }} | |
| OC_SERVER: ${{ vars.oc_server }} | |
| OC_TOKEN: ${{ secrets.oc_token }} | |
| TARGET_ENV: ${{ inputs.environment || 'prod' }} | |
| steps: | |
| - name: Login to OpenShift | |
| uses: bcgov/action-oc-runner@f900830adadd4d9eef3ca6ff80103e839ba8b7c0 # v1.3.0 | |
| with: | |
| oc_namespace: ${{ env.OC_NAMESPACE }} | |
| oc_server: ${{ env.OC_SERVER }} | |
| oc_token: ${{ env.OC_TOKEN }} | |
| commands: | | |
| oc project ${{ env.OC_NAMESPACE }} | |
| - name: Restart selected deployments | |
| id: restart | |
| env: | |
| DEPLOYMENTS: >- | |
| pay-transparency-${{ env.TARGET_ENV }}-backend | |
| pay-transparency-${{ env.TARGET_ENV }}-doc-gen-service | |
| run: | | |
| set -euo pipefail | |
| echo "Deployments to restart: $DEPLOYMENTS" | |
| echo "Namespace: $OC_NAMESPACE" | |
| restarted=() | |
| failed=() | |
| for dep in $DEPLOYMENTS; do | |
| echo "Restarting deployment/$dep ..." | |
| if oc rollout restart deployment/"$dep" -n "$OC_NAMESPACE" --request-timeout=300s && \ | |
| oc rollout status deployment/"$dep" -n "$OC_NAMESPACE" --request-timeout=300s; then | |
| echo "Deployment $dep restarted successfully." | |
| restarted+=("$dep") | |
| else | |
| echo "Failed to restart deployment $dep." | |
| failed+=("$dep") | |
| continue | |
| fi | |
| done | |
| { | |
| echo "## Restart Summary" | |
| echo "| Deployment | Status |" | |
| echo "|------------|--------|" | |
| for d in "${restarted[@]}"; do | |
| echo "| $d | Restarted |" | |
| done | |
| } >> "$GITHUB_STEP_SUMMARY" |