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

on:
push:
branches: [main, test, develop]
pull_request:
branches: [main]

env:
NODE_VERSION: '20'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
# ============ LINT & TYPE CHECK ============
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install API dependencies
working-directory: services/api
run: npm ci

- name: Install Dashboard dependencies
working-directory: cdn-dashboard
run: npm ci

- name: Lint API
working-directory: services/api
run: npm run lint --if-present

- name: Lint Dashboard
working-directory: cdn-dashboard
run: npm run lint --if-present

- name: Type check Dashboard
working-directory: cdn-dashboard
run: npx tsc --noEmit

# ============ API TESTS ============
test-api:
name: API Tests
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: cdn_test_db
POSTGRES_USER: cdn_test_user
POSTGRES_PASSWORD: cdn_test_password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

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

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

- name: Install dependencies
working-directory: services/api
run: npm ci

- name: Run tests
working-directory: services/api
run: npm test
env:
NODE_ENV: test
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: cdn_test_db
POSTGRES_USER: cdn_test_user
POSTGRES_PASSWORD: cdn_test_password
JWT_SECRET: test-jwt-secret
API_KEY: test-api-key

- name: Upload coverage
uses: codecov/codecov-action@v4

Copilot AI Dec 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using @v4 without specifying a full SHA or tag makes the workflow vulnerable to supply chain attacks. Pin to a specific commit SHA or use a full version tag.

Suggested change
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4.4.1

Copilot uses AI. Check for mistakes.
if: always()
with:
files: services/api/coverage/lcov.info
flags: api
token: ${{ secrets.CODECOV_TOKEN }}

# ============ DASHBOARD TESTS ============
test-dashboard:
name: Dashboard Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install dependencies
working-directory: cdn-dashboard
run: npm ci

- name: Run tests
working-directory: cdn-dashboard
run: npm test --if-present
env:
CI: true

- name: Build Dashboard
working-directory: cdn-dashboard
run: npm run build
env:
NEXT_PUBLIC_API_URL: /api

# ============ BUILD DOCKER IMAGES ============
build:
name: Build Docker Images
runs-on: ubuntu-latest
needs: [test-api, test-dashboard]
if: github.event_name == 'push'
permissions:
contents: read
packages: write

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

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for API
id: meta-api
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/api
tags: |
type=ref,event=branch
type=sha,prefix=
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}

- name: Build and push API image
uses: docker/build-push-action@v5
with:
context: ./services/api
push: true
tags: ${{ steps.meta-api.outputs.tags }}
labels: ${{ steps.meta-api.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Extract metadata for Dashboard
id: meta-dashboard
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/dashboard
tags: |
type=ref,event=branch
type=sha,prefix=
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}

- name: Build and push Dashboard image
uses: docker/build-push-action@v5
with:
context: ./cdn-dashboard
push: true
tags: ${{ steps.meta-dashboard.outputs.tags }}
labels: ${{ steps.meta-dashboard.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NEXT_PUBLIC_API_URL=/api

- name: Extract metadata for Nginx
id: meta-nginx
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/nginx
tags: |
type=ref,event=branch
type=sha,prefix=
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}

- name: Build and push Nginx image
uses: docker/build-push-action@v5
with:
context: ./services/nginx
push: true
tags: ${{ steps.meta-nginx.outputs.tags }}
labels: ${{ steps.meta-nginx.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# ============ SECURITY SCAN ============
security:
name: Security Scan
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
severity: 'CRITICAL,HIGH'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v2

Copilot AI Dec 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using @v2 without specifying a full SHA or tag makes the workflow vulnerable to supply chain attacks. Pin to a specific commit SHA or use a full version tag.

Suggested change
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v2.22.7

Copilot uses AI. Check for mistakes.
if: always()
with:
sarif_file: 'trivy-results.sarif'

# ============ DEPLOY TO STAGING ============
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: [build, security]
if: github.ref == 'refs/heads/test'
environment: staging
steps:
- name: Deploy to staging
run: |
echo "🚀 Deploying to staging environment..."
echo "Branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
# Add your deployment commands here
# Example: SSH to server and pull new images

# ============ DEPLOY TO PRODUCTION ============
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, security]
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Deploy to production
run: |
echo "🚀 Deploying to production environment..."
echo "Branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
# Add your deployment commands here
Loading
Loading