Skip to content

Commit

Permalink
Fix overwrite error
Browse files Browse the repository at this point in the history
Using `|` as delimiter for all sed commands
Using \< \> as word break for all sed commands
  • Loading branch information
thenav56 committed Nov 6, 2024
1 parent 2f7c514 commit 1d7e50f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions nginx-serve/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 23 additions & 10 deletions nginx-serve/apply-helm-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_PLACEHOLDER\>/$APP_TITLE/g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\<APP_ENVIRONMENT_PLACEHOLDER\>/$APP_ENVIRONMENT/g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\<APP_MAPBOX_ACCESS_TOKEN_PLACEHOLDER\>/$APP_MAPBOX_ACCESS_TOKEN/g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s/\<APP_TINY_API_KEY_PLACEHOLDER\>/$APP_TINY_API_KEY/g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_TITLE_PLACEHOLDER\>|$APP_TITLE|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_ENVIRONMENT_PLACEHOLDER\>|$APP_ENVIRONMENT|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_MAPBOX_ACCESS_TOKEN_PLACEHOLDER\>|$APP_MAPBOX_ACCESS_TOKEN|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<APP_TINY_API_KEY_PLACEHOLDER\>|$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|\<https://APP-API-ENDPOINT-PLACEHOLDER.COM/|$APP_API_ENDPOINT|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-RISK-API-ENDPOINT-PLACEHOLDER.COM/|$APP_RISK_API_ENDPOINT|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\bhttps://APP-SENTRY-DSN-PLACEHOLDER.COM\b|$APP_SENTRY_DSN|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-RISK-API-ENDPOINT-PLACEHOLDER.COM/|$APP_RISK_API_ENDPOINT|g" {} +
find "$DESTINATION_DIRECTORY" -type f -exec sed -i "s|\<https://APP-SENTRY-DSN-PLACEHOLDER.COM\>|$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

0 comments on commit 1d7e50f

Please sign in to comment.