Skip to content

Commit

Permalink
Update cd.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
flowramps authored Nov 11, 2024
1 parent 04676ea commit 5463043
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ name: CD
on:
push:
branches: [main]
workflow_dispatch: # Permite execução manual para rollback

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build Image and Push to Docker Hub
uses: docker/[email protected]
with:
username: rampss
password: ${{ secrets.DOCKER_PASSWORD }}
repository: rampss/argocd
tags: ${{ github.sha }}, latest
tags: ${{ github.sha }}, latest

deploy:
name: Deploy
Expand All @@ -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
Expand All @@ -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 "[email protected]"
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 }}

0 comments on commit 5463043

Please sign in to comment.