diff --git a/generate.sh b/generate.sh index 5ea0d38..fda150a 100755 --- a/generate.sh +++ b/generate.sh @@ -24,7 +24,29 @@ for ((i=0; i<$count; i++)); do modelBasePath=$(jq -r ".models[$i].modelBasePath" config.json) apiBasePath=$(jq -r ".models[$i].apiBasePath" config.json) containerPort=$(jq -r ".models[$i].containerPort" config.json) + + # Error Handling + # Check if the path starts with / + if [[ "${apiBasePath}" != /* ]]; then + apiBasePath="/${apiBasePath}" + fi + # Check if the path ends with / + if [[ "${apiBasePath}" != */ ]]; then + apiBasePath="${apiBasePath}/" + fi + + if ! [[ $containerPort =~ ^[0-9]+$ ]]; then + echo "Error: Container Port is not a positive numeral, Skipping $serviceName service" + continue + fi + + if [ -f "${modelBasePath::-1}Dockerfile" ]; then + echo "Info: Dockerfile exists for service $serviceName, Adding $serviceName service" + else + echo "Error: Dockerfile missing for service $serviceName, skipping $serviceName service" + continue + fi # Calculate the exposed port for the model exposedPort=$((8000 + i)) @@ -32,7 +54,7 @@ for ((i=0; i<$count; i++)); do environment=($(jq -r ".models[$i].environment | keys[]" config.json)) # Add location block to Nginx configuration - printf " location ${apiBasePath}/ {\n proxy_pass http://localhost:${exposedPort}/;\n }\n" >> "${DOMAIN_NAME}.conf" + printf " location ${apiBasePath} {\n proxy_pass http://localhost:${exposedPort}/;\n }\n" >> "${DOMAIN_NAME}.conf" # Add service details to docker-compose.yaml @@ -43,7 +65,11 @@ for ((i=0; i<$count; i++)); do printf " environment:\n" >> docker-compose-generated.yaml fi for key in "${environment[@]}"; do - value=`jq -r '.models['$i'].environment["'$key'"]' config.json` + value_name=`jq -r '.models['$i'].environment["'$key'"]' config.json` + eval "value=$value_name" + if [[ -z $value ]]; then + echo "Warning: Environement variable $key is empty" + fi printf " - ${key}=${value}\n" >> docker-compose-generated.yaml done done diff --git a/generate_independent_docker.sh b/generate_independent_docker.sh index e2ed6ef..db25c58 100755 --- a/generate_independent_docker.sh +++ b/generate_independent_docker.sh @@ -36,7 +36,8 @@ for ((i=0; i<$count; i++)); do printf " environment:\n" >> docker-compose-independent-generated.yaml fi for key in "${environment[@]}"; do - value=`jq -r '.models['$i'].environment["'$key'"]' config.json` + value_name=`jq -r '.models['$i'].environment["'$key'"]' config.json` + eval "value=$value_name" printf " - ${key}=${value}\n" >> docker-compose-independent-generated.yaml done done diff --git a/sample.env b/sample.env index 3358bdb..481ef61 100644 --- a/sample.env +++ b/sample.env @@ -1,7 +1,7 @@ -OPENAI_API_KEY= -AUTH_HEADER= +OPENAI_API_KEY=YourOpenAPIKey +AUTH_HEADER=auth AUTH_HEADER_KEY=Authorization -DOMAIN_NAME= +DOMAIN_NAME=default DOCKER_REGISTRY_URL=ghcr.io -GITHUB_REPOSITORY= +GITHUB_REPOSITORY=aitools USE_HTTPS=false