Skip to content

Commit

Permalink
Nginx to communicate using service names. Models not exposed to local…
Browse files Browse the repository at this point in the history
…host.
  • Loading branch information
singhalkarun committed Oct 26, 2023
1 parent d01eca5 commit 6a5bf8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ count=$(jq '.models | length' config.json)
# Generate docker-compose.yaml file
printf "version: '3'\nservices:\n" > docker-compose-generated.yaml

print "" > "${DOMAIN_NAME}.conf"

for ((i=0; i<$count; i++)); do
serviceName=$(jq -r ".models[$i].serviceName" config.json)
modelBasePath=$(jq -r ".models[$i].modelBasePath" config.json)
apiBasePath=$(jq -r ".models[$i].apiBasePath" config.json)
containerPort=$(jq -r ".models[$i].containerPort" config.json)


printf "upstream ${serviceName} {
server ${serviceName}:${containerPort};
}\n" >> "${DOMAIN_NAME}.conf"
done

# Generate Nginx configuration file
printf "server { listen 80; \n listen [::]:80; \n server_name ${DOMAIN_NAME};\n" > "${DOMAIN_NAME}.conf"
printf "server { listen 80; \n listen [::]:80; \n server_name ${DOMAIN_NAME};\n" >> "${DOMAIN_NAME}.conf"

# Loop through each model
for ((i=0; i<$count; i++)); do
Expand Down Expand Up @@ -50,7 +64,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://${INGRESS_IP}:${exposedPort}/;\n " >> "${DOMAIN_NAME}.conf"
printf " location ${apiBasePath} {\n proxy_pass http://${serviceName}/;\n " >> "${DOMAIN_NAME}.conf"

for ((j=0; j<$countNginx; j++)); do
configLine=$(jq -r ".models[$i].nginx[$j]" config.json)
Expand Down Expand Up @@ -92,8 +106,8 @@ if [ "${USE_HTTPS}" = "true" ]; then
exposedPort=$((8000 + i))

# Add location block to Nginx configuration
printf " location ${apiBasePath}/ {\n proxy_pass http://${INGRESS_IP}:${exposedPort}/;\n }\n" >> "${DOMAIN_NAME}.conf"
printf " location ${apiBasePath}/ {\n proxy_pass http://${serviceName}/;\n }\n" >> "${DOMAIN_NAME}.conf"
done

printf " }\n" >> "${DOMAIN_NAME}.conf"
fi
fi
4 changes: 2 additions & 2 deletions generate_independent_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for ((i=0; i<$count; i++)); do
environment=($(jq -r ".models[$i].environment | keys[]" config.json))

# Add service details to docker-compose.yaml
printf " ${serviceName}:\n image: ${DOCKER_REGISTRY_URL}/${GITHUB_REPOSITORY_URL}/${serviceName}:latest\n ports:\n - ${exposedPort}:${containerPort}\nnetworks:\n - aitools\n" >> docker-compose-independent-generated.yaml
printf " ${serviceName}:\n image: ${DOCKER_REGISTRY_URL}/${GITHUB_REPOSITORY_URL}/${serviceName}:latest\n container_name: ${serviceName}\n networks:\n - communication\n" >> docker-compose-independent-generated.yaml

if [[ countConstraints -gt 0 ]]; then
printf " deploy:\n placement:\n constraints:\n" >> docker-compose-independent-generated.yaml
Expand All @@ -51,4 +51,4 @@ for ((i=0; i<$count; i++)); do
done
done

printf "networks:\n aitools:\n driver: overlay\n attachable: true\n config:\n - subnet: 172.1.0.0/16"
printf "networks:\n communication:\n external: true\n" >> docker-compose-independent-generated.yaml

0 comments on commit 6a5bf8f

Please sign in to comment.