From 546304396e29221ea9e3578530772aeca0c2fbfa Mon Sep 17 00:00:00 2001 From: Rafael Rampasso <143979531+flowramps@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:18:59 -0300 Subject: [PATCH] Update cd.yaml --- .github/workflows/cd.yaml | 55 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 1e9dc8f..3b8c84d 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -2,6 +2,8 @@ name: CD on: push: branches: [main] + workflow_dispatch: # Permite execução manual para rollback + jobs: build: name: Build @@ -9,14 +11,14 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - + - name: Build Image and Push to Docker Hub uses: docker/build-push-action@v1.1.0 with: username: rampss password: ${{ secrets.DOCKER_PASSWORD }} repository: rampss/argocd - tags: ${{ github.sha }}, latest + tags: ${{ github.sha }}, latest deploy: name: Deploy @@ -25,12 +27,22 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - + - name: Setup Kustomize uses: imranismail/setup-kustomize@v1 with: kustomize-version: v3.6.1 + - name: Read Previous Version + id: read_version + run: | + if test -f VERSION_HISTORY; then + export PREVIOUS_VERSION=$(cat VERSION_HISTORY) + else + export PREVIOUS_VERSION="latest" + fi + echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_ENV + - name: Update K8s Image in Base run: | cd quickstart/base @@ -47,3 +59,40 @@ jobs: uses: ad-m/github-push-action@master with: github_token: ${{ secrets.PERSONAL_TOKEN }} + + - name: Update Version History + run: | + echo "${{ github.sha }}" > VERSION_HISTORY + git add VERSION_HISTORY + git commit -m "Update version history" + git push + + rollback: + name: Rollback + runs-on: ubuntu-latest + if: github.event.inputs.rollback == 'true' # Executa apenas se chamado para rollback manualmente + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Kustomize + uses: imranismail/setup-kustomize@v1 + with: + kustomize-version: v3.6.1 + + - name: Rollback to Previous Version + run: | + cd quickstart/base + kustomize edit set image goapp=rampss/argocd:${{ env.previous_version }} + cat kustomization.yaml + + - name: Commit Rollback Changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "Deploy Action" + git commit -am "Rollback to previous version ${{ env.previous_version }}" || echo "No changes to commit" + + - name: Push Rollback Changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.PERSONAL_TOKEN }}