-
Notifications
You must be signed in to change notification settings - Fork 0
Add automated deployment and testing scripts #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- deploy.sh: Install dependencies and setup virtual environment - start.sh: Start server with intelligent port fallback (7300→7301→etc) - send_openai_request.sh: Test API with OpenAI client - all.sh: One-command deployment, start, and test - Comprehensive README and QUICKSTART guide Features: - Port auto-detection and fallback logic - Virtual environment management - ZAI credentials support (optional) - Clean error handling with exit codes - Server readiness detection - Full test suite with response validation Usage: export ZAI_EMAIL='email' ZAI_PASSWORD='pass' SERVER_PORT=7322 bash scripts/all.sh Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 6 files
Prompt for AI agents (all 3 issues)
Understand the root cause of the following 3 issues and fix them.
<file name="scripts/start.sh">
<violation number="1" location="scripts/start.sh:23">
The Python fallback in is_port_in_use returns success when the port is free, so the loop believes every free port is occupied and either exits after 10 attempts or picks a port that is already bound.</violation>
</file>
<file name="scripts/README.md">
<violation number="1" location="scripts/README.md:325">
The Docker build command points at the repository root, but there is no Dockerfile there, so `docker build -t z-ai2api .` will fail. Update the command to reference the actual Dockerfile path.</violation>
</file>
<file name="scripts/send_openai_request.sh">
<violation number="1" location="scripts/send_openai_request.sh:39">
The script prints the AUTH_TOKEN directly to the console, exposing real credentials in logs. Remove or mask the token to avoid leaking secrets.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
scripts/start.sh
Outdated
| nc -z localhost $port &> /dev/null | ||
| else | ||
| # Fallback: try to bind with Python | ||
| ./.venv/bin/python -c "import socket; s=socket.socket(); s.bind(('', $port)); s.close()" 2>/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python fallback in is_port_in_use returns success when the port is free, so the loop believes every free port is occupied and either exits after 10 attempts or picks a port that is already bound.
Prompt for AI agents
Address the following comment on scripts/start.sh at line 23:
<comment>The Python fallback in is_port_in_use returns success when the port is free, so the loop believes every free port is occupied and either exits after 10 attempts or picks a port that is already bound.</comment>
<file context>
@@ -0,0 +1,106 @@
+ nc -z localhost $port &> /dev/null
+ else
+ # Fallback: try to bind with Python
+ ./.venv/bin/python -c "import socket; s=socket.socket(); s.bind(('', $port)); s.close()" 2>/dev/null
+ return $?
+ fi
</file context>
✅ Addressed in c963084
|
|
||
| ```bash | ||
| # Build image | ||
| docker build -t z-ai2api . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Docker build command points at the repository root, but there is no Dockerfile there, so docker build -t z-ai2api . will fail. Update the command to reference the actual Dockerfile path.
Prompt for AI agents
Address the following comment on scripts/README.md at line 325:
<comment>The Docker build command points at the repository root, but there is no Dockerfile there, so `docker build -t z-ai2api .` will fail. Update the command to reference the actual Dockerfile path.</comment>
<file context>
@@ -0,0 +1,385 @@
+
+```bash
+# Build image
+docker build -t z-ai2api .
+
+# Run container
</file context>
| docker build -t z-ai2api . | |
| docker build -f deploy/Dockerfile -t z-ai2api . |
scripts/send_openai_request.sh
Outdated
| echo "📡 Request details:" | ||
| echo " URL: http://localhost:$SERVER_PORT/v1" | ||
| echo " Model: gpt-5" | ||
| echo " AUTH_TOKEN: $AUTH_TOKEN" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script prints the AUTH_TOKEN directly to the console, exposing real credentials in logs. Remove or mask the token to avoid leaking secrets.
Prompt for AI agents
Address the following comment on scripts/send_openai_request.sh at line 39:
<comment>The script prints the AUTH_TOKEN directly to the console, exposing real credentials in logs. Remove or mask the token to avoid leaking secrets.</comment>
<file context>
@@ -0,0 +1,95 @@
+echo "📡 Request details:"
+echo " URL: http://localhost:$SERVER_PORT/v1"
+echo " Model: gpt-5"
+echo " AUTH_TOKEN: $AUTH_TOKEN"
+echo ""
+
</file context>
| echo " AUTH_TOKEN: $AUTH_TOKEN" | |
| echo " AUTH_TOKEN: ${AUTH_TOKEN:+(hidden)}" |
✅ Addressed in c963084
Fixes #3 security and logic issues identified by code review: 1. Fix port detection logic in start.sh - Python fallback was inverted: successful bind meant port was FREE - Now correctly returns: 0=in-use, 1=free - Prevents selecting already-bound ports 2. Mask AUTH_TOKEN in send_openai_request.sh - Only show first 8 chars: 'sk-any12... (masked for security)' - Prevents credential leakage in logs - Maintains security best practices 3. Fix Docker documentation in README.md - Added note that Dockerfile doesn't exist yet - Provided example Dockerfile for users - Prevents confusion with non-existent file 4. Add troubleshooting for Z.AI 405 errors - Document anonymous token acquisition failures - Provide workarounds (use credentials, check service status) - Help users resolve common API errors All fixes tested and validated. Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
🚀 Overview
This PR adds a complete set of automated deployment and testing scripts to make it easy to deploy and test the Z.AI to OpenAI API proxy with a single command.
✨ What's New
4 New Scripts
deploy.sh- Install dependencies and setup virtual environmentuvinstallationstart.sh- Start server with intelligent port fallbacksend_openai_request.sh- Test API with OpenAI clientall.sh- One-command deployment (RECOMMENDED)Documentation
scripts/README.md- Comprehensive guide with examples, troubleshooting, and advanced usagescripts/QUICKSTART.md- 60-second quick start guide🎯 Usage
Quick Start (Recommended)
Individual Scripts
🎨 Features
Intelligent Port Management
SERVER_PORT(default: 7300)server.portfileRobust Error Handling
all.shserver.logServer Management
server.pid)kill $(cat server.pid)bash scripts/start.shEnvironment Support
PYTHONPATHclearing to avoid conflicts📊 Test Results
Tested successfully with:
Sample Output
📁 Files Added
🔧 Environment Variables
SERVER_PORT7300ZAI_EMAILZAI_PASSWORDAUTH_TOKEN"sk-any"🐛 Error Handling
Each script has specific exit codes:
0- Success1- General error (missing files, venv not found)2- Missing dependency (uvnot installed)3- No available port found4- Server failed to start5- API request failed📖 Documentation
See the included documentation files:
✅ Checklist
🎉 Benefits
bash scripts/all.shReady to merge! This makes deployment trivially easy for new users. 🚀
💻 View my work • 👤 Initiated by @Zeeeepa • About Codegen
⛔ Remove Codegen from PR • 🚫 Ban action checks
Summary by cubic
Added automated scripts to deploy, start, and smoke‑test the OpenAI‑compatible proxy with one command. Improves onboarding with reliable venv setup, intelligent port fallback, and clear logs.