瀏覽代碼

added option to specify if build image or not

Daniele Viti 1 年之前
父節點
當前提交
16a2d0cdb0
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      run-compose.sh

+ 13 - 2
run-compose.sh

@@ -74,6 +74,7 @@ usage() {
     echo "  --enable-api[port=PORT]    Enable API and expose it on the specified port."
     echo "  --enable-api[port=PORT]    Enable API and expose it on the specified port."
     echo "  --webui[port=PORT]         Set the port for the web user interface."
     echo "  --webui[port=PORT]         Set the port for the web user interface."
     echo "  --data[folder=PATH]        Bind mount for ollama data folder (by default will create the 'ollama' volume)."
     echo "  --data[folder=PATH]        Bind mount for ollama data folder (by default will create the 'ollama' volume)."
+    echo "  --build                    Build the docker image before running the compose project."
     echo "  -q, --quiet                Run script in headless mode."
     echo "  -q, --quiet                Run script in headless mode."
     echo "  -h, --help                 Show this help message."
     echo "  -h, --help                 Show this help message."
     echo ""
     echo ""
@@ -93,6 +94,7 @@ gpu_count=1
 api_port=11435
 api_port=11435
 webui_port=3000
 webui_port=3000
 headless=false
 headless=false
+build_image=false
 
 
 # Function to extract value from the parameter
 # Function to extract value from the parameter
 extract_value() {
 extract_value() {
@@ -122,6 +124,9 @@ while [[ $# -gt 0 ]]; do
             value=$(extract_value "$key")
             value=$(extract_value "$key")
             data_dir=${value:-"./ollama-data"}
             data_dir=${value:-"./ollama-data"}
             ;;
             ;;
+        --build)
+            build_image=true
+            ;;
         -q|--quiet)
         -q|--quiet)
             headless=true
             headless=true
             ;;
             ;;
@@ -164,7 +169,13 @@ if [[ -n $data_dir ]]; then
     DEFAULT_COMPOSE_COMMAND+=" -f docker-compose.data.yaml"
     DEFAULT_COMPOSE_COMMAND+=" -f docker-compose.data.yaml"
     export OLLAMA_DATA_DIR=$data_dir # Set OLLAMA_DATA_DIR environment variable
     export OLLAMA_DATA_DIR=$data_dir # Set OLLAMA_DATA_DIR environment variable
 fi
 fi
-DEFAULT_COMPOSE_COMMAND+=" up -d > /dev/null 2>&1"
+DEFAULT_COMPOSE_COMMAND+=" up -d"
+DEFAULT_COMPOSE_COMMAND+=" --remove-orphans"
+DEFAULT_COMPOSE_COMMAND+=" --force-recreate"
+if [[ -n $build_image ]]; then
+    DEFAULT_COMPOSE_COMMAND+=" --build"
+fi
+DEFAULT_COMPOSE_COMMAND+=" > /dev/null 2>&1"
 
 
 # Recap of environment variables
 # Recap of environment variables
 echo
 echo
@@ -193,7 +204,7 @@ read -n1 -s choice
 
 
 if [[ $choice == "" || $choice == "y" ]]; then
 if [[ $choice == "" || $choice == "y" ]]; then
     # Execute the command with the current user
     # Execute the command with the current user
-    eval "docker compose down > /dev/null 2>&1; $DEFAULT_COMPOSE_COMMAND" &
+    eval "$DEFAULT_COMPOSE_COMMAND" &
 
 
     # Capture the background process PID
     # Capture the background process PID
     PID=$!
     PID=$!