Spaces:
Runtime error
Runtime error
Commit
·
825f021
1
Parent(s):
9de4eee
Added run.sh
Browse files
run.sh
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Default values
|
4 |
+
PORT=7860
|
5 |
+
ENV_FILE=".env"
|
6 |
+
CONTAINER_NAME="llm-inference-server"
|
7 |
+
BUILD_ONLY=false
|
8 |
+
PLATFORM=""
|
9 |
+
|
10 |
+
# Function to display usage
|
11 |
+
usage() {
|
12 |
+
echo "Usage: $0 [-p <port>] [-e <env_file>] [-n <container_name>] [-b] [-h]"
|
13 |
+
echo " -p : Port to expose (default: 7860)"
|
14 |
+
echo " -e : Environment file path (default: .env)"
|
15 |
+
echo " -n : Container name (default: llm-inference-server)"
|
16 |
+
echo " -b : Build only (don't run container)"
|
17 |
+
echo " -h : Display this help message"
|
18 |
+
exit 1
|
19 |
+
}
|
20 |
+
|
21 |
+
# Parse command line arguments
|
22 |
+
while getopts "p:e:n:bh" opt; do
|
23 |
+
case $opt in
|
24 |
+
p) PORT=$OPTARG ;;
|
25 |
+
e) ENV_FILE=$OPTARG ;;
|
26 |
+
n) CONTAINER_NAME=$OPTARG ;;
|
27 |
+
b) BUILD_ONLY=true ;;
|
28 |
+
h) usage ;;
|
29 |
+
?) usage ;;
|
30 |
+
esac
|
31 |
+
done
|
32 |
+
|
33 |
+
# Detect platform and set appropriate options
|
34 |
+
if [[ "$(uname -s)" == "Darwin" ]]; then
|
35 |
+
echo "Detected MacOS platform"
|
36 |
+
PLATFORM="linux/arm64"
|
37 |
+
if [[ "$(uname -m)" == "x86_64" ]]; then
|
38 |
+
PLATFORM="linux/amd64"
|
39 |
+
fi
|
40 |
+
PLATFORM_ARG="--platform=${PLATFORM}"
|
41 |
+
else
|
42 |
+
echo "Detected Linux platform"
|
43 |
+
PLATFORM_ARG=""
|
44 |
+
# Check if podman is available (common in RHEL environments)
|
45 |
+
if command -v podman &> /dev/null; then
|
46 |
+
echo "Podman detected, using podman instead of docker"
|
47 |
+
function docker { podman "${@}"; }
|
48 |
+
fi
|
49 |
+
|
50 |
+
# Check if docker is installed
|
51 |
+
if ! command -v docker &> /dev/null; then
|
52 |
+
echo "Error: docker is not installed"
|
53 |
+
exit 1
|
54 |
+
fi
|
55 |
+
|
56 |
+
# Check if .env file exists
|
57 |
+
if [ ! -f "$ENV_FILE" ]; then
|
58 |
+
echo "Warning: $ENV_FILE file not found"
|
59 |
+
echo "Creating sample $ENV_FILE file..."
|
60 |
+
cat > "$ENV_FILE" << EOL
|
61 |
+
InfAPITokenWrite=your_huggingface_token_here
|
62 |
+
EOL
|
63 |
+
echo "Please edit $ENV_FILE with your actual configuration"
|
64 |
+
fi
|
65 |
+
|
66 |
+
# Build the Docker image
|
67 |
+
echo "Building Docker image..."
|
68 |
+
docker build $PLATFORM_ARG -t $CONTAINER_NAME .
|
69 |
+
|
70 |
+
# Exit if build only
|
71 |
+
if [ "$BUILD_ONLY" = true ]; then
|
72 |
+
echo "Build completed. Exiting as requested."
|
73 |
+
exit 0
|
74 |
+
fi
|
75 |
+
|
76 |
+
# Check if container is already running
|
77 |
+
if docker ps -q -f name=$CONTAINER_NAME | grep -q .; then
|
78 |
+
echo "Stopping existing container..."
|
79 |
+
docker stop $CONTAINER_NAME
|
80 |
+
fi
|
81 |
+
|
82 |
+
# Remove existing container
|
83 |
+
if docker ps -aq -f name=$CONTAINER_NAME | grep -q .; then
|
84 |
+
echo "Removing existing container..."
|
85 |
+
docker rm $CONTAINER_NAME
|
86 |
+
fi
|
87 |
+
|
88 |
+
# Run the container
|
89 |
+
echo "Starting container on port $PORT..."
|
90 |
+
docker run -d \
|
91 |
+
--name $CONTAINER_NAME \
|
92 |
+
--env-file $ENV_FILE \
|
93 |
+
-p $PORT:7860 \
|
94 |
+
-v $HOME/.cache/huggingface:/home/user/.cache/huggingface \
|
95 |
+
$CONTAINER_NAME
|
96 |
+
|
97 |
+
echo "Container started! API should be available at http://localhost:$PORT"
|
98 |
+
echo "To view logs, run: docker logs -f $CONTAINER_NAME"
|