-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
52 lines (43 loc) · 1.66 KB
/
Copy pathrun.sh
File metadata and controls
52 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
IMAGE_NAME="finagent-env"
CONTAINER_NAME="finagent-env-container"
PORT=7860
echo "🚀 Building Docker image '$IMAGE_NAME'..."
docker build -t $IMAGE_NAME .
echo "🏃 Starting Docker container '$CONTAINER_NAME' on port $PORT..."
# Clean up any existing container with the same name
docker rm -f $CONTAINER_NAME 2>/dev/null || true
docker run -d --name $CONTAINER_NAME -p $PORT:$PORT $IMAGE_NAME
echo "⏳ Waiting for the FastAPI server to become healthy..."
MAX_RETRIES=15
RETRY_COUNT=0
# Loop until the healthcheck endpoint returns the expected JSON or we time out
until curl -s http://localhost:$PORT/health | grep -q '"status":"ok"'; do
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "❌ Healthcheck failed or timed out. Check container logs:"
docker logs $CONTAINER_NAME
docker rm -f $CONTAINER_NAME
exit 1
fi
echo " ...waiting (Attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 2
RETRY_COUNT=$((RETRY_COUNT+1))
done
echo "✅ Environment is up and healthy!"
echo "🤖 Running baseline inference script..."
# Check if key is in the environment OR if a .env file exists
if [ -z "$OPENAI_API_KEY" ] && [ ! -f .env ]; then
echo "⚠️ WARNING: OPENAI_API_KEY environment variable is not set and no .env file found."
echo "Please create a .env file with your key."
echo "Cleaning up container..."
docker rm -f $CONTAINER_NAME
exit 1
else
# Run the baseline script
python3 finagent_env/baseline.py
fi
echo "🧹 Cleaning up..."
docker rm -f $CONTAINER_NAME
echo "🎉 Run complete! Your OpenEnv submission is ready to ship."