dockerizing for production

This commit is contained in:
2025-08-05 14:00:07 +09:00
parent 9527b7d385
commit 27844ef237
10 changed files with 159 additions and 84 deletions

32
docker-entrypoint.sh Executable file → Normal file
View File

@@ -3,8 +3,34 @@
# Exit immediately if a command exits with a non-zero status.
set -e
# Substitute environment variables in the nginx template
envsubst '${VITE_API_PROXY_TARGET}' < /etc/nginx/templates/nginx.conf.template > /etc/nginx/nginx.conf
echo "--- Docker Entrypoint Script Started ---"
echo "Listing all environment variables:"
printenv
echo "----------------------------------------"
# Execute the command passed to this script, e.g., "nginx -g 'daemon off;'"
# 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 "$@"