Skip to content

Commit

Permalink
Merge pull request #486 from IntersectMBO/chore/444-simplifying-toggl…
Browse files Browse the repository at this point in the history
…e-maintenance-workflow-configuration

[#444] Simplifying Toggle Maintenance workflow configuration
  • Loading branch information
placek authored Mar 18, 2024
2 parents 97ad6c0 + 89f6298 commit b647323
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
52 changes: 21 additions & 31 deletions .github/workflows/toggle-maintenance.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: Toggle (enable/disable) maintenance page
run-name: Maintenance mode set to ${{ inputs.maintenance }} on ${{ inputs.environment }}/${{ inputs.cardano_network }} by @${{ github.actor }}
name: Toggle maintenance page
run-name: Maintenance mode set to ${{ inputs.maintenance }} on ${{ inputs.environment }} by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
cardano_network:
required: true
type: choice
default: "sanchonet"
options:
- "sanchonet"
environment:
required: true
type: choice
Expand All @@ -22,57 +16,53 @@ on:
maintenance:
required: true
type: choice
default: "enable"
default: "enabled"
options:
- "enable"
- "disable"
- "enabled"
- "disabled"

env:
ENVIRONMENT: ${{ inputs.environment || 'dev' }}
CARDANO_NETWORK: ${{ inputs.cardano_network || 'sanchonet' }}
CARDANO_NETWORK: "sanchonet"

jobs:
check_environment_exists:
name: Check if target environment exists before proceeding
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts/govtool
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check environment exists
run: |
make check-env-defined cardano_network=$CARDANO_NETWORK env=$ENVIRONMENT
toggle_maintenance:
name: Toggl maintenance state
needs:
- check_environment_exists
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts/govtool
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.GHA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.GHA_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1

- name: Login to AWS ECR
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: eu-west-1

- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.GHA_SSH_PRIVATE_KEY }}

- name: Set domain
run: |
if [[ "${{ inputs.environment }}" == "staging" ]]; then
echo "DOMAIN=staging.govtool.byron.network" >> $GITHUB_ENV
elif [[ "${{ inputs.environment }}" == "beta" ]]; then
echo "DOMAIN=sanchogov.tools" >> $GITHUB_ENV
else
echo "DOMAIN=${DOMAIN:-$ENVIRONMENT-$CARDANO_NETWORK.govtool.byron.network}" >> $GITHUB_ENV
fi
- name: Toggle maintenance
run: |
make docker-login
if [[ "${{ inputs.environment }}" == "staging" ]]; then export DOMAIN=staging.govtool.byron.network; fi;
if [[ "${{ inputs.environment }}" == "beta" ]]; then export DOMAIN=sanchogov.tools; fi;
make toggle-maintenance cardano_network=$CARDANO_NETWORK env=$ENVIRONMENT maintenance=${{ inputs.maintenance || 'disable' }}
make toggle-maintenance maintenance=${{ inputs.maintenance || 'disabled' }}
4 changes: 2 additions & 2 deletions scripts/govtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ destroy-cardano-node-and-dbsync: prepare-config
$(docker) volume rm $${volumes}

.PHONY: toggle-maintenance
toggle-maintenance: prepare-config
toggle-maintenance: docker-login prepare-config
@:$(call check_defined, cardano_network)
@:$(call check_defined, env)
@:$(call check_defined, maintenance)
Expand All @@ -59,5 +59,5 @@ toggle-maintenance: prepare-config
export CARDANO_NODE_TAG=$(cardano_node_image_tag); \
export CARDANO_DB_SYNC_TAG=$(cardano_db_sync_image_tag); \
$(ssh-keyscan) $(docker_host) 2>/dev/null >> ~/.ssh/known_hosts; \
if [[ "$(maintenance)" = "enable" ]]; then $(docker) compose -f $(docker_compose_file) -p $(compose_stack_name) exec frontend touch /var/run/maintenance_enabled; \
if [[ "$(maintenance)" = "enabled" ]]; then $(docker) compose -f $(docker_compose_file) -p $(compose_stack_name) exec frontend touch /var/run/maintenance_enabled; \
else $(docker) compose -f $(docker_compose_file) -p $(compose_stack_name) exec frontend rm /var/run/maintenance_enabled; fi

0 comments on commit b647323

Please sign in to comment.