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
51 changes: 51 additions & 0 deletions .github/workflows/cd-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CD - Main

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
# 1️⃣ Checkout code
- name: Checkout repository
uses: actions/checkout@v4

# 2️⃣ Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

# 3️⃣ Update kubeconfig for EKS
- name: Update kubeconfig
run: |
aws eks update-kubeconfig \
--region ${{ secrets.AWS_REGION }} \
--name ${{ secrets.EKS_CLUSTER_NAME }}

# 4️⃣ Deploy backend and frontend
- name: Deploy to EKS
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
SHORT_SHA=${GITHUB_SHA::7}

BACKEND_IMAGE=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pgagi-backend:$SHORT_SHA
FRONTEND_IMAGE=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pgagi-frontend:$SHORT_SHA

kubectl set image deployment/pgagi-backend \
backend=$BACKEND_IMAGE

kubectl set image deployment/pgagi-frontend \
frontend=$FRONTEND_IMAGE

kubectl rollout status deployment/pgagi-backend
kubectl rollout status deployment/pgagi-frontend

69 changes: 69 additions & 0 deletions .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: CI - Develop

on:
push:
branches:
- develop

jobs:
build-test-push:
runs-on: ubuntu-latest
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}

steps:
# Checkout
- uses: actions/checkout@v4

# Python
- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Backend tests
working-directory: backend
run: |
pip install -r requirements.txt
pytest

# Node
- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Frontend build
working-directory: frontend
run: |
npm ci
npm run build

# Configure AWS credentials FIRST
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}


# Docker login to ECR
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2

# Build & push images
- name: Build and push Docker images
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
SHORT_SHA=${GITHUB_SHA::7}

BACKEND_IMAGE=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pgagi-backend:$SHORT_SHA
FRONTEND_IMAGE=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pgagi-frontend:$SHORT_SHA

docker build -t $BACKEND_IMAGE backend
docker build -t $FRONTEND_IMAGE frontend

docker push $BACKEND_IMAGE
docker push $FRONTEND_IMAGE
19 changes: 19 additions & 0 deletions K8s/back-dep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgagi-backend
spec:
replicas: 1
selector:
matchLabels:
app: pgagi-backend
template:
metadata:
labels:
app: pgagi-backend
spec:
containers:
- name: backend
image: kavithakumari062001/pgagi-backend:latest
ports:
- containerPort: 5000
11 changes: 11 additions & 0 deletions K8s/back-ser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: pgagi-backend-service
spec:
selector:
app: pgagi-backend
ports:
- port: 5000
targetPort: 5000
type: ClusterIP
22 changes: 22 additions & 0 deletions K8s/front-dep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgagi-frontend
spec:
replicas: 1
selector:
matchLabels:
app: pgagi-frontend
template:
metadata:
labels:
app: pgagi-frontend
spec:
containers:
- name: frontend
image: kavithakumari062001/pgagi-frontend:ingress
ports:
- containerPort: 3000
env:
- name: NEXT_PUBLIC_API_URL
value: "http://pgagi-backend-service:5000"
11 changes: 11 additions & 0 deletions K8s/front-ser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: pgagi-frontend-service
spec:
selector:
app: pgagi-frontend
ports:
- port: 3000
targetPort: 3000
type: NodePort
23 changes: 23 additions & 0 deletions K8s/pgagi-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pgagi-ingress
spec:
rules:
- host: pgagi.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: pgagi-frontend-service
port:
number: 3000
- path: /api
pathType: Prefix
backend:
service:
name: pgagi-backend-service
port:
number: 5000
Loading