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 35e84c5 commit 53a1409
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@ name: CD
on:
push:
branches: [main]

env:
REPO: rampss/argocd
CURRENT_TAG: ${{ github.sha }}
workflow_dispatch:
inputs:
rollback_tag:
description: "Tag ou SHA da imagem para rollback"
required: true

jobs:
build:
name: Build
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Image and Push to Docker Hub
uses: docker/build-push-action@v2
uses: docker/build-push-action@v1.1.0
with:
push: true
tags: ${{ env.REPO }}:${{ env.CURRENT_TAG }}, ${{ env.REPO }}:latest

- name: Save Previous Image Tag
run: echo "PREVIOUS_TAG=$(docker images --format '{{.Tag}}' | head -n 2 | tail -n 1)" >> $GITHUB_ENV
username: rampss
password: ${{ secrets.DOCKER_PASSWORD }}
repository: rampss/argocd
tags: ${{ github.sha }}, latest

deploy:
name: Deploy
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -46,14 +42,14 @@ jobs:
- name: Update K8s Image in Base
run: |
cd quickstart/base
kustomize edit set image goapp=${{ env.REPO }}:${{ env.CURRENT_TAG }}
kustomize edit set image goapp=rampss/argocd:${{ github.sha }}
cat kustomization.yaml
- name: Commit Changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "Deploy Action"
git commit -am "Update image tag to ${{ env.CURRENT_TAG }}" || echo "No changes to commit"
git commit -am "Update image tag to ${{ github.sha }}" || echo "No changes to commit"
- name: Push Changes
uses: ad-m/github-push-action@master
Expand All @@ -62,8 +58,8 @@ jobs:

rollback:
name: Rollback
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
if: needs.build.result == 'failure'
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -73,17 +69,17 @@ jobs:
with:
kustomize-version: v3.6.1

- name: Rollback Image in K8s
- name: Rollback to Previous Tag
run: |
cd quickstart/base
kustomize edit set image goapp=${{ env.REPO }}:${{ env.PREVIOUS_TAG }}
kustomize edit set image goapp=rampss/argocd:${{ github.event.inputs.rollback_tag }}
cat kustomization.yaml
- name: Commit Rollback Changes
- name: Commit Rollback
run: |
git config --local user.email "[email protected]"
git config --local user.name "Rollback Action"
git commit -am "Rollback to previous image tag ${{ env.PREVIOUS_TAG }}" || echo "No changes to commit"
git commit -am "Rollback to image tag ${{ github.event.inputs.rollback_tag }}" || echo "No changes to commit"
- name: Push Rollback Changes
uses: ad-m/github-push-action@master
Expand Down

0 comments on commit 53a1409

Please sign in to comment.