Skip to content

dataprovider-updates #4

dataprovider-updates

dataprovider-updates #4

Workflow file for this run

name: K8s Dashboard CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
# Frontend Tests
frontend-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Lint code
run: npm run lint
- name: Run unit tests
run: npm test -- --coverage --watchAll=false
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./frontend/coverage
flags: frontend
name: frontend-coverage
# Backend Tests
backend-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: k8s_dash_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov httpx
- name: Run backend tests
run: python -m pytest --cov=. --cov-report=xml
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/k8s_dash_test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./backend
flags: backend
name: backend-coverage
# E2E Tests
e2e-test:
runs-on: ubuntu-latest
needs: [frontend-test, backend-test]
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install frontend dependencies
working-directory: ./frontend
run: npm ci
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install backend dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Start backend server
working-directory: ./backend
run: |
uvicorn main:app --host 0.0.0.0 --port 8000 &
sleep 10
- name: Run Cypress E2E tests
working-directory: ./frontend
run: npm run cypress:run
env:
CYPRESS_baseUrl: http://localhost:3000
- name: Upload Cypress screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: frontend/cypress/screenshots
- name: Upload Cypress videos
uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: frontend/cypress/videos
# Load Testing
load-test:
runs-on: ubuntu-latest
needs: [e2e-test]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Artillery
run: npm install -g artillery
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install backend dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Start backend server
working-directory: ./backend
run: |
uvicorn main:app --host 0.0.0.0 --port 8000 &
sleep 10
- name: Run load tests
run: artillery run load-test.yml --output load-test-results.json
- name: Generate load test report
run: artillery report load-test-results.json
- name: Upload load test results
uses: actions/upload-artifact@v3
with:
name: load-test-results
path: load-test-results.json
# Security Testing
security-test:
runs-on: ubuntu-latest
needs: [e2e-test]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install OWASP ZAP
run: |
sudo apt-get update
sudo apt-get install -y wget
wget -q https://github.com/zaproxy/zaproxy/releases/download/v2.12.0/ZAP_2.12.0_Linux.tar.gz
tar -xzf ZAP_2.12.0_Linux.tar.gz
sudo mv ZAP_2.12.0 /opt/zaproxy
sudo ln -s /opt/zaproxy/zap.sh /usr/local/bin/zap.sh
- name: Install backend dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Start backend server
working-directory: ./backend
run: |
uvicorn main:app --host 0.0.0.0 --port 8000 &
sleep 10
- name: Run security baseline scan
run: |
zap.sh -cmd -quickurl http://localhost:8000 -quickprogress -quickout security-report.html
- name: Upload security report
uses: actions/upload-artifact@v3
with:
name: security-report
path: security-report.html
# Build and Deploy
build-and-deploy:
runs-on: ubuntu-latest
needs: [frontend-test, backend-test, e2e-test]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push frontend image
uses: docker/build-push-action@v4
with:
context: ./frontend
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/k8s-dash-frontend:latest
${{ secrets.DOCKERHUB_USERNAME }}/k8s-dash-frontend:${{ github.sha }}
- name: Build and push backend image
uses: docker/build-push-action@v4
with:
context: ./backend
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/k8s-dash-backend:latest
${{ secrets.DOCKERHUB_USERNAME }}/k8s-dash-backend:${{ github.sha }}
- name: Deploy to staging
if: github.ref == 'refs/heads/main'
run: |
echo "Deploying to staging environment..."
# Add your deployment scripts here
# kubectl apply -f k8s/staging/
- name: Deploy to production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
echo "Deploying to production environment..."
# Add your production deployment scripts here
# kubectl apply -f k8s/production/
# Performance monitoring
performance-monitoring:
runs-on: ubuntu-latest
needs: [build-and-deploy]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
http://localhost:3000
configPath: '.lighthouserc.js'
uploadArtifacts: true
temporaryPublicStorage: true