From 4d1276b1f9303070b2878c57e616da6be8ffdf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Caetano?= Date: Thu, 12 Jun 2025 00:25:36 +0000 Subject: [PATCH] Update README.md --- README.md | 91 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d8f363d..9212b44 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ name: CI & CD on: push: branches: - - master + - dev jobs: lint_commits: @@ -145,12 +145,11 @@ jobs: run: npm ci --no-audit - name: Lint Commit Messages - # Se qualquer mensagem não corresponder ao Conventional Commits, este step falha - run: npx commitlint --from=origin/master --to=HEAD + run: npx commitlint --from=origin/dev --to=HEAD release: name: Release - needs: lint_commits # só roda se lint_commits passar + needs: lint_commits runs-on: [self-hosted] outputs: sha_short: ${{ steps.commit_short.outputs.sha_short }} @@ -192,12 +191,12 @@ jobs: build_and_push: name: Docker | Build and Push needs: release - if: ${{ needs.release.outputs.is_tagged == 'true' }} # só roda se semantic-release criou tag + if: ${{ needs.release.outputs.is_tagged == 'true' }} runs-on: [self-hosted] env: DEJO_NODE_AWS_REGION: us-east-1 AWS_ECR_REPOSITORY: dev-dejo/dejo-node - DISABLE_DISCORD_NOTIFY: true + DISABLE_DISCORD_NOTIFY: false DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} sha_short: ${{ needs.release.outputs.sha_short }} steps: @@ -211,7 +210,7 @@ jobs: run: | TAG=${GITHUB_REF#refs/tags/} curl -X POST -H "Content-Type: application/json" \ - -d "{\"content\": \":arrow_forward: Deploy da versão **${TAG}** iniciado...\"}" \ + -d "{\"content\":\":arrow_forward: Deploy da versão **${TAG}** iniciado...\"}" \ "${DISCORD_WEBHOOK}" - name: Set up Docker Buildx @@ -235,10 +234,12 @@ jobs: password: ${{ secrets.DEJO_NODE_AWS_SECRET_KEY }} - name: Build and Push Backend + id: build_push + continue-on-error: true uses: docker/build-push-action@v5 with: - context: infrastructure - file: infrastructure/Dockerfile + context: . + file: ./Dockerfile push: true tags: | ${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}/${{ env.AWS_ECR_REPOSITORY }}:latest @@ -246,11 +247,29 @@ jobs: cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new + - name: Discord | Notify Error (Build) + if: steps.build_push.outcome == 'failure' && env.DISABLE_DISCORD_NOTIFY != 'true' + run: | + curl -X POST -H "Content-Type: application/json" \ + -d '{"content":":x: Falha no build/push do Docker. Veja logs."}' \ + "${DISCORD_WEBHOOK}" + + - name: Fail job if build_push failed + if: steps.build_push.outcome == 'failure' + run: exit 1 + - name: Moving Cache run: | rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache + - name: Discord | Notify Success (Build) + if: steps.build_push.outcome == 'success' && env.DISABLE_DISCORD_NOTIFY != 'true' + run: | + curl -X POST -H "Content-Type: application/json" \ + -d '{"content":":white_check_mark: Build e push do Docker concluídos com sucesso."}' \ + "${DISCORD_WEBHOOK}" + kustomize_apply: name: Kubernetes | Kustomize Apply needs: build_and_push @@ -258,6 +277,8 @@ jobs: env: DEJO_NODE_AWS_REGION: us-east-1 KUBE_NAMESPACE: dejo-node + DISABLE_DISCORD_NOTIFY: false + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -272,11 +293,31 @@ jobs: aws-region: ${{ env.DEJO_NODE_AWS_REGION }} - name: Apply Kustomize + id: kustomize + continue-on-error: true run: | echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig export KUBECONFIG=$PWD/kubeconfig kubectl apply -k infrastructure/kubernetes/dev -n "${KUBE_NAMESPACE}" + - name: Discord | Notify Error (Kustomize) + if: steps.kustomize.outcome == 'failure' && env.DISABLE_DISCORD_NOTIFY != 'true' + run: | + curl -X POST -H "Content-Type: application/json" \ + -d '{"content":":x: Falha ao aplicar Kustomize. Veja logs."}' \ + "${DISCORD_WEBHOOK}" + + - name: Fail job if kustomize failed + if: steps.kustomize.outcome == 'failure' + run: exit 1 + + - name: Discord | Notify Success (Kustomize) + if: steps.kustomize.outcome == 'success' && env.DISABLE_DISCORD_NOTIFY != 'true' + run: | + curl -X POST -H "Content-Type: application/json" \ + -d '{"content":":white_check_mark: Kustomize aplicado com sucesso."}' \ + "${DISCORD_WEBHOOK}" + deploy_backend: name: Kubernetes | Deploy App needs: kustomize_apply @@ -286,7 +327,7 @@ jobs: AWS_ECR_REPOSITORY: dev-dejo/dejo-node KUBE_NAMESPACE: dejo-node KUBE_DEPLOY_NAME: api-app - DISABLE_DISCORD_NOTIFY: true + DISABLE_DISCORD_NOTIFY: false DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} sha_short: ${{ needs.release.outputs.sha_short }} steps: @@ -303,6 +344,8 @@ jobs: aws-region: ${{ env.DEJO_NODE_AWS_REGION }} - name: Deploy API + id: deploy_api + continue-on-error: true run: | echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig export KUBECONFIG=$PWD/kubeconfig @@ -310,27 +353,23 @@ jobs: ${{ env.KUBE_DEPLOY_NAME }}="${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}/${{ env.AWS_ECR_REPOSITORY }}:${{ env.sha_short }}" \ --record -n "${KUBE_NAMESPACE}" - - name: Verify Rollout - run: | - echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig - export KUBECONFIG=$PWD/kubeconfig - kubectl rollout status deployment/${{ env.KUBE_DEPLOY_NAME }} -n "${KUBE_NAMESPACE}" - - - name: Discord | Notify Error - if: ${{ failure() && env.DISABLE_DISCORD_NOTIFY != 'true' }} + - name: Discord | Notify Error (Deploy) + if: steps.deploy_api.outcome == 'failure' && env.DISABLE_DISCORD_NOTIFY != 'true' run: | curl -X POST -H "Content-Type: application/json" \ - -d '{"content": ":x: Erro durante o deploy! Veja logs."}' \ - "${{ env.DISCORD_WEBHOOK }}" - exit 1 + -d '{"content":":x: Erro durante o deploy! Veja logs."}' \ + "${DISCORD_WEBHOOK}" - - name: Discord | Notify Success - if: ${{ success() && env.DISABLE_DISCORD_NOTIFY != 'true' }} + - name: Fail job if deploy_api failed + if: steps.deploy_api.outcome == 'failure' + run: exit 1 + + - name: Discord | Notify Success (Deploy) + if: steps.deploy_api.outcome == 'success' && env.DISABLE_DISCORD_NOTIFY != 'true' run: | curl -X POST -H "Content-Type: application/json" \ - -d '{"content": ":white_check_mark: Deploy concluído com sucesso! :rocket:"}' \ - "${{ env.DISCORD_WEBHOOK }}" - + -d '{"content":":white_check_mark: Deploy concluído com sucesso! :rocket:"}' \ + "${DISCORD_WEBHOOK}" ``` ---