Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing build-time env variables to run-time only #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ services:
context: .
dockerfile: Dockerfile
args:
NEXT_PUBLIC_WEBAPP_URL: ${NEXT_PUBLIC_WEBAPP_URL}
NEXT_PUBLIC_LICENSE_CONSENT: ${NEXT_PUBLIC_LICENSE_CONSENT}
CALCOM_TELEMETRY_DISABLED: ${CALCOM_TELEMETRY_DISABLED}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
CALENDSO_ENCRYPTION_KEY: ${CALENDSO_ENCRYPTION_KEY}
DATABASE_URL: ${DATABASE_URL}
- DATABASE_URL
network: stack
restart: always
networks:
Expand Down
38 changes: 22 additions & 16 deletions scripts/replace-placeholder.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
FROM=$1
TO=$2

if [ "${FROM}" = "${TO}" ]; then
echo "Nothing to replace, the value is already set to ${TO}."

exit 0
fi

# Only peform action if $FROM and $TO are different.
echo "Replacing all statically built instances of $FROM with $TO."

find apps/web/.next/ apps/web/public -type f |
while read file; do
sed -i "s|$FROM|$TO|g" "$file"
done
#!/bin/sh

# List of variables to replace
VARIABLES="NEXT_PUBLIC_WEBAPP_URL NEXT_PUBLIC_LICENSE_CONSENT CALCOM_TELEMETRY_DISABLED NEXTAUTH_SECRET CALENDSO_ENCRYPTION_KEY DATABASE_URL"

for VAR in $VARIABLES; do
# Retrieve the current value of the variable
TO_VALUE=$(eval echo \$$VAR)

# Only proceed if the variable is set and not empty
if [ ! -z "$TO_VALUE" ]; then
FROM_PLACEHOLDER="PLACEHOLDER_${VAR}"
echo "Replacing $FROM_PLACEHOLDER with $TO_VALUE"

find apps/web/.next/ apps/web/public -type f |
while read file; do
sed -i "s|$FROM_PLACEHOLDER|$TO_VALUE|g" "$file"
done
else
echo "Variable $VAR is not set. Skipping replacement for $VAR."
fi
done
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -x

# Replace the statically built BUILT_NEXT_PUBLIC_WEBAPP_URL with run-time NEXT_PUBLIC_WEBAPP_URL
# NOTE: if these values are the same, this will be skipped.
scripts/replace-placeholder.sh "$BUILT_NEXT_PUBLIC_WEBAPP_URL" "$NEXT_PUBLIC_WEBAPP_URL"
scripts/replace-placeholder.sh

scripts/wait-for-it.sh ${DATABASE_HOST} -- echo "database is up"
npx prisma migrate deploy --schema /calcom/packages/prisma/schema.prisma
Expand Down