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
32 changes: 22 additions & 10 deletions .github/README-CICD.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
# CI/CD Quick Start

## Pull Production Images
## 🌐 **Live Application**
- **Frontend**: https://ocpp.sankalpnarula.com (Cloudflare Workers)
- **Backend**: Pull from GHCR for your orchestration

## 📦 **Pull Production Images**

```bash
# Backend
# Backend (for your orchestration)
docker pull ghcr.io/hackstrix/ocpp-chaos-simulator:latest

# Frontend
docker pull ghcr.io/hackstrix/ocpp-chaos-simulator-frontend:latest
# Frontend (deployed to Cloudflare Workers automatically)
# No manual deployment needed - handled by GitHub Actions
```

## Deploy with Docker Compose
## 🚀 **Deployment Architecture**

- **Frontend**: Auto-deployed to Cloudflare Workers on push to main
- **Backend**: Docker image pushed to GHCR, use with your orchestration

```bash
# Use production compose file
# Backend deployment with Docker Compose
docker-compose -f deployments/docker-compose.prod.yml up -d
```

## Pipeline Status
## 📊 **Pipeline Status**

- ✅ **Build & Test**: Runs on all pushes and PRs
- 🚀 **Deploy**: Runs on main branch merges
- 📦 **Registry**: Images pushed to GHCR automatically
- 🚀 **Deploy**:
- Frontend → Cloudflare Workers (automatic)
- Backend → GHCR (for your orchestration)

## 📚 **Documentation**

For detailed documentation, see [docs/ci-cd-pipeline.md](../docs/ci-cd-pipeline.md)
- [CI/CD Pipeline Details](../docs/ci-cd-pipeline.md)
- [Cloudflare Workers Migration](../docs/cloudflare-workers-migration.md)
- [Custom Domain Setup](../docs/custom-domain-setup.md)

3 changes: 2 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ jobs:
cache-dependency-path: './frontend/package-lock.json'

- name: Install dependencies
run: npm ci
run: |
npm ci

- name: Run linter
run: npm run lint
Expand Down
174 changes: 75 additions & 99 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
echo "✅ No frontend changes detected"
fi

build-and-push:
build-and-push-backend:
name: Build and Push Backend
runs-on: [self-hosted, home]
needs: check-changes
Expand Down Expand Up @@ -99,70 +99,53 @@ jobs:
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64

build-frontend-image:
name: Build Frontend Container
runs-on: [self-hosted, home]
deploy-frontend-cloudflare:
name: Deploy Frontend to Cloudflare Workers
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.frontend-changed == 'true'
permissions:
contents: read
packages: write


defaults:
run:
working-directory: ./frontend

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

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

- name: Log in to Container Registry
uses: docker/login-action@v3
- name: Set up Node.js
uses: actions/setup-node@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for frontend
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
node-version: '24'
cache: 'npm'
cache-dependency-path: './frontend/package-lock.json'

- name: Install dependencies
run: npm ci

- name: Install Wrangler
run: npm install -g wrangler

- name: Build for Cloudflare Workers
run: npm run build:cloudflare
env:
NEXT_PUBLIC_API_URL: ${{ secrets.BACKEND_API_URL }}

- name: Build and push Frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/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
- name: Deploy to Cloudflare Workers
run: wrangler deploy --env="production"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

deploy-via-portainer:
name: Deploy via Portainer
deploy-backend-portainer:
name: Deploy Backend via Portainer
runs-on: [self-hosted, home]
needs: [check-changes, build-and-push, build-frontend-image]
needs: [check-changes, build-and-push-backend]
if: always() && github.ref == 'refs/heads/main' &&
(needs.build-and-push.result == 'success' || needs.build-and-push.result == 'skipped') &&
(needs.build-frontend-image.result == 'success' || needs.build-frontend-image.result == 'skipped') &&
(needs.check-changes.outputs.backend-changed == 'true' || needs.check-changes.outputs.frontend-changed == 'true')
needs.check-changes.outputs.backend-changed == 'true' &&
(needs.build-and-push-backend.result == 'success' || needs.build-and-push-backend.result == 'skipped')

steps:
- name: Deployment Info
run: |
echo "📋 **Deployment Information**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Backend Changed**: ${{ needs.check-changes.outputs.backend-changed }}" >> $GITHUB_STEP_SUMMARY
echo "- **Frontend Changed**: ${{ needs.check-changes.outputs.frontend-changed }}" >> $GITHUB_STEP_SUMMARY
echo "- **Backend Build**: ${{ needs.build-and-push.result }}" >> $GITHUB_STEP_SUMMARY
echo "- **Frontend Build**: ${{ needs.build-frontend-image.result }}" >> $GITHUB_STEP_SUMMARY

- name: Verify Portainer Connection
run: |
echo "🔍 Verifying connection to Portainer..."
Expand All @@ -173,18 +156,11 @@ jobs:
exit 1
fi

- name: Trigger Portainer Stack Redeployment
- name: Trigger Portainer Stack Redeployment
env:
PORTAINER_WEBHOOK_URL: ${{ secrets.PORTAINER_WEBHOOK_URL }}
BACKEND_CHANGED: ${{ needs.check-changes.outputs.backend-changed }}
FRONTEND_CHANGED: ${{ needs.check-changes.outputs.frontend-changed }}
run: |
echo "🚀 Starting deployment process..."
echo "📋 Backend changed: $BACKEND_CHANGED"
echo "📋 Frontend changed: $FRONTEND_CHANGED"

# Trigger redeployment via webhook
echo "🔄 Triggering stack redeployment via webhook..."
echo "🚀 Starting backend deployment..."

RESPONSE=$(curl -s -w "%{http_code}" -X POST \
-H "Content-Type: application/json" \
Expand All @@ -196,52 +172,52 @@ jobs:

case $HTTP_CODE in
200|204)
echo "✅ Stack redeployment triggered successfully!"
[ -n "$RESPONSE_BODY" ] && echo "📝 Response: $RESPONSE_BODY"
echo "✅ Backend redeployment triggered successfully!"
;;
*)
echo "❌ Deployment webhook failed with HTTP $HTTP_CODE"
echo "❌ Backend deployment failed with HTTP $HTTP_CODE"
echo "📝 Response: $RESPONSE_BODY"
echo "🔗 Check Portainer for more details"
exit 1
;;
esac

echo "⏳ Deployment initiated via webhook - check Portainer for progress"
echo "🔗 Monitor at: https://portainer.sankalpnarula.com"

- name: Deployment Summary
if: always()
deployment-summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [check-changes, deploy-frontend-cloudflare, deploy-backend-portainer]
if: always() && github.ref == 'refs/heads/main'

steps:
- name: Create Summary
run: |
echo "🎯 **Portainer Deployment Summary**" >> $GITHUB_STEP_SUMMARY
echo "# 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ job.status }}" = "success" ]; then
echo "✅ **Status**: Deployment successful" >> $GITHUB_STEP_SUMMARY
echo "🔗 **Portainer**: [View Stack](https://portainer.sankalpnarula.com)" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
echo "📦 **Backend Image**: \`ghcr.io/${{ github.repository }}:latest\` (updated)" >> $GITHUB_STEP_SUMMARY
else
echo "📦 **Backend Image**: \`ghcr.io/${{ github.repository }}:latest\` (unchanged)" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
echo "📦 **Frontend Image**: \`ghcr.io/${{ github.repository }}-frontend:latest\` (updated)" >> $GITHUB_STEP_SUMMARY
else
echo "📦 **Frontend Image**: \`ghcr.io/${{ github.repository }}-frontend:latest\` (unchanged)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**What was deployed:**" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
echo "- ✅ Backend: Built and deployed new image" >> $GITHUB_STEP_SUMMARY
else
echo "- ⏭️ Backend: No changes, using existing image" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
echo "- ✅ Frontend: Built and deployed new image" >> $GITHUB_STEP_SUMMARY
else
echo "- ⏭️ Frontend: No changes, using existing image" >> $GITHUB_STEP_SUMMARY
fi

# Frontend status
if [ "${{ needs.deploy-frontend-cloudflare.result }}" = "success" ]; then
echo "## ✅ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **Deployed successfully**" >> $GITHUB_STEP_SUMMARY
echo "- Platform: Cloudflare Workers" >> $GITHUB_STEP_SUMMARY
echo "- Domain: https://ocpp.sankalpnarula.com" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
echo "## ❌ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **Deployment failed**" >> $GITHUB_STEP_SUMMARY
else
echo "## ⏭️ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **No changes, skipped**" >> $GITHUB_STEP_SUMMARY
fi

echo "" >> $GITHUB_STEP_SUMMARY

# Backend status
if [ "${{ needs.deploy-backend-portainer.result }}" = "success" ]; then
echo "## ✅ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **Deployed successfully**" >> $GITHUB_STEP_SUMMARY
echo "- Platform: Portainer + Docker" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
echo "## ❌ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **Deployment failed**" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status**: Deployment failed" >> $GITHUB_STEP_SUMMARY
echo "🔍 **Check**: Review job logs for details" >> $GITHUB_STEP_SUMMARY
echo "🔗 **Portainer**: [Check Stack Status](https://portainer.sankalpnarula.com)" >> $GITHUB_STEP_SUMMARY
echo "## ⏭️ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
echo "- Status: **No changes, skipped**" >> $GITHUB_STEP_SUMMARY
fi
Loading
Loading