Skip to content

Commit f3f9d5b

Browse files
committed
feat: add support for LOCAL_R2 var for local dev
1 parent 73a658e commit f3f9d5b

File tree

6 files changed

+76
-37
lines changed

6 files changed

+76
-37
lines changed

definitions/vite-cf-DO-runner/prompts/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async addMyData(item: MyType): Promise<MyType[]> {
9696

9797
## Bindings
9898
CRITICAL: only `GlobalDurableObject` is available for stateful ops
99+
**IMPORTANT: You are NOT ALLOWED to edit/add/remove ANY worker bindings OR touch wrangler.jsonc/wrangler.toml. Build your application around what is already provided.**
99100

100101
**YOU CANNOT**:
101102
- Modify `wrangler.jsonc`

definitions/vite-cf-DO-v2-runner/prompts/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ app.post('/api/users', async (c) => {
7070

7171
## Bindings
7272
CRITICAL: only `GlobalDurableObject` is available for stateful ops
73+
**IMPORTANT: You are NOT ALLOWED to edit/add/remove ANY worker bindings OR touch wrangler.jsonc/wrangler.toml. Build your application around what is already provided.**
7374

7475
**YOU CANNOT**:
7576
- Modify `wrangler.jsonc`

definitions/vite-cfagents-runner/prompts/selection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This template provides a production-ready AI agent chatbot built with Cloudflare
88
* Multi-model AI support (GPT-4o, Gemini 2.0/2.5, Claude Opus 4)
99
* Production-ready MCP integration with official TypeScript SDK
1010
* Real-time conversation management
11-
* Real-time streaming chat
11+
* Real-time streaming chat with AI Agents
1212
* Advanced AI Agents capabilities and AI based applications like image generation, chat bots etc
1313

1414
* Do not use it for:
@@ -17,7 +17,7 @@ This template provides a production-ready AI agent chatbot built with Cloudflare
1717
* Projects requiring complex multi-user chat rooms or real-time streaming
1818
* Simple question-answer bots without tool requirements
1919

20-
**IMPORTANT NOTE: Only use this template if you NEED AI/LLM capabilities as core of your application**
20+
**IMPORTANT NOTE: Only use this template if you NEED AI/LLM capabilities as core of your application. If the requirement is for durable objects, there are much better templates like 'vite-cf-DO-runner' or 'vite-cf-DO-v2-runner'**
2121

2222
* Built with:
2323
* **Cloudflare Agents SDK** for stateful agent management with Durable Objects

definitions/vite-cfagents-runner/prompts/usage.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ tooltip.tsx
171171

172172
# Available bindings:
173173
**Only The following bindings are to be used in the project! Do not use any other bindings or remove/replace any of the bindings**
174-
- `CHAT_AGENT`: A durable object binding for the chat agent
175-
- `APP_CONTROLLER`: A durable object binding for the app controller
174+
- `CHAT_AGENT`: A durable object binding for the chat agent, but can be extended and used for other agentic purposes
175+
- `APP_CONTROLLER`: A durable object binding for the app controller, but can be extended and used for other agentic purposes
176+
**IMPORTANT: You are NOT ALLOWED to edit/add/remove ANY worker bindings OR touch wrangler.jsonc/wrangler.toml. Build your application around what is already provided.**
176177

177178
# IMPORTANT NOTE: If AI capabilities are required, you must inform the user that although this project has AI capaibilities, there is no way to pass API keys and thus AI inferencing won't work. Users must export the app to their github, then make necessary changes and deploy it themselves to have it work. This is due to security reasons but we are implementing it in a secure way, and this would be available soon.
178179
Add the above note in an appropriate and visible location in the app - like in the footer or in the chat interface or as a modal

deploy_templates.sh

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,19 @@ echo "⚙️ Verifying Wrangler CLI..."
9595
wrangler --version
9696
echo "✅ Wrangler CLI ready"
9797

98-
# Upload files to Cloudflare R2
99-
echo "🚀 Uploading files to Cloudflare R2..."
98+
# Determine R2 endpoint based on LOCAL_R2 environment variable
99+
if [ "${LOCAL_R2:-}" = "true" ]; then
100+
echo "🏠 LOCAL_R2=true - using local R2 endpoint"
101+
R2_FLAGS="--local"
102+
R2_ENDPOINT="local R2"
103+
else
104+
echo "☁️ Using remote Cloudflare R2"
105+
R2_FLAGS="--remote"
106+
R2_ENDPOINT="Cloudflare R2"
107+
fi
108+
109+
# Upload files to R2
110+
echo "🚀 Uploading files to $R2_ENDPOINT..."
100111

101112
# Function to upload a file to R2
102113
upload_to_r2() {
@@ -105,7 +116,7 @@ upload_to_r2() {
105116
local description="$3"
106117

107118
echo "Uploading: $description"
108-
if wrangler r2 object put "${R2_BUCKET_NAME}/$r2_key" --file="$file_path" --remote; then
119+
if wrangler r2 object put "${R2_BUCKET_NAME}/$r2_key" --file="$file_path" $R2_FLAGS; then
109120
echo "✅ Successfully uploaded $description"
110121
return 0
111122
else
@@ -114,31 +125,51 @@ upload_to_r2() {
114125
fi
115126
}
116127

117-
# Upload template catalog JSON and all zip files in parallel
118-
echo "📄📦 Uploading template catalog and zip files in parallel..."
119-
upload_pids=()
120-
failed_uploads=()
121-
122-
# Start catalog upload in background
123-
upload_to_r2 "template_catalog.json" "template_catalog.json" "template_catalog.json" &
124-
upload_pids+=($!)
125-
126-
# Start zip file uploads in background
127-
for zip_file in zips/*.zip; do
128-
if [ -f "$zip_file" ]; then
129-
filename=$(basename "$zip_file")
130-
upload_to_r2 "$zip_file" "$filename" "$filename" &
131-
upload_pids+=($!)
132-
fi
133-
done
128+
# Upload template catalog JSON and all zip files
129+
if [ "${LOCAL_R2:-}" = "true" ]; then
130+
echo "📄📦 Uploading template catalog and zip files sequentially (local R2)..."
131+
failed_uploads=()
134132

135-
# Wait for all uploads to complete and check for failures
136-
echo "⏳ Waiting for all uploads to complete..."
137-
for pid in "${upload_pids[@]}"; do
138-
if ! wait "$pid"; then
139-
failed_uploads+=("Upload process $pid failed")
133+
# Upload catalog first
134+
if ! upload_to_r2 "template_catalog.json" "template_catalog.json" "template_catalog.json"; then
135+
failed_uploads+=("template_catalog.json upload failed")
140136
fi
141-
done
137+
138+
# Upload zip files sequentially
139+
for zip_file in zips/*.zip; do
140+
if [ -f "$zip_file" ]; then
141+
filename=$(basename "$zip_file")
142+
if ! upload_to_r2 "$zip_file" "$filename" "$filename"; then
143+
failed_uploads+=("$filename upload failed")
144+
fi
145+
fi
146+
done
147+
else
148+
echo "📄📦 Uploading template catalog and zip files in parallel..."
149+
upload_pids=()
150+
failed_uploads=()
151+
152+
# Start catalog upload in background
153+
upload_to_r2 "template_catalog.json" "template_catalog.json" "template_catalog.json" &
154+
upload_pids+=($!)
155+
156+
# Start zip file uploads in background
157+
for zip_file in zips/*.zip; do
158+
if [ -f "$zip_file" ]; then
159+
filename=$(basename "$zip_file")
160+
upload_to_r2 "$zip_file" "$filename" "$filename" &
161+
upload_pids+=($!)
162+
fi
163+
done
164+
165+
# Wait for all uploads to complete and check for failures
166+
echo "⏳ Waiting for all uploads to complete..."
167+
for pid in "${upload_pids[@]}"; do
168+
if ! wait "$pid"; then
169+
failed_uploads+=("Upload process $pid failed")
170+
fi
171+
done
172+
fi
142173

143174
# Check if any uploads failed
144175
if [ ${#failed_uploads[@]} -gt 0 ]; then
@@ -149,7 +180,7 @@ if [ ${#failed_uploads[@]} -gt 0 ]; then
149180
exit 1
150181
fi
151182

152-
echo "🎉 All files uploaded successfully to R2 bucket: ${R2_BUCKET_NAME}"
183+
echo "🎉 All files uploaded successfully to $R2_ENDPOINT bucket: ${R2_BUCKET_NAME}"
153184

154185
# Skip verification as wrangler doesn't have a list command
155186
echo "✅ All uploads completed successfully"
@@ -177,8 +208,13 @@ if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
177208

178209
echo "" >> $GITHUB_STEP_SUMMARY
179210
echo "### 🌐 Access URLs" >> $GITHUB_STEP_SUMMARY
180-
echo "- **Catalog**: \`https://${R2_BUCKET_NAME}.r2.dev/template_catalog.json\`" >> $GITHUB_STEP_SUMMARY
181-
echo "- **Templates**: \`https://${R2_BUCKET_NAME}.r2.dev/[template-name].zip\`" >> $GITHUB_STEP_SUMMARY
211+
if [ "${LOCAL_R2:-}" = "true" ]; then
212+
echo "- **Target**: Local R2 (${R2_BUCKET_NAME})" >> $GITHUB_STEP_SUMMARY
213+
echo "- **Note**: Files uploaded to local R2 development environment" >> $GITHUB_STEP_SUMMARY
214+
else
215+
echo "- **Catalog**: \`https://${R2_BUCKET_NAME}.r2.dev/template_catalog.json\`" >> $GITHUB_STEP_SUMMARY
216+
echo "- **Templates**: \`https://${R2_BUCKET_NAME}.r2.dev/[template-name].zip\`" >> $GITHUB_STEP_SUMMARY
217+
fi
182218
echo "" >> $GITHUB_STEP_SUMMARY
183219
echo "🕐 **Deployed at**: $(date -u +%Y-%m-%d\ %H:%M:%S\ UTC)" >> $GITHUB_STEP_SUMMARY
184220
fi

0 commit comments

Comments
 (0)