AurelioAguirre commited on
Commit
65f1d1f
·
1 Parent(s): 2f48b4a

Updated run.sh and Dockerfile.

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -0
  2. run.sh +37 -19
Dockerfile CHANGED
@@ -32,6 +32,7 @@ RUN pip install --no-cache-dir --upgrade pip && \
32
  # Copy application code
33
  COPY --chown=1001:0 . /app
34
  COPY --chown=1001:0 main/ /app/main
 
35
 
36
  # Create directory for models cache
37
  RUN mkdir -p /app/.cache/huggingface && \
 
32
  # Copy application code
33
  COPY --chown=1001:0 . /app
34
  COPY --chown=1001:0 main/ /app/main
35
+ COPY --chown=1001:0 resources/local_config.yaml /app/resources/local_config.yaml
36
 
37
  # Create directory for models cache
38
  RUN mkdir -p /app/.cache/huggingface && \
run.sh CHANGED
@@ -3,7 +3,7 @@
3
  set -e # Exit on error
4
 
5
  # Default values
6
- PORT=7860
7
  ENV_FILE=".env"
8
  CONTAINER_NAME="llm-inference-server"
9
  BUILD_ONLY=false
@@ -11,8 +11,8 @@ PLATFORM=""
11
 
12
  # Function to display usage
13
  usage() {
14
- echo "Usage: $0 [-p <port>] [-e <env_file>] [-n <container_name>] [-b] [-h]"
15
- echo " -p : Port to expose (default: 7860)"
16
  echo " -e : Environment file path (default: .env)"
17
  echo " -n : Container name (default: llm-inference-server)"
18
  echo " -b : Build only (don't run container)"
@@ -26,10 +26,26 @@ handle_error() {
26
  exit 1
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Parse command line arguments
30
- while getopts "p:e:n:bh" opt; do
31
  case $opt in
32
- p) PORT=$OPTARG ;;
33
  e) ENV_FILE=$OPTARG ;;
34
  n) CONTAINER_NAME=$OPTARG ;;
35
  b) BUILD_ONLY=true ;;
@@ -38,6 +54,15 @@ while getopts "p:e:n:bh" opt; do
38
  esac
39
  done
40
 
 
 
 
 
 
 
 
 
 
41
  # Detect platform and set appropriate options
42
  if [[ "$(uname -s)" == "Darwin" ]]; then
43
  echo "Detected MacOS platform"
@@ -93,22 +118,15 @@ if docker ps -aq -f name=$CONTAINER_NAME | grep -q .; then
93
  docker rm $CONTAINER_NAME || handle_error "Failed to remove existing container"
94
  fi
95
 
96
- # Run the container
97
  echo "Starting container on port $PORT..."
98
- if ! docker run -d \
 
99
  --name $CONTAINER_NAME \
100
  --env-file $ENV_FILE \
101
- -p $PORT:7860 \
102
  -v $HOME/.cache/huggingface:/app/.cache/huggingface \
103
- $CONTAINER_NAME; then
104
- handle_error "Failed to start container"
105
- fi
106
-
107
- # Verify container is running
108
- if ! docker ps | grep -q $CONTAINER_NAME; then
109
- handle_error "Container failed to start. Check logs with: docker logs $CONTAINER_NAME"
110
- fi
111
 
112
- echo "Container started successfully!"
113
- echo "API should be available at http://localhost:$PORT"
114
- echo "To view logs, run: docker logs -f $CONTAINER_NAME"
 
3
  set -e # Exit on error
4
 
5
  # Default values
6
+ CONFIG_FILE="resources/local_config.yaml"
7
  ENV_FILE=".env"
8
  CONTAINER_NAME="llm-inference-server"
9
  BUILD_ONLY=false
 
11
 
12
  # Function to display usage
13
  usage() {
14
+ echo "Usage: $0 [-c <config_file>] [-e <env_file>] [-n <container_name>] [-b] [-h]"
15
+ echo " -c : Config file path (default: resources/local_config.yaml)"
16
  echo " -e : Environment file path (default: .env)"
17
  echo " -n : Container name (default: llm-inference-server)"
18
  echo " -b : Build only (don't run container)"
 
26
  exit 1
27
  }
28
 
29
+ # Function to read yaml (simplified)
30
+ parse_yaml() {
31
+ local file=$1
32
+ if command -v python3 &> /dev/null; then
33
+ python3 -c "
34
+ import yaml
35
+ with open('$file', 'r') as f:
36
+ config = yaml.safe_load(f)
37
+ print(config['server']['port'])
38
+ print(config['server']['host'])
39
+ "
40
+ else
41
+ handle_error "Python3 is required to parse YAML config"
42
+ fi
43
+ }
44
+
45
  # Parse command line arguments
46
+ while getopts "c:e:n:bh" opt; do
47
  case $opt in
48
+ c) CONFIG_FILE=$OPTARG ;;
49
  e) ENV_FILE=$OPTARG ;;
50
  n) CONTAINER_NAME=$OPTARG ;;
51
  b) BUILD_ONLY=true ;;
 
54
  esac
55
  done
56
 
57
+ # Check if config file exists
58
+ if [ ! -f "$CONFIG_FILE" ]; then
59
+ handle_error "Config file not found: $CONFIG_FILE"
60
+ fi
61
+
62
+ # Read port and host from config
63
+ read PORT HOST < <(parse_yaml "$CONFIG_FILE")
64
+ echo "Using configuration - Port: $PORT, Host: $HOST"
65
+
66
  # Detect platform and set appropriate options
67
  if [[ "$(uname -s)" == "Darwin" ]]; then
68
  echo "Detected MacOS platform"
 
118
  docker rm $CONTAINER_NAME || handle_error "Failed to remove existing container"
119
  fi
120
 
121
+ # Run the container in interactive mode
122
  echo "Starting container on port $PORT..."
123
+ echo "Press Ctrl+C to stop the server"
124
+ docker run --rm -it \
125
  --name $CONTAINER_NAME \
126
  --env-file $ENV_FILE \
127
+ -p $PORT:$PORT \
128
  -v $HOME/.cache/huggingface:/app/.cache/huggingface \
129
+ -v "$(pwd)/$CONFIG_FILE:/app/$CONFIG_FILE" \
130
+ $CONTAINER_NAME
 
 
 
 
 
 
131
 
132
+ echo "Container stopped"