Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CD Pipeline

on:
workflow_dispatch:
inputs:
docker_tag:
description: 'Docker tag from CI job'
required: true
type: string

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: DevOps
token: ${{ secrets.GH_PAT }}

- name: Verify Docker Tag
run: |
echo "DOCKER TAG RECEIVED: ${{ github.event.inputs.docker_tag }}"

- name: Update Kubernetes Manifest
run: |
cd kubernetes
sed -i -e 's|trainwithshubham/bankapp-eks:.*|trainwithshubham/bankapp-eks:${{ github.event.inputs.docker_tag }}|g' bankapp-deployment.yaml
cat bankapp-deployment.yaml

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Commit and Push Changes
run: |
echo "Checking repository status:"
git status

echo "Adding changes to git:"
git add .

echo "Committing changes:"
git commit -m "Updated K8s Deployment Docker Image Version"

echo "Pushing changes to github:"
git push origin DevOps

- name: Send Email Notification
uses: dawidd6/action-send-mail@v3
if: always()
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: "BankApp Application has been updated and deployed - ${{ job.status }}"
to: trainwithshubham@gmail.com
from: ${{ secrets.EMAIL_USERNAME }}
html_body: |
<html>
<body>
<div style="background-color: #FFA07A; padding: 10px; margin-bottom: 10px;">
<p style="color: black; font-weight: bold;">Project: ${{ github.repository }}</p>
</div>
<div style="background-color: #90EE90; padding: 10px; margin-bottom: 10px;">
<p style="color: black; font-weight: bold;">Build Number: ${{ github.run_number }}</p>
</div>
<div style="background-color: #87CEEB; padding: 10px; margin-bottom: 10px;">
<p style="color: black; font-weight: bold;">URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}</p>
</div>
</body>
</html>
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI Pipeline

on:
push:
branches:
- DevOps
workflow_dispatch:
inputs:
docker_tag:
description: 'Docker image tag'
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: DevOps

- name: Trivy Filesystem Scan
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'

- name: OWASP Dependency Check
uses: dependency-check/Dependency-Check_Action@main
with:
project: 'bankapp'
path: '.'
format: 'XML'

- name: SonarQube Analysis
uses: SonarSource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: >
-Dsonar.projectKey=bankapp
-Dsonar.projectName=bankapp

- name: SonarQube Quality Gate
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: madhupdevops/bankapp:${{ github.event.inputs.docker_tag || github.sha }}

- name: Upload OWASP Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: owasp-reports
path: '*.xml'

- name: Trigger CD Workflow
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PAT }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'cd.yml',
ref: 'DevOps',
inputs: {
docker_tag: '${{ github.event.inputs.docker_tag || github.sha }}'
}
})