From 1d7e50ffcc29af823319304929e9c898eec3db68 Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 6 Nov 2024 23:11:50 +0545 Subject: [PATCH] Fix overwrite error Using `|` as delimiter for all sed commands Using \< \> as word break for all sed commands --- nginx-serve/Dockerfile | 1 + nginx-serve/apply-helm-config.sh | 33 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/nginx-serve/Dockerfile b/nginx-serve/Dockerfile index f41b31bf2..98da20f0d 100644 --- a/nginx-serve/Dockerfile +++ b/nginx-serve/Dockerfile @@ -54,3 +54,4 @@ COPY --from=nginx-build /code/build /code/build ENV SOURCE_DIRECTORY=/code/build/ ENV DESTINATION_DIRECTORY=/usr/share/nginx/html/ +ENV OVERWRITE_DESTINATION=true diff --git a/nginx-serve/apply-helm-config.sh b/nginx-serve/apply-helm-config.sh index 66ee24610..f8c2c19e9 100755 --- a/nginx-serve/apply-helm-config.sh +++ b/nginx-serve/apply-helm-config.sh @@ -3,26 +3,39 @@ SOURCE_DIRECTORY=${SOURCE_DIRECTORY?Required} DESTINATION_DIRECTORY=${DESTINATION_DIRECTORY?Required} +# Parse arguments for --overwrite option +OVERWRITE_DESTINATION=${OVERWRITE_DESTINATION:-false} +for arg in "$@"; do + if [[ "$arg" == "--overwrite" ]]; then + OVERWRITE_DESTINATION=true + fi +done + if [ -d "$DESTINATION_DIRECTORY" ]; then - echo "Destination directory <$DESTINATION_DIRECTORY> already exists. Please delete and try again" - exit 1 + if [ "$OVERWRITE_DESTINATION" == "true" ]; then + echo "Destination directory <$DESTINATION_DIRECTORY> already exists. Force deleting..." + rm -rf "$DESTINATION_DIRECTORY" + else + echo "Destination directory <$DESTINATION_DIRECTORY> already exists. Please delete and try again, or use --overwrite to force delete." + exit 1 + fi fi mkdir -p $(dirname "$DESTINATION_DIRECTORY") cp -r --no-target-directory "$SOURCE_DIRECTORY" "$DESTINATION_DIRECTORY" -find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\/$APP_TITLE/g" {} + -find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\/$APP_ENVIRONMENT/g" {} + -find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\/$APP_MAPBOX_ACCESS_TOKEN/g" {} + -find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\/$APP_TINY_API_KEY/g" {} + +find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\|$APP_TITLE|g" {} + +find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\|$APP_ENVIRONMENT|g" {} + +find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\|$APP_MAPBOX_ACCESS_TOKEN|g" {} + +find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\|$APP_TINY_API_KEY|g" {} + # NOTE: We don't need a word boundary at end as we already have a trailing slash -find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\bhttps://APP-API-ENDPOINT-PLACEHOLDER.COM/|$APP_API_ENDPOINT|g" {} + +find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\|$APP_SENTRY_DSN|g" {} + # Show diffs (Useful to debug issues) -set +x +set +xe find "$SOURCE_DIRECTORY" -type f -printf '%P\n' | while IFS= read -r file; do diff -W 100 <(fold -w 100 "$SOURCE_DIRECTORY/$file") <(fold -w 100 "$DESTINATION_DIRECTORY/$file") --suppress-common-lines done