Skip to content
Closed
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
57 changes: 57 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI/CD Pipeline

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to ACR
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Build and push course-service
run: |
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/course-service:${{ github.sha }} -t ${{ secrets.ACR_LOGIN_SERVER }}/course-service:latest ./course-service
docker push ${{ secrets.ACR_LOGIN_SERVER }}/course-service:${{ github.sha }}
docker push ${{ secrets.ACR_LOGIN_SERVER }}/course-service:latest

- name: Build and push frontend
run: |
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} -t ${{ secrets.ACR_LOGIN_SERVER }}/frontend:latest ./frontend
docker push ${{ secrets.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }}
docker push ${{ secrets.ACR_LOGIN_SERVER }}/frontend:latest

deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up kubectl
uses: azure/setup-kubectl@v3

- name: Deploy to AKS
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config
kubectl apply -f kubernetes/
kubectl rollout restart deployment/course-service
kubectl rollout restart deployment/frontend

- name: Verify deployment
run: |
kubectl rollout status deployment/course-service --timeout=120s
kubectl rollout status deployment/frontend --timeout=120s
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ cython_debug/
.cursorignore
.cursorindexingignore

node_modules/
node_modules/
terraform/
1 change: 1 addition & 0 deletions course-service/app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# CI trigger test - Rithwik 225379656
import logging
import time
from contextlib import asynccontextmanager
Expand Down
34 changes: 33 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,38 @@ services:
networks:
- koalatech-network

prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- koalatech-network

grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3001:3000"
depends_on:
- prometheus
networks:
- koalatech-network

cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
container_name: cadvisor
ports:
- "8080:8080"
volumes:
- //var/run:/var/run:ro
- //sys:/sys:ro
- //var/lib/docker/:/var/lib/docker:ro
networks:
- koalatech-network

networks:
koalatech-network:
driver: bridge
Expand All @@ -241,4 +273,4 @@ volumes:
student-db-data:
lecturer-db-data:
course-db-data:
enrollment-db-data:
enrollment-db-data:
2 changes: 1 addition & 1 deletion frontend/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Login = () => {
variant="h4"
gutterBottom
>
KoalaTech University
KoalaTech University - V2 Deployed
</Typography>

<Typography
Expand Down
21 changes: 21 additions & 0 deletions kubernetes/configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-nginx-config
data:
default.conf: |
server {
listen 3000;
root /usr/share/nginx/html;
index index.html;

location / {
try_files $uri $uri/ /index.html;
}

location /api/courses {
proxy_pass http://course-service:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
91 changes: 91 additions & 0 deletions kubernetes/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: course-service
labels:
app: course-service
spec:
replicas: 1
selector:
matchLabels:
app: course-service
template:
metadata:
labels:
app: course-service
spec:
containers:
- name: course-service
image: sit722acrrithwik5566.azurecr.io/course-service:latest
ports:
- containerPort: 3000
env:
- name: POSTGRES_HOST
value: course-db
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: postgres
- name: POSTGRES_DB
value: course_db
- name: JWT_SECRET
value: mysecretkey
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: course-db
labels:
app: course-db
spec:
replicas: 1
selector:
matchLabels:
app: course-db
template:
metadata:
labels:
app: course-db
spec:
containers:
- name: course-db
image: postgres:15
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: postgres
- name: POSTGRES_DB
value: course_db
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
app: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: sit722acrrithwik5566.azurecr.io/frontend:latest
ports:
- containerPort: 3000
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
volumes:
- name: nginx-config
configMap:
name: frontend-nginx-config
35 changes: 35 additions & 0 deletions kubernetes/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: v1
kind: Service
metadata:
name: course-service
spec:
selector:
app: course-service
ports:
- port: 3000
targetPort: 3000
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: course-db
spec:
selector:
app: course-db
ports:
- port: 5432
targetPort: 5432
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
selector:
app: frontend
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
11 changes: 11 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']

- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8080']