Skip to content

Commit 6e2dfab

Browse files
feat: add GitHub Actions CI/CD workflows replacing Jenkins pipelines
Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
1 parent 305826d commit 6e2dfab

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CD Pipeline
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
DOCKER_TAG:
7+
description: "Docker tag of the image built by the CI job"
8+
required: true
9+
type: string
10+
repository_dispatch:
11+
types: [trigger-cd]
12+
13+
jobs:
14+
cd:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
ref: DevOps
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Verify Docker Image Tag
25+
run: echo "DOCKER TAG RECEIVED: ${{ inputs.DOCKER_TAG || github.event.client_payload.DOCKER_TAG }}"
26+
27+
- name: Update Kubernetes manifest
28+
run: |
29+
sed -i -e 's|trainwithshubham/bankapp-eks:.*|trainwithshubham/bankapp-eks:${{ inputs.DOCKER_TAG || github.event.client_payload.DOCKER_TAG }}|g' kubernetes/bankapp-deployment.yml
30+
31+
- name: Git commit and push
32+
run: |
33+
git config user.name "github-actions[bot]"
34+
git config user.email "github-actions[bot]@users.noreply.github.com"
35+
git add .
36+
git commit -m "Updated K8s Deployment Docker Image Version"
37+
git push origin DevOps
38+
39+
- name: Send email notification
40+
if: always()
41+
uses: dawidd6/action-send-mail@v3
42+
with:
43+
server_address: smtp.gmail.com
44+
server_port: 587
45+
username: ${{ secrets.MAIL_USERNAME }}
46+
password: ${{ secrets.MAIL_PASSWORD }}
47+
subject: "BankApp Application has been updated and deployed - ${{ job.status }}"
48+
to: trainwithshubham@gmail.com
49+
from: trainwithshubham@gmail.com
50+
html_body: |
51+
<html>
52+
<body>
53+
<div style="background-color: #FFA07A; padding: 10px; margin-bottom: 10px;">
54+
<p style="color: black; font-weight: bold;">Project: ${{ github.job }}</p>
55+
</div>
56+
<div style="background-color: #90EE90; padding: 10px; margin-bottom: 10px;">
57+
<p style="color: black; font-weight: bold;">Build Number: ${{ github.run_number }}</p>
58+
</div>
59+
<div style="background-color: #87CEEB; padding: 10px; margin-bottom: 10px;">
60+
<p style="color: black; font-weight: bold;">URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}</p>
61+
</div>
62+
</body>
63+
</html>

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI Pipeline
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
DOCKER_TAG:
7+
description: "Setting docker image for latest push"
8+
required: true
9+
type: string
10+
push:
11+
branches:
12+
- DevOps
13+
14+
jobs:
15+
ci:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
ref: DevOps
23+
24+
- name: Trivy filesystem scan
25+
uses: aquasecurity/trivy-action@master
26+
with:
27+
scan-type: "fs"
28+
scan-ref: "."
29+
30+
- name: OWASP Dependency Check
31+
uses: dependency-check/Dependency-Check_Action@main
32+
with:
33+
project: "bankapp"
34+
path: "."
35+
format: "XML"
36+
out: "reports"
37+
38+
- name: Upload OWASP Dependency Check report
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: dependency-check-report
42+
path: reports/
43+
44+
- name: SonarQube Analysis
45+
uses: SonarSource/sonarqube-scan-action@master
46+
with:
47+
args: >
48+
-Dsonar.projectKey=bankapp
49+
-Dsonar.projectName=bankapp
50+
env:
51+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
52+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
53+
54+
- name: SonarQube Quality Gate
55+
uses: SonarSource/sonarqube-quality-gate-action@master
56+
env:
57+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
58+
59+
- name: Docker Login
60+
uses: docker/login-action@v3
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
65+
- name: Docker Build & Push
66+
uses: docker/build-push-action@v5
67+
with:
68+
push: true
69+
tags: madhupdevops/bankapp:${{ inputs.DOCKER_TAG }}
70+
71+
- name: Trigger CD workflow
72+
run: |
73+
gh workflow run cd.yml \
74+
-r DevOps \
75+
-f DOCKER_TAG="${{ inputs.DOCKER_TAG }}"
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)