Skip to content

Commit 617afdb

Browse files
committed
updating frontend deployment to cloudflare workers
1 parent b29f2f5 commit 617afdb

File tree

6 files changed

+4252
-1023
lines changed

6 files changed

+4252
-1023
lines changed

.github/workflows/deploy.yml

Lines changed: 74 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
echo "✅ No frontend changes detected"
5555
fi
5656
57-
build-and-push:
57+
build-and-push-backend:
5858
name: Build and Push Backend
5959
runs-on: [self-hosted, home]
6060
needs: check-changes
@@ -99,70 +99,53 @@ jobs:
9999
cache-to: type=gha,mode=max
100100
platforms: linux/amd64,linux/arm64
101101

102-
build-frontend-image:
103-
name: Build Frontend Container
104-
runs-on: [self-hosted, home]
102+
deploy-frontend-cloudflare:
103+
name: Deploy Frontend to Cloudflare Workers
104+
runs-on: ubuntu-latest
105105
needs: check-changes
106106
if: needs.check-changes.outputs.frontend-changed == 'true'
107-
permissions:
108-
contents: read
109-
packages: write
110-
107+
108+
defaults:
109+
run:
110+
working-directory: ./frontend
111+
111112
steps:
112113
- name: Checkout code
113114
uses: actions/checkout@v4
114115

115-
- name: Set up Docker Buildx
116-
uses: docker/setup-buildx-action@v3
117-
118-
- name: Log in to Container Registry
119-
uses: docker/login-action@v3
116+
- name: Set up Node.js
117+
uses: actions/setup-node@v4
120118
with:
121-
registry: ${{ env.REGISTRY }}
122-
username: ${{ github.actor }}
123-
password: ${{ secrets.GITHUB_TOKEN }}
119+
node-version: '24'
120+
cache: 'npm'
121+
cache-dependency-path: './frontend/package-lock.json'
124122

125-
- name: Extract metadata for frontend
126-
id: meta
127-
uses: docker/metadata-action@v5
128-
with:
129-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend
130-
tags: |
131-
type=ref,event=branch
132-
type=sha,prefix={{branch}}-
133-
type=raw,value=latest,enable={{is_default_branch}}
123+
- name: Install dependencies
124+
run: npm ci
134125

135-
- name: Build and push Frontend Docker image
136-
uses: docker/build-push-action@v5
137-
with:
138-
context: ./frontend
139-
file: ./frontend/Dockerfile
140-
push: true
141-
tags: ${{ steps.meta.outputs.tags }}
142-
labels: ${{ steps.meta.outputs.labels }}
143-
cache-from: type=gha
144-
cache-to: type=gha,mode=max
145-
platforms: linux/amd64,linux/arm64
126+
- name: Install Wrangler
127+
run: npm install -g wrangler
146128

147-
deploy-via-portainer:
148-
name: Deploy via Portainer
129+
- name: Build for Cloudflare Workers
130+
run: npm run build:cloudflare
131+
env:
132+
NEXT_PUBLIC_API_URL: ${{ secrets.BACKEND_API_URL }}
133+
134+
- name: Deploy to Cloudflare Workers
135+
run: wrangler deploy
136+
env:
137+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
138+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
139+
140+
deploy-backend-portainer:
141+
name: Deploy Backend via Portainer
149142
runs-on: [self-hosted, home]
150-
needs: [check-changes, build-and-push, build-frontend-image]
143+
needs: [check-changes, build-and-push-backend]
151144
if: always() && github.ref == 'refs/heads/main' &&
152-
(needs.build-and-push.result == 'success' || needs.build-and-push.result == 'skipped') &&
153-
(needs.build-frontend-image.result == 'success' || needs.build-frontend-image.result == 'skipped') &&
154-
(needs.check-changes.outputs.backend-changed == 'true' || needs.check-changes.outputs.frontend-changed == 'true')
145+
needs.check-changes.outputs.backend-changed == 'true' &&
146+
(needs.build-and-push-backend.result == 'success' || needs.build-and-push-backend.result == 'skipped')
155147

