-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
24 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,23 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
# Script to replace `NEXT_PUBLIC_*` environment variables because they're set | ||
# at build-time but we want to set them at runtime in `docker-compose.yml` | ||
if [ -z ${NEXT_PUBLIC_API_BASE_URL+x} ]; | ||
then echo "Environment variable `NEXT_PUBLIC_API_BASE_URL` is not set, please set it in docker-compose.yml"; | ||
exit 1; | ||
fi | ||
|
||
# The first part wrapped in a function | ||
makeSedCommands() { | ||
printenv | \ | ||
grep '^NEXT_PUBLIC' | \ | ||
sed -r "s/=/ /g" | \ | ||
xargs -n 2 bash -c 'echo "sed -i \"s#APP_PLACEHOLDER_$0#$1#g\""' | ||
} | ||
|
||
# Set the delimiter to newlines (needed for looping over the function output) | ||
IFS=$'\n' | ||
# For each sed command | ||
for c in $(makeSedCommands); do | ||
# For each file in the .next directory | ||
for f in $(find .next -type f); do | ||
# Execute the command against the file | ||
COMMAND="$c $f" | ||
eval $COMMAND | ||
# Replace the statically built placeholder literals from Dockerfile with run-time | ||
# the value of the `NEXT_PUBLIC_WEBAPP_URL` environment variable | ||
replace_placeholder() { | ||
find .next public -type f | | ||
while read file; do | ||
sed -i "s|$1|$2|g" "$file" || true | ||
done | ||
done | ||
} | ||
|
||
replace_placeholder "http://NEXT_PUBLIC_API_BASE_URL_PLACEHOLDER" "$NEXT_PUBLIC_API_BASE_URL" | ||
replace_placeholder "NEXT_PUBLIC_HCAPTCHA_SITE_KEY_PLACEHOLDER" "$NEXT_PUBLIC_HCAPTCHA_SITE_KEY" | ||
|
||
echo "Starting Nextjs" | ||
exec "$@" |