-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify public env script (#157)
* refactor: replace variable script * fix: run script with bash to read array syntax
- Loading branch information
1 parent
fefe63b
commit 84983a2
Showing
3 changed files
with
32 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
#!/bin/bash | ||
# replace-variables.sh | ||
|
||
# Ensure NEXT_PUBLIC_BACKEND_API_BASE and NEXT_PUBLIC_NEXTAUTH_PROVIDERS are set | ||
if [ -z "$NEXT_PUBLIC_BACKEND_API_BASE" ]; then | ||
echo "NEXT_PUBLIC_BACKEND_API_BASE is not set. Please set it and rerun the script." | ||
exit 1 | ||
fi | ||
# Define a list of mandatory environment variables to check | ||
MANDATORY_VARS=("NEXT_PUBLIC_BACKEND_API_BASE" "NEXT_PUBLIC_NEXTAUTH_PROVIDERS") | ||
|
||
# Define a list of optional environment variables (no check needed) | ||
OPTIONAL_VARS=("APP_HOST" "NEXT_PUBLIC_POSTHOG_KEY" "NEXT_PUBLIC_POSTHOG_HOST" "NEXT_PUBLIC_GITHUB_INTEGRATION_CLIENT_ID") | ||
|
||
if [ -z "$NEXT_PUBLIC_NEXTAUTH_PROVIDERS" ]; then | ||
echo "NEXT_PUBLIC_NEXTAUTH_PROVIDERS is not set. Please set it and rerun the script." | ||
exit 1 | ||
# Infer NEXT_PUBLIC_APP_HOST from APP_HOST if not already set | ||
if [ -z "$NEXT_PUBLIC_APP_HOST" ] && [ ! -z "$APP_HOST" ]; then | ||
export NEXT_PUBLIC_APP_HOST="$APP_HOST" | ||
fi | ||
|
||
# Check if each mandatory variable is set | ||
for VAR in "${MANDATORY_VARS[@]}"; do | ||
if [ -z "${!VAR}" ]; then | ||
echo "$VAR is not set. Please set it and rerun the script." | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Combine mandatory and optional variables for replacement | ||
ALL_VARS=("${MANDATORY_VARS[@]}" "${OPTIONAL_VARS[@]}") | ||
|
||
# Add NEXT_PUBLIC_APP_HOST to the list for replacement | ||
ALL_VARS+=("NEXT_PUBLIC_APP_HOST") | ||
|
||
# Find and replace BAKED values with real values | ||
find /app/public /app/.next -type f -name "*.js" | | ||
while read file; do | ||
sed -i "s|BAKED_NEXT_PUBLIC_BACKEND_API_BASE|$NEXT_PUBLIC_BACKEND_API_BASE|g" "$file" | ||
sed -i "s|BAKED_NEXT_PUBLIC_NEXTAUTH_PROVIDERS|$NEXT_PUBLIC_NEXTAUTH_PROVIDERS|g" "$file" | ||
sed -i "s|BAKED_NEXT_PUBLIC_APP_HOST|$APP_HOST|g" "$file" | ||
sed -i "s|BAKED_NEXT_PUBLIC_POSTHOG_KEY|$NEXT_PUBLIC_POSTHOG_KEY|g" "$file" | ||
sed -i "s|BAKED_NEXT_PUBLIC_POSTHOG_HOST|$NEXT_PUBLIC_POSTHOG_HOST|g" "$file" | ||
sed -i "s|BAKED_NEXT_PUBLIC_GITHUB_INTEGRATION_CLIENT_ID|$GITHUB_INTEGRATION_CLIENT_ID|g" "$file" | ||
done | ||
for VAR in "${ALL_VARS[@]}"; do | ||
if [ ! -z "${!VAR}" ]; then | ||
sed -i "s|BAKED_$VAR|${!VAR}|g" "$file" | ||
fi | ||
done | ||
done |
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,5 +1,5 @@ | ||
#!/bin/sh | ||
|
||
# Set up runtime env vars and start next server | ||
sh scripts/replace-variable.sh && | ||
bash scripts/replace-variable.sh && | ||
yarn start |