Skip to content
Merged
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
50 changes: 0 additions & 50 deletions .github/workflows/build.yml

This file was deleted.

204 changes: 204 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
name: CodeCampus CI/CD Pipeline

on:
push:
branches: [ main, sahil-dev ]
pull_request:
branches: [ main, sahil-dev ]
workflow_dispatch: # Allow manual trigger

env:
NODE_VERSION: '18.x'

jobs:
# Job 1: Test & Quality Check (Backend)
test-backend:
name: 🧪 Test & Quality Check (backend)
runs-on: ubuntu-latest

steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

- name: 🟢 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json

- name: 📦 Install dependencies
working-directory: backend
run: npm ci

- name: 🔧 TypeScript compilation check
working-directory: backend
run: npx tsc --noEmit

- name: 🧪 Run tests
working-directory: backend
run: npm test -- --coverage --watchAll=false
env:
CI: true

- name: 🔒 Security audit
working-directory: backend
run: npm audit --audit-level high
continue-on-error: true

# Job 2: Test & Quality Check (Frontend)
test-frontend:
name: 🧪 Test & Quality Check (frontend)
runs-on: ubuntu-latest

steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

- name: 🟢 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: 📦 Install dependencies
working-directory: frontend
run: npm ci

- name: 🔍 Run ESLint
working-directory: frontend
run: npm run lint
continue-on-error: true

- name: 🔧 TypeScript compilation check
working-directory: frontend
run: npx tsc --noEmit

- name: 🧪 Run tests
working-directory: frontend
run: npm test -- --coverage --watchAll=false
env:
CI: true

- name: 🔒 Security audit
working-directory: frontend
run: npm audit --audit-level high
continue-on-error: true

# Job 3: Build Applications (Backend)
build-backend:
name: 🏗️ Build Applications (backend)
runs-on: ubuntu-latest
needs: test-backend

steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

- name: 🟢 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json

- name: 📦 Install dependencies
working-directory: backend
run: npm ci

- name: 🏗️ Build backend
working-directory: backend
run: npm run build
env:
NODE_ENV: production

- name: 📄 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-backend
path: backend/dist/
retention-days: 30

# Job 4: Build Applications (Frontend)
build-frontend:
name: 🏗️ Build Applications (frontend)
runs-on: ubuntu-latest
needs: test-frontend

steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

- name: 🟢 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: 📦 Install dependencies
working-directory: frontend
run: npm ci

- name: 🏗️ Build frontend
working-directory: frontend
run: npm run build
env:
NODE_ENV: production
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL || 'http://localhost:5000' }}

- name: 📄 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-frontend
path: frontend/.next/
retention-days: 30

# Job 5: Build & Push Docker Images
docker:
name: 🐳 Build & Push Docker Images
runs-on: ubuntu-latest
needs: [build-backend, build-frontend]
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/sahil-dev') && github.event_name == 'push'

strategy:
matrix:
component: [backend, frontend]

steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

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

- name: 🔑 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: 🏷️ Generate tags and labels
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/codecampus-${{ matrix.component }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}

- name: 🏗️ Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.component }}
file: ./${{ matrix.component }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64

12 changes: 12 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
npm-debug.log
__tests__
coverage
*.md
.git
.gitignore
.env
.env.*
Dockerfile
.dockerignore
.nyc_output
14 changes: 14 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18-alpine

WORKDIR /app

# Copy package files and install dependencies (including dev dependencies for nodemon/ts-node)
COPY package*.json ./
RUN npm install

# Copy source code
COPY . .

# Expose port and start in development mode
EXPOSE 5000
CMD ["npm", "run", "dev"]
Loading
Loading