Skip to content

Commit

Permalink
Error Handling in Generate.sh (#226)
Browse files Browse the repository at this point in the history
* Added Eval Statement

* fix independent-docker generate script

* Error Check for apiBasePath

* Added Error Handling
  • Loading branch information
Manas23601 authored Jul 31, 2023
1 parent 366f2d5 commit 5c359f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
30 changes: 28 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,37 @@ 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))

# Get environment variables for the model
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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion generate_independent_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions sample.env
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5c359f0

Please sign in to comment.