From e3bda0de76fc392ce6b6010915c13144da6c7524 Mon Sep 17 00:00:00 2001 From: Nana Kofi Larbi Mantey Date: Mon, 28 Oct 2024 17:02:10 +0000 Subject: [PATCH 1/2] updates replace variables deployment script --- deployment/replace-variables.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) mode change 100644 => 100755 deployment/replace-variables.sh diff --git a/deployment/replace-variables.sh b/deployment/replace-variables.sh old mode 100644 new mode 100755 index 85f21a4..d4ec355 --- a/deployment/replace-variables.sh +++ b/deployment/replace-variables.sh @@ -7,10 +7,16 @@ if [ -z "${API_URI}" ]; then exit 1 fi -# Find and replace baked values with real values for the API_URI +if [ -z "${AWS_REGION}" ]; then + echo "AWS_REGION is not set. Exiting..." + exit 1 +fi + +# Find and replace baked values with real values for the API_URI AND AWS_REGION find /app/packages/dashboard/public /app/packages/dashboard/.next -type f -name "*.js" | while read file; do sed -i "s|PLUNK_API_URI|${API_URI}|g" "$file" + sed -i "s|PLUNK_AWS_REGION|${AWS_REGION}|g" "$file" done echo "Environment Variables Baked." \ No newline at end of file From 6196c41a072fa3394af585a39e02ade74d8e0d58 Mon Sep 17 00:00:00 2001 From: Nana Kofi Larbi Mantey Date: Mon, 28 Oct 2024 17:06:10 +0000 Subject: [PATCH 2/2] improves script --- deployment/replace-variables.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/deployment/replace-variables.sh b/deployment/replace-variables.sh index d4ec355..8822aa9 100755 --- a/deployment/replace-variables.sh +++ b/deployment/replace-variables.sh @@ -12,11 +12,21 @@ if [ -z "${AWS_REGION}" ]; then exit 1 fi -# Find and replace baked values with real values for the API_URI AND AWS_REGION -find /app/packages/dashboard/public /app/packages/dashboard/.next -type f -name "*.js" | -while read file; do - sed -i "s|PLUNK_API_URI|${API_URI}|g" "$file" - sed -i "s|PLUNK_AWS_REGION|${AWS_REGION}|g" "$file" +# Process each directory that might contain JS files +for dir in "/app/packages/dashboard/public" "/app/packages/dashboard/.next"; do + if [ -d "$dir" ]; then + # Find all JS files and process them + find "$dir" -type f -name "*.js" -o -name "*.mjs" | while read -r file; do + if [ -f "$file" ]; then + # Replace environment variables + sed -i "s|PLUNK_API_URI|${API_URI}|g" "$file" + sed -i "s|PLUNK_AWS_REGION|${AWS_REGION}|g" "$file" + echo "Processed: $file" + fi + done + else + echo "Warning: Directory $dir does not exist, skipping..." + fi done -echo "Environment Variables Baked." \ No newline at end of file +echo "Environment Variables Baked."