-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 "[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 }} |