Skip to content

Commit

Permalink
refactor(ci/cd) Update main.yml with trivy and k8s stages
Browse files Browse the repository at this point in the history
  • Loading branch information
Uj5Ghare authored Dec 8, 2024
1 parent be962dc commit 8bae55a
Showing 1 changed file with 131 additions and 26 deletions.
157 changes: 131 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,134 @@ jobs:
# - name: Create production build folder
# run: npm run build --if-present

Docker:
runs-on: ubuntu-24.04
defaults:
run:
shell: bash
working-directory: ./frontend
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
refs: ${{ github.refs_name }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: fronted/
push: true
tags: ${{ vars.DOCKER_USER }}/eng-frontend:${{ github.run_number }}
Image-Vuln-Check-Frontend:
runs-on: ubuntu-24.04
continue-on-error: true
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
run: docker build -t docker.io/${{ vars.DOCKER_USER }}/eng-frontend:${{ github.sha }} .
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/[email protected]
with:
image-ref: "docker.io/${{ vars.DOCKER_USER }}/eng-frontend:${{ github.sha }}"
format: "table"
exit-code: "1"
ignore-unfixed: true
output: trivy-report-frontend.txt
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: trivy-report-frontend
path: trivy-report-frontend.txt

Image-Vuln-Check-Backend:
runs-on: ubuntu-24.04
continue-on-error: true
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
run: docker build -t docker.io/${{ vars.DOCKER_USER }}/eng-backend:${{ github.sha }} .
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/[email protected]
with:
image-ref: "docker.io/${{ vars.DOCKER_USER }}/eng-backend:${{ github.sha }}"
format: "table"
exit-code: "1"
ignore-unfixed: true
output: trivy-report-backend.txt
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: trivy-report-backend
path: trivy-report-backend.txt

Push-To-DockerHub-Frontend:
runs-on: ubuntu-24.04
needs: [Image-Vuln-Check-Frontend]
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKER_USER }}/eng-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKER_USER }}/eng-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}

Push-To-DockerHub-Backend:
runs-on: ubuntu-24.04
needs: [Image-Vuln-Check-Backend]
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKER_USER }}/eng-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKER_USER }}/eng-backend:1.${{ github.run_number }}.${{ github.run_attempt}}

Deploy-On-Minikube:
runs-on: ubuntu-24.04
needs: [Push-To-DockerHub-Frontend, Push-To-DockerHub-Backend]
defaults:
run:
shell: bash
working-directory: k8s/manifests/
steps:
- uses: actions/checkout@v4
with:
refs: ${{ github.refs_name }}
- name: Start minikube
uses: medyagh/setup-minikube@latest
- name: Try the cluster!
run: kubectl get pods -A
- name: Deploy to minikube
run:
kubectl apply -f frontend/namespace.yml
kubectl apply -f frontend/.
- name: Watch the changes
run: |
sleep 20
kubectl get all -n app

0 comments on commit 8bae55a

Please sign in to comment.