From 57d1cf5453cb49eb0d97b58a76148bf50fb365c6 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Mon, 23 Oct 2023 20:06:12 -0300 Subject: [PATCH] Implements Workflow Dispatcher for Deployment Refresh --- .github/workflows/refresh-deployment.yml | 48 ++++++++++++++++++++++++ deploy.sh | 7 ++-- refresh.sh | 16 +++++--- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/refresh-deployment.yml diff --git a/.github/workflows/refresh-deployment.yml b/.github/workflows/refresh-deployment.yml new file mode 100644 index 0000000..02f9511 --- /dev/null +++ b/.github/workflows/refresh-deployment.yml @@ -0,0 +1,48 @@ +name: workflow_02 + +on: + workflow_run: + workflows: ["build"] + branches: [main] + types: + - completed + repository_dispatch: + types: [refresh-deployments] + +jobs: + refresh-deployments: + name: Refresh deployments + environment: prod + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Executing Remote Commands - Refresh All Deployments + env: + deployments: ${{ github.event.client_payload.deployments }} + if: ${{ env.deployments == '' }} + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_KEY }} + script: | + [[ -d infra-hideyoshi.com ]] && \ + ./infra-hideyoshi.com/refresh.sh + + - name: Executing Remote Commands - Refresh Specific Deployments + env: + deployments: ${{ github.event.client_payload.deployments }} + if: ${{ env.deployments != '' }} + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_KEY }} + script: | + [[ -d infra-hideyoshi.com ]] && \ + ./infra-hideyoshi.com/refresh.sh ${{ env.deployments }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 152b02f..6c0c271 100755 --- a/deploy.sh +++ b/deploy.sh @@ -109,10 +109,11 @@ function main() { kubectl apply -f \ ./deployment/cert-manager/cert-manager-certificate.yaml - fi + if [[ $1 == "--staging" || $1 == "-s" ]]; then + bash ./refresh.sh + fi - # Refreshes all pods in case of a new image - bash ./refresh.sh + fi exit 0 diff --git a/refresh.sh b/refresh.sh index 3d2a6ed..9f3e17d 100755 --- a/refresh.sh +++ b/refresh.sh @@ -4,12 +4,16 @@ NAMESPACES=( portfolio ) -DEPLOYMENTS=( - "frontend-deployment" - "backend-deployment" - "storage-deployment" - "storage-processor-deployment" -) +if [ $# -eq 0 ]; then + DEPLOYMENTS=( + "frontend-deployment" + "backend-deployment" + "storage-deployment" + "storage-processor-deployment" + ) +else + DEPLOYMENTS=("$@") +fi for i in "${NAMESPACES[@]}"; do for x in "${DEPLOYMENTS[@]}"; do