Skip to content

Commit 4feb18b

Browse files
authored
Merge pull request #138 from Zeeeepa/codegen-bot/update-examples-deployment-scripts
2 parents 759732b + 77fd74c commit 4feb18b

File tree

31 files changed

+1789
-300
lines changed

31 files changed

+1789
-300
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
# Check if Python is installed
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Python 3 is required but not installed. Please install Python 3 and try again."
13+
exit 1
14+
fi
15+
16+
# Check if Modal is installed
17+
if ! python3 -c "import modal" &> /dev/null; then
18+
echo "Modal is not installed. Installing now..."
19+
pip install modal
20+
fi
21+
22+
# Check if Modal token is set up
23+
if ! modal token list &> /dev/null; then
24+
echo "Modal token not set up. Please run 'modal token new' to set up your Modal token."
25+
exit 1
26+
fi
27+
28+
# Function to deploy a single example
29+
deploy_example() {
30+
local example_dir="$1"
31+
local example_name=$(basename "$example_dir")
32+
33+
if [ -f "$example_dir/deploy.sh" ]; then
34+
echo "Deploying $example_name..."
35+
(cd "$example_dir" && bash deploy.sh)
36+
return $?
37+
else
38+
echo "No deploy.sh script found for $example_name. Skipping."
39+
return 1
40+
fi
41+
}
42+
43+
# Find all examples with deploy.sh scripts
44+
examples=()
45+
for dir in "$SCRIPT_DIR"/*/; do
46+
if [ -f "${dir}deploy.sh" ]; then
47+
examples+=("$(basename "$dir")")
48+
fi
49+
done
50+
51+
if [ ${#examples[@]} -eq 0 ]; then
52+
echo "No deployable examples found."
53+
exit 1
54+
fi
55+
56+
# Display menu
57+
echo "Available examples for deployment:"
58+
echo ""
59+
60+
for i in "${!examples[@]}"; do
61+
echo "[$((i+1))] ${examples[$i]}"
62+
done
63+
64+
echo ""
65+
echo "[a] Deploy all examples"
66+
echo "[q] Quit"
67+
echo ""
68+
69+
# Get user selection
70+
selected_indices=()
71+
while true; do
72+
read -p "Select examples to deploy (e.g., '1 3 5' or 'a' for all, 'q' to quit, 'd' when done): " selection
73+
74+
if [ "$selection" == "q" ]; then
75+
echo "Exiting without deployment."
76+
exit 0
77+
elif [ "$selection" == "a" ]; then
78+
for i in "${!examples[@]}"; do
79+
selected_indices+=($i)
80+
done
81+
break
82+
elif [ "$selection" == "d" ]; then
83+
if [ ${#selected_indices[@]} -eq 0 ]; then
84+
echo "No examples selected. Please select at least one example."
85+
else
86+
break
87+
fi
88+
else
89+
# Parse space-separated numbers
90+
for num in $selection; do
91+
if [[ "$num" =~ ^[0-9]+$ ]] && [ "$num" -ge 1 ] && [ "$num" -le ${#examples[@]} ]; then
92+
idx=$((num-1))
93+
# Check if already selected
94+
if [[ ! " ${selected_indices[@]} " =~ " ${idx} " ]]; then
95+
selected_indices+=($idx)
96+
echo "Added ${examples[$idx]} to deployment list."
97+
else
98+
echo "${examples[$idx]} is already selected."
99+
fi
100+
else
101+
echo "Invalid selection: $num. Please enter numbers between 1 and ${#examples[@]}."
102+
fi
103+
done
104+
fi
105+
done
106+
107+
# Show selected examples
108+
echo ""
109+
echo "Selected examples for deployment:"
110+
for idx in "${selected_indices[@]}"; do
111+
echo "- ${examples[$idx]}"
112+
done
113+
echo ""
114+
115+
# Confirm deployment
116+
read -p "Deploy these examples? (y/n): " confirm
117+
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
118+
echo "Deployment cancelled."
119+
exit 0
120+
fi
121+
122+
# Deploy selected examples concurrently
123+
echo "Starting deployment of selected examples..."
124+
pids=()
125+
results=()
126+
127+
for idx in "${selected_indices[@]}"; do
128+
example="${examples[$idx]}"
129+
example_dir="$SCRIPT_DIR/$example"
130+
131+
# Start deployment in background
132+
(deploy_example "$example_dir" && echo "SUCCESS: $example" || echo "FAILED: $example") &
133+
pids+=($!)
134+
results+=("")
135+
done
136+
137+
# Wait for all deployments to complete
138+
for i in "${!pids[@]}"; do
139+
wait "${pids[$i]}"
140+
results[$i]=$?
141+
done
142+
143+
# Print summary
144+
echo ""
145+
echo "Deployment Summary:"
146+
echo "=================="
147+
success_count=0
148+
failure_count=0
149+
150+
for i in "${!selected_indices[@]}"; do
151+
idx="${selected_indices[$i]}"
152+
example="${examples[$idx]}"
153+
result="${results[$i]}"
154+
155+
if [ "$result" -eq 0 ]; then
156+
echo "${example}: SUCCESS"
157+
((success_count++))
158+
else
159+
echo "${example}: FAILED"
160+
((failure_count++))
161+
fi
162+
done
163+
164+
echo ""
165+
echo "Total: $((success_count + failure_count)), Successful: $success_count, Failed: $failure_count"
166+
167+
if [ "$failure_count" -gt 0 ]; then
168+
echo ""
169+
echo "Some deployments failed. Check the logs above for details."
170+
exit 1
171+
fi
172+
173+
echo ""
174+
echo "All deployments completed successfully!"
175+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
# Check if Python is installed
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Python 3 is required but not installed. Please install Python 3 and try again."
13+
exit 1
14+
fi
15+
16+
# Check if Modal is installed
17+
if ! python3 -c "import modal" &> /dev/null; then
18+
echo "Modal is not installed. Installing now..."
19+
pip install modal
20+
fi
21+
22+
# Check if Modal token is set up
23+
if ! modal token list &> /dev/null; then
24+
echo "Modal token not set up. Please run 'modal token new' to set up your Modal token."
25+
exit 1
26+
fi
27+
28+
# Create .env file if it doesn't exist
29+
if [ ! -f .env ]; then
30+
echo "Creating .env file..."
31+
cat > .env << EOL
32+
# GitHub credentials
33+
GITHUB_TOKEN=your_github_token
34+
35+
# Modal configuration (optional)
36+
MODAL_API_KEY=your_modal_api_key
37+
EOL
38+
echo "Please edit the .env file with your credentials before deploying."
39+
exit 1
40+
fi
41+
42+
# Deploy the backend API
43+
echo "Deploying AI Impact Analysis Backend API to Modal..."
44+
python3 dashboard/backend/api.py
45+
46+
echo "Deployment complete! You can check the status with 'modal app status ai-impact-analysis-api'"
47+
echo "To view logs, run 'modal app logs ai-impact-analysis-api'"
48+
49+
# Instructions for frontend deployment
50+
echo ""
51+
echo "To deploy the frontend:"
52+
echo "1. Navigate to the frontend directory: cd dashboard/frontend"
53+
echo "2. Install dependencies: npm install"
54+
echo "3. Update the API_URL in src/config.js to point to your Modal deployment"
55+
echo "4. Build the frontend: npm run build"
56+
echo "5. Deploy to your preferred hosting service (e.g., Vercel, Netlify, GitHub Pages)"
57+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
# Check if Python is installed
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Python 3 is required but not installed. Please install Python 3 and try again."
13+
exit 1
14+
fi
15+
16+
# Check if Modal is installed
17+
if ! python3 -c "import modal" &> /dev/null; then
18+
echo "Modal is not installed. Installing now..."
19+
pip install modal
20+
fi
21+
22+
# Check if Modal token is set up
23+
if ! modal token list &> /dev/null; then
24+
echo "Modal token not set up. Please run 'modal token new' to set up your Modal token."
25+
exit 1
26+
fi
27+
28+
# Create .env file if it doesn't exist
29+
if [ ! -f .env ]; then
30+
echo "Creating .env file..."
31+
cat > .env << EOL
32+
# GitHub credentials (for repository access)
33+
GITHUB_TOKEN=your_github_token
34+
35+
# OpenAI credentials (if using OpenAI)
36+
OPENAI_API_KEY=your_openai_api_key
37+
38+
# Modal configuration (optional)
39+
MODAL_API_KEY=your_modal_api_key
40+
EOL
41+
echo "Please edit the .env file with your credentials before deploying."
42+
exit 1
43+
fi
44+
45+
# Check if LLM dependencies are installed
46+
echo "Note: This server requires LLM dependencies. See llms-install.md for details."
47+
48+
# Deploy the application
49+
echo "Deploying Codegen MCP Server to Modal..."
50+
python3 server.py
51+
52+
echo "Deployment complete! You can check the status with 'modal app status codegen-mcp-server'"
53+
echo "To view logs, run 'modal app logs codegen-mcp-server'"
54+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
# Check if Python is installed
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Python 3 is required but not installed. Please install Python 3 and try again."
13+
exit 1
14+
fi
15+
16+
# Check if Modal is installed
17+
if ! python3 -c "import modal" &> /dev/null; then
18+
echo "Modal is not installed. Installing now..."
19+
pip install modal
20+
fi
21+
22+
# Check if Modal token is set up
23+
if ! modal token list &> /dev/null; then
24+
echo "Modal token not set up. Please run 'modal token new' to set up your Modal token."
25+
exit 1
26+
fi
27+
28+
# Create .env file if it doesn't exist
29+
if [ ! -f .env ]; then
30+
echo "Creating .env file..."
31+
cat > .env << EOL
32+
# GitHub credentials
33+
GITHUB_TOKEN=your_github_token
34+
35+
# Modal configuration (optional)
36+
MODAL_API_KEY=your_modal_api_key
37+
EOL
38+
echo "Please edit the .env file with your credentials before deploying."
39+
exit 1
40+
fi
41+
42+
# Deploy the application
43+
echo "Deploying Codegen App to Modal..."
44+
python3 app.py
45+
46+
echo "Deployment complete! You can check the status with 'modal app status codegen-app'"
47+
echo "To view logs, run 'modal app logs codegen-app'"
48+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
# Check if Python is installed
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Python 3 is required but not installed. Please install Python 3 and try again."
13+
exit 1
14+
fi
15+
16+
# Check if Modal is installed
17+
if ! python3 -c "import modal" &> /dev/null; then
18+
echo "Modal is not installed. Installing now..."
19+
pip install modal
20+
fi
21+
22+
# Check if Modal token is set up
23+
if ! modal token list &> /dev/null; then
24+
echo "Modal token not set up. Please run 'modal token new' to set up your Modal token."
25+
exit 1
26+
fi
27+
28+
# Create .env file if it doesn't exist
29+
if [ ! -f .env ]; then
30+
echo "Creating .env file..."
31+
cat > .env << EOL
32+
# GitHub credentials
33+
GITHUB_TOKEN=your_github_token
34+
35+
# Modal configuration (optional)
36+
MODAL_API_KEY=your_modal_api_key
37+
EOL
38+
echo "Please edit the .env file with your credentials before deploying."
39+
exit 1
40+
fi
41+
42+
# Deploy the application
43+
echo "Deploying Cyclomatic Complexity Analyzer to Modal..."
44+
python3 run.py
45+
46+
echo "Deployment complete! You can check the status with 'modal app status cyclomatic-complexity'"
47+
echo "To view logs, run 'modal app logs cyclomatic-complexity'"
48+

0 commit comments

Comments
 (0)