156148
steps:
157-
- name: Deployment Info
158-
run: |
159-
echo "📋 **Deployment Information**" >> $GITHUB_STEP_SUMMARY
160-
echo "" >> $GITHUB_STEP_SUMMARY
161-
echo "- **Backend Changed**: ${{ needs.check-changes.outputs.backend-changed }}" >> $GITHUB_STEP_SUMMARY
162-
echo "- **Frontend Changed**: ${{ needs.check-changes.outputs.frontend-changed }}" >> $GITHUB_STEP_SUMMARY
163-
echo "- **Backend Build**: ${{ needs.build-and-push.result }}" >> $GITHUB_STEP_SUMMARY
164-
echo "- **Frontend Build**: ${{ needs.build-frontend-image.result }}" >> $GITHUB_STEP_SUMMARY
165-
166149
- name: Verify Portainer Connection
167150
run: |
168151
echo "🔍 Verifying connection to Portainer..."
@@ -173,18 +156,11 @@ jobs:
173156
exit 1
174157
fi
175158
176-
- name: Trigger Portainer Stack Redeployment
159+
- name: Trigger Portainer Stack Redeployment
177160
env:
178161
PORTAINER_WEBHOOK_URL: ${{ secrets.PORTAINER_WEBHOOK_URL }}
179-
BACKEND_CHANGED: ${{ needs.check-changes.outputs.backend-changed }}
180-
FRONTEND_CHANGED: ${{ needs.check-changes.outputs.frontend-changed }}
181162
run: |
182-
echo "🚀 Starting deployment process..."
183-
echo "📋 Backend changed: $BACKEND_CHANGED"
184-
echo "📋 Frontend changed: $FRONTEND_CHANGED"
185-
186-
# Trigger redeployment via webhook
187-
echo "🔄 Triggering stack redeployment via webhook..."
163+
echo "🚀 Starting backend deployment..."
188164
189165
RESPONSE=$(curl -s -w "%{http_code}" -X POST \
190166
-H "Content-Type: application/json" \
@@ -196,52 +172,52 @@ jobs:
196172
197173
case $HTTP_CODE in
198174
200|204)
199-
echo "✅ Stack redeployment triggered successfully!"
200-
[ -n "$RESPONSE_BODY" ] && echo "📝 Response: $RESPONSE_BODY"
175+
echo "✅ Backend redeployment triggered successfully!"
201176
;;
202177
*)
203-
echo "❌ Deployment webhook failed with HTTP $HTTP_CODE"
178+
echo "❌ Backend deployment failed with HTTP $HTTP_CODE"
204179
echo "📝 Response: $RESPONSE_BODY"
205-
echo "🔗 Check Portainer for more details"
206180
exit 1
207181
;;
208182
esac
209-
210-
echo "⏳ Deployment initiated via webhook - check Portainer for progress"
211-
echo "🔗 Monitor at: https://portainer.sankalpnarula.com"
212183
213-
- name: Deployment Summary
214-
if: always()
184+
deployment-summary:
185+
name: Deployment Summary
186+
runs-on: ubuntu-latest
187+
needs: [check-changes, deploy-frontend-cloudflare, deploy-backend-portainer]
188+
if: always() && github.ref == 'refs/heads/main'
189+
190+
steps:
191+
- name: Create Summary
215192
run: |
216-
echo "🎯 **Portainer Deployment Summary**" >> $GITHUB_STEP_SUMMARY
193+
echo "# 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
217194
echo "" >> $GITHUB_STEP_SUMMARY
218-
if [ "${{ job.status }}" = "success" ]; then
219-
echo "✅ **Status**: Deployment successful" >> $GITHUB_STEP_SUMMARY
220-
echo "🔗 **Portainer**: [View Stack](https://portainer.sankalpnarula.com)" >> $GITHUB_STEP_SUMMARY
221-
if [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
222-
echo "📦 **Backend Image**: \`ghcr.io/${{ github.repository }}:latest\` (updated)" >> $GITHUB_STEP_SUMMARY
223-
else
224-
echo "📦 **Backend Image**: \`ghcr.io/${{ github.repository }}:latest\` (unchanged)" >> $GITHUB_STEP_SUMMARY
225-
fi
226-
if [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
227-
echo "📦 **Frontend Image**: \`ghcr.io/${{ github.repository }}-frontend:latest\` (updated)" >> $GITHUB_STEP_SUMMARY
228-
else
229-
echo "📦 **Frontend Image**: \`ghcr.io/${{ github.repository }}-frontend:latest\` (unchanged)" >> $GITHUB_STEP_SUMMARY
230-
fi
231-
echo "" >> $GITHUB_STEP_SUMMARY
232-
echo "**What was deployed:**" >> $GITHUB_STEP_SUMMARY
233-
if [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
234-
echo "- ✅ Backend: Built and deployed new image" >> $GITHUB_STEP_SUMMARY
235-
else
236-
echo "- ⏭️ Backend: No changes, using existing image" >> $GITHUB_STEP_SUMMARY
237-
fi
238-
if [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
239-
echo "- ✅ Frontend: Built and deployed new image" >> $GITHUB_STEP_SUMMARY
240-
else
241-
echo "- ⏭️ Frontend: No changes, using existing image" >> $GITHUB_STEP_SUMMARY
242-
fi
195+
196+
# Frontend status
197+
if [ "${{ needs.deploy-frontend-cloudflare.result }}" = "success" ]; then
198+
echo "## ✅ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
199+
echo "- Status: **Deployed successfully**" >> $GITHUB_STEP_SUMMARY
200+
echo "- Platform: Cloudflare Workers" >> $GITHUB_STEP_SUMMARY
201+
echo "- Domain: https://ocpp.sankalpnarula.com" >> $GITHUB_STEP_SUMMARY
202+
elif [ "${{ needs.check-changes.outputs.frontend-changed }}" = "true" ]; then
203+
echo "## ❌ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
204+
echo "- Status: **Deployment failed**" >> $GITHUB_STEP_SUMMARY
205+
else
206+
echo "## ⏭️ Frontend (Cloudflare Workers)" >> $GITHUB_STEP_SUMMARY
207+
echo "- Status: **No changes, skipped**" >> $GITHUB_STEP_SUMMARY
208+
fi
209+
210+
echo "" >> $GITHUB_STEP_SUMMARY
211+
212+
# Backend status
213+
if [ "${{ needs.deploy-backend-portainer.result }}" = "success" ]; then
214+
echo "## ✅ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
215+
echo "- Status: **Deployed successfully**" >> $GITHUB_STEP_SUMMARY
216+
echo "- Platform: Portainer + Docker" >> $GITHUB_STEP_SUMMARY
217+
elif [ "${{ needs.check-changes.outputs.backend-changed }}" = "true" ]; then
218+
echo "## ❌ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
219+
echo "- Status: **Deployment failed**" >> $GITHUB_STEP_SUMMARY
243220
else
244-
echo "❌ **Status**: Deployment failed" >> $GITHUB_STEP_SUMMARY
245-
echo "🔍 **Check**: Review job logs for details" >> $GITHUB_STEP_SUMMARY
246-
echo "🔗 **Portainer**: [Check Stack Status](https://portainer.sankalpnarula.com)" >> $GITHUB_STEP_SUMMARY
221+
echo "## ⏭️ Backend (Portainer)" >> $GITHUB_STEP_SUMMARY
222+
echo "- Status: **No changes, skipped**" >> $GITHUB_STEP_SUMMARY
247223
fi

frontend/next.config.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22
const nextConfig = {
33
reactStrictMode: true,
44
swcMinify: true,
5-
output: 'standalone',
6-
assetPrefix: '',
7-
// Configure API proxy for development
8-
async rewrites() {
9-
return [
10-
{
11-
source: '/health',
12-
destination: 'http://localhost:8080/health', // Health check endpoint
13-
},
14-
{
15-
source: '/api/:path*',
16-
destination: 'http://localhost:8080/api/:path*', // Go backend
17-
},
18-
{
19-
source: '/ws',
20-
destination: 'http://localhost:8080/ws', // WebSocket endpoint
21-
},
22-
];
5+
output: 'export', // Static export for Cloudflare Workers
6+
trailingSlash: true,
7+
images: {
8+
unoptimized: true // Required for static export
239
},
10+
// Configure API proxy only for development (rewrites don't work with export)
11+
...(process.env.NODE_ENV === 'development' && {
12+
async rewrites() {
13+
return [
14+
{
15+
source: '/health',
16+
destination: 'http://localhost:8080/health', // Health check endpoint
17+
},
18+
{
19+
source: '/api/:path*',
20+
destination: 'http://localhost:8080/api/:path*', // Go backend
21+
},
22+
{
23+
source: '/ws',
24+
destination: 'http://localhost:8080/ws', // WebSocket endpoint
25+
},
26+
];
27+
},
28+
}),
2429
};
2530

2631
module.exports = nextConfig;

0 commit comments

Comments
 (0)