Files
qna-viewer-react/docker-entrypoint.sh

37 lines
1.4 KiB
Bash

#!/bin/sh
# Exit immediately if a command exits with a non-zero status.
set -e
echo "--- Docker Entrypoint Script Started ---"
echo "Listing all environment variables:"
printenv
echo "----------------------------------------"
# Check if the required environment variables are set. Exit with an error if they are not.
: "${VITE_API_PROXY_TARGET:?Error: VITE_API_PROXY_TARGET is not set. Please check your .env file and docker-compose.yml}"
: "${VITE_API_KEY:?Error: VITE_API_KEY is not set. Please check your .env file and docker-compose.yml}"
# Extract host and directory from VITE_API_PROXY_TARGET
export VITE_API_HOST=$(echo $VITE_API_PROXY_TARGET | sed -e 's,http://\([^/]*\).*$,\1,g')
export VITE_API_DIR=$(echo $VITE_API_PROXY_TARGET | sed -e 's,http://[^/]*\(/.*\)$,\1,g' -e 's,/$,,')
echo "Extracted VITE_API_HOST: ${VITE_API_HOST}"
echo "Extracted VITE_API_DIR: ${VITE_API_DIR}"
# Define the template and output file paths
TEMPLATE_FILE="/etc/nginx/templates/nginx.conf.template"
OUTPUT_FILE="/etc/nginx/conf.d/default.conf"
# Substitute environment variables in the template file.
envsubst '${VITE_API_HOST} ${VITE_API_DIR} ${VITE_API_KEY}' < "$TEMPLATE_FILE" > "$OUTPUT_FILE"
echo "Nginx configuration generated successfully. Content:"
echo "----------------------------------------"
cat "$OUTPUT_FILE"
echo "----------------------------------------"
# Execute the command passed to this script (e.g., "nginx -g 'daemon off;'")
exec "$@